Skip to content

Instantly share code, notes, and snippets.

@woloski
Created August 29, 2016 18:16
Show Gist options
  • Save woloski/bebc4b9ab0b494852248c5b2e6e9f90c to your computer and use it in GitHub Desktop.
Save woloski/bebc4b9ab0b494852248c5b2e6e9f90c to your computer and use it in GitHub Desktop.
functions registry

Public Functions

I will create a hello world function:

echo "module.exports = function(ctx, cb) { cb(null, 'hello'); }" > hello.js
wt create hello.js

Try browsing it, works fine. Ready to share it with the rest of the word:

To share it we will create a function.json with manifest (secrets, description, readme.md, etc).

{
  "title": "Hello World",
  "name": "hello",
  "version": "1.0.0",
  "author": "auth0",
  "description": "Hello World.",
  "logoUrl": "https://cdn.auth0.com/extensions/auth0-user-invite-extension/assets/logo.svg",
  "repository": "https://github.com/auth0-extensions/auth0-user-invite-extension",
  "keywords": [
    "foo",
    "bar"
  ]
  "secrets": {
    "FOO": {
      "example": "example secret",
      "description": "Foo Secret",
      "required": true
    }
  }
}

Although a default could be created using fpm init.

We can publish now to the registry:

fpm publish

It will now be searchable:

https://<fpm.com>/hello

This publish a public function that anybody can access.

If another webtask user wants to use this function, she can do:

fpm install hello

Behind the scenes it will install the function in the webtask. This would be the equivalent of doing:

wget -qO- https://func.com/hello.tar.gz | tar xvz
wt create hello.js

If the function requires secrets, it will ask for them or they can be provided by default

fpm install hello --secret FOO=bar

This could be extended to use other faas providers (serverless, azure functions, etc). We would need a plugin architecture for fpm

fpm plugin add webtask

The function.json would specify which provider can be used and multiple would be allowed. The user would have to pick which one they want (by default).

Releasing a new version

Now we want to release an improved version.

echo "module.exports = function(ctx, cb) { cb(null, 'hello II'); }" > hello.js
wt create hello.js

We will bump function.json version, using:

fpm version minor

Let's publish it again:

fpm publish

Now, v1.1.0 is the latest.

I will tell a friend to install this function:

fpm install hello@1.1.0

or

fpm install hello@latest

Private Team Functions

Let's say now I want to create a new function but make it available only for my company.

fpm init --scope=@auth0
fpm publish

Now this function is made available only for @auth0

https://<fpm.com>/@auth0/hello

Only users belonging to this org can install/access this function.

fpm install @auth0/hello

Integration with Auth0

TBD

  "auth0": {
    "createClient": true,
    "onUninstallPath": "/.extensions/on-uninstall",
    "scopes": "read:connections read:users create:users update:users"
  },

Integration with Webtask

TBD

Future: Function Dependencies

module.exports = function(ctx, cb) {
	var foo = frequire('hello@1.1.0');
	foo.run(input, function(err, output) {
		cb(null, 'hello');
	});
}

I might depednd

{
  "title": "Hello World",
  "name": "hello",
  "version": "1.0.0",
  ...
  "dependencies" : {
  	"foo": "1.1.0"
  	"bar": "1.0.0"
  }
}

If I had installed foo already in the container, fpm install should install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment