aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2017-04-14 01:36:45 -0700
committerChristine Dodrill <me@christine.website>2017-04-14 01:36:45 -0700
commit249836270b7e1fe145296b5aa0ef644dcd99bb71 (patch)
tree40c3750f4bc838c3c01d1fd4831bcc750e890ca4
parent07eac9e223ae6a8a59d007b9df3ff12481111e42 (diff)
downloadx-249836270b7e1fe145296b5aa0ef644dcd99bb71.tar.xz
x-249836270b7e1fe145296b5aa0ef644dcd99bb71.zip
kcpd: add stdlib backend service
-rw-r--r--irc/kcpd/stdlibsvc/README.md81
-rw-r--r--irc/kcpd/stdlibsvc/env.json8
-rw-r--r--irc/kcpd/stdlibsvc/functions/main/function.json15
-rw-r--r--irc/kcpd/stdlibsvc/functions/main/index.js32
-rw-r--r--irc/kcpd/stdlibsvc/package.json19
5 files changed, 155 insertions, 0 deletions
diff --git a/irc/kcpd/stdlibsvc/README.md b/irc/kcpd/stdlibsvc/README.md
new file mode 100644
index 0000000..b378de4
--- /dev/null
+++ b/irc/kcpd/stdlibsvc/README.md
@@ -0,0 +1,81 @@
+# Your stdlib service: xena/kcpdwhitelist
+
+This is the README for your service.
+
+A few notes;
+
+`package.json` is NPM-compatible and contains some stdlib configuration details.
+`.gitignore` has also been provided for your convenience.
+
+# package.json
+
+This is a standard `package.json`. You'll notice an additional `"stdlib"` field.
+You can configure your service for the stdlib registry using;
+
+`name` - The name to register on stdlib, in the format of `<username>/<service>`.
+In order to compile to the registry you must have permission to compile to the
+provided username's account.
+
+`defaultFunction` - Execute if provided no function route (root service).
+If not specified, your base service route will provide a list of available
+functions in JSON format.
+
+`timeout` - The time in ms at which to kill service execution. Free accounts are
+limited to 30 seconds (30000).
+
+`publish` - Whether to publish releases (versioned) to the stdlib public
+ directory. Packages pushed to the registry in non-release environments will
+ never be published.
+
+# env.json
+
+Environment configuration for your service. Each top level key (i.e.
+ `"dev"` and `"release"`) specifies their own set of key-value
+ pairs for a specific execution environment. The keys and values specified
+ are automatically added to the `process.env` variable in Node.js.
+
+`"dev"` is the *non-configurable* name of the local environment, but can
+also be used as an environment name for compilation
+(i.e. `$ lib up development`).
+
+`"release"` is the *non-configurable* name of the production environment when
+you create releases with `$ lib release`.
+
+You can add additional environments and key-value pairs, and use them for
+compilation with `lib up <environment>`. Note that free accounts are
+restricted to one compilation environment (aside from `"release"`).
+
+*We recommend against checking this file in to version control*. It will be
+saved with your tarball and is privately retrievable from the stdlib registry
+using your account credentials. It has been added to `.gitignore` by default.
+
+# f/main/function.json
+
+This is your function definition file. The following fields can be used for
+execution configuration of specific functions within your service.
+
+`name` - The function name. This maps to an execution route over HTTP. For
+example, `xena/kcpdwhitelist/main` would map to the first
+function you've created.
+
+`description` - A brief description of the function. To provide detailed
+information about function execution, overwrite this README.
+
+`args` - An `Array` describing each argument as you expect them to be passed to
+`params.args`.
+
+`kwargs` - An `Object` describing each keyword argument as you expect them to be
+passed to `params.kwargs`
+
+`http` - Information to provide to function requests over HTTP.
+
+`http.headers` - HTTP headers to return in the response. Examples are
+`"Content-Type"` to specify file type if your function returns a `Buffer` or
+`"Access-Control-Allow-Origin"` to restrict browser-based function requests.
+
+# f/main/index.js
+
+The entry point to your function described in `f/main/function.json`.
+This is *non-configurable*. You may add as many subdirectories and supportive
+files as you like, but `index.js` will remain the entry point and *must*
+export a function to be active.
diff --git a/irc/kcpd/stdlibsvc/env.json b/irc/kcpd/stdlibsvc/env.json
new file mode 100644
index 0000000..d8f72e9
--- /dev/null
+++ b/irc/kcpd/stdlibsvc/env.json
@@ -0,0 +1,8 @@
+{
+ "dev": {
+ "key": "value"
+ },
+ "release": {
+ "key": "value"
+ }
+}
diff --git a/irc/kcpd/stdlibsvc/functions/main/function.json b/irc/kcpd/stdlibsvc/functions/main/function.json
new file mode 100644
index 0000000..3fa3c9f
--- /dev/null
+++ b/irc/kcpd/stdlibsvc/functions/main/function.json
@@ -0,0 +1,15 @@
+{
+ "name": "main",
+ "description": "Function",
+ "args": [
+ "First argument",
+ "Second argument"
+ ],
+ "kwargs": {
+ "alpha": "Keyword argument alpha",
+ "beta": "Keyword argument beta"
+ },
+ "http": {
+ "headers": {}
+ }
+} \ No newline at end of file
diff --git a/irc/kcpd/stdlibsvc/functions/main/index.js b/irc/kcpd/stdlibsvc/functions/main/index.js
new file mode 100644
index 0000000..a843dd1
--- /dev/null
+++ b/irc/kcpd/stdlibsvc/functions/main/index.js
@@ -0,0 +1,32 @@
+/* Import dependencies, declare constants */
+
+win = (callback) => {
+ callback(null, "allowed");
+};
+
+fail = (callback) => {
+ callback("not allowed");
+};
+
+/**
+* Your function call
+* @param {Object} params Execution parameters
+* Members
+* - {Array} args Arguments passed to function
+* - {Object} kwargs Keyword arguments (key-value pairs) passed to function
+* - {String} remoteAddress The IPv4 or IPv6 address of the caller
+*
+* @param {Function} callback Execute this to end the function call
+* Arguments
+* - {Error} error The error to show if function fails
+* - {Any} returnValue JSON serializable (or Buffer) return value
+*/
+module.exports = (params, callback) => {
+ switch (params.kwargs.user) {
+ case "Xena":
+ win(callback);
+
+ default:
+ fail(callback);
+ }
+};
diff --git a/irc/kcpd/stdlibsvc/package.json b/irc/kcpd/stdlibsvc/package.json
new file mode 100644
index 0000000..7986c05
--- /dev/null
+++ b/irc/kcpd/stdlibsvc/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "kcpdwhitelist",
+ "version": "0.0.2",
+ "description": "Service",
+ "author": "xena <me@christine.website>",
+ "main": "functions/main/index.js",
+ "dependencies": {},
+ "private": true,
+ "stdlib": {
+ "name": "xena/kcpdwhitelist",
+ "defaultFunction": "main",
+ "timeout": 10000,
+ "publish": true,
+ "personalize": {
+ "keys": [],
+ "user": []
+ }
+ }
+}