Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Token Plugins #162

Merged
merged 1 commit into from
Apr 7, 2015
Merged

Introduce Token Plugins #162

merged 1 commit into from
Apr 7, 2015

Conversation

DirectXMan12
Copy link
Member

Token plugins provide a generic interface for transforming a token
into a (host, port) tuple.

The plugin name is specified using the '--token-plugin' option,
and may either be the name of a class from websockify.token_plugins,
or a fully qualified python path to the token plugin class (see below).

An optional plugin parameter can be specified using the '--token-source'
option (a value of None will be used if no '--token-source' option is
passed).

Token plugins should inherit from websockify.token_plugins.BasePlugin,
and should implement the lookup(token) method. The value of the
'--token-source' option is available as self.source.

Several plugins are included by default. The ReadOnlyTokenFile
and TokenFile plugins implement functionality from '--target-config'
(with the former only reading the file(s) once, and the latter reading
them every time). The 'BaseTokenAPI' plugin fetches the value from
an API, returning the result of process_result(response_object).
By default, process_result simply returns the text of the response,
but may be overriden. The JSONTokenAPI does just this, returning
the 'host' and 'port' values from the response JSON object.

The old '--target-config' option is now deprecated, and maps to the
TokenFile plugin under the hood.

Closes #157

@DirectXMan12
Copy link
Member Author

@james-portman : does this work for you?

@kanaka : look good to you?

Token plugins provide a generic interface for transforming a token
into a `(host, port)` tuple.

The plugin name is specified using the '--token-plugin' option,
and may either be the name of a class from `websockify.token_plugins`,
or a fully qualified python path to the token plugin class (see below).

An optional plugin parameter can be specified using the '--token-source'
option (a value of `None` will be used if no '--token-source' option is
passed).

Token plugins should inherit from `websockify.token_plugins.BasePlugin`,
and should implement the `lookup(token)` method.  The value of the
'--token-source' option is available as `self.source`.

Several plugins are included by default.  The `ReadOnlyTokenFile`
and `TokenFile` plugins implement functionality from '--target-config'
(with the former only reading the file(s) once, and the latter reading
them every time).  The 'BaseTokenAPI' plugin fetches the value from
an API, returning the result of `process_result(response_object)`.
By default, `process_result` simply returns the text of the response,
but may be overriden.  The `JSONTokenAPI` does just this, returning
the 'host' and 'port' values from the response JSON object.

The old '--target-config' option is now deprecated, and maps to the
`TokenFile` plugin under the hood.

Also-Authored-By: James Portman (@james-portman)

Closes #157
@DirectXMan12 DirectXMan12 force-pushed the feature/token-plugins branch from e7d8f91 to 69a8b92 Compare March 26, 2015 20:21
@james-portman
Copy link

@DirectXMan12 , looks good to me, sorry I didn't have time to do this recently.

I did actually make another version which calls an external executable and uses the output, rather than being limited to just python, if that would be useful as an additional token plugin?
It would work in a similar way to the 'BaseTokenAPI' plugin but catch an executables output rather than a curl.

DirectXMan12 added a commit that referenced this pull request Apr 7, 2015
@DirectXMan12 DirectXMan12 merged commit ce07749 into master Apr 7, 2015
@DirectXMan12 DirectXMan12 deleted the feature/token-plugins branch April 7, 2015 16:51
@DirectXMan12 DirectXMan12 mentioned this pull request Apr 14, 2015
@DirectXMan12 DirectXMan12 added feature New feature or request python labels Apr 28, 2015
@DirectXMan12 DirectXMan12 added this to the v0.7.0 milestone Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants