appauth -> appkeys

This commit is contained in:
Gina Häußge authored and Gina Häußge committed 2018-09-29 15:00:27 +02:00
1 parent ad8205c386
commit d6c63a5cb9
7 files changed
+104 -76

No files matched your search

@@ -1,42 +0,0 @@
<table class="table table-condensed table-hover" id="settings_plugin_appauth_keys_table">
<thead>
<tr>
<th class="settings_plugin_appauth_keys_app">{{ _('Application') }}</th>
<th class="settings_plugin_appauth_keys_actions">{{ _('Action') }}</th>
</tr>
</thead>
<tbody data-bind="foreach: keys.paginatedItems">
<tr>
<td class="settings_plugin_appauth_keys_app"><span data-bind="text: app_id"></span><br /><small class="muted">{{ _('API Key') }}: <span data-bind="text: api_key"></span></small></td>
<td class="settings_plugin_appauth_keys_actions"><a href="javascript:void(0)" title="{{ _('Revoke') }}" class="fa fa-trash-o" data-bind="click: function() { $parent.revokeKey($data.api_key) }"></a></td>
</tr>
</tbody>
</table>
<div class="pagination pagination-mini pagination-centered">
<ul>
<li data-bind="css: {disabled: keys.currentPage() === 0}"><a href="javascript:void(0)" data-bind="click: keys.prevPage">«</a></li>
</ul>
<ul data-bind="foreach: keys.pages">
<li data-bind="css: { active: $data.number === $root.keys.currentPage(), disabled: $data.number === -1 }"><a href="javascript:void(0)" data-bind="text: $data.text, click: function() { $root.keys.changePage($data.number); }"></a></li>
</ul>
<ul>
<li data-bind="css: {disabled: keys.currentPage() === keys.lastPage()}"><a href="javascript:void(0)" data-bind="click: keys.nextPage">»</a></li>
</ul>
</div>
<hr>
<form class="form-horizontal">
<div class="control-group">
<label>App</label>
<div class="controls">
<input type="text" data-bind="value: editorApp">
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn btn-primary" data-bind="click: generateKey">{{ _('Generate app key') }}</button>
</div>
</div>
</form>
@@ -6,6 +6,7 @@ import threading
import os
from binascii import hexlify
from collections import defaultdict
from flask_babel import gettext
import octoprint.plugin
from octoprint.settings import valid_boolean_trues
@@ -51,7 +52,7 @@ class ActiveKey(object):
api_key=self.api_key)
class AppAuthPlugin(octoprint.plugin.AssetPlugin,
class AppKeysPlugin(octoprint.plugin.AssetPlugin,
octoprint.plugin.BlueprintPlugin,
octoprint.plugin.SimpleApiPlugin,
octoprint.plugin.TemplatePlugin):
@@ -66,11 +67,18 @@ class AppAuthPlugin(octoprint.plugin.AssetPlugin,
self._keys = defaultdict(list)
self._keys_lock = threading.RLock()
##-- AssetPlugin hooks
##~~ TemplatePlugin
def get_template_configs(self):
return [dict(type="usersettings", name=gettext("Application Keys"), custom_bindings=False)]
##~~ AssetPlugin
def get_assets(self):
return dict(js=["js/appauth.js"],
clientjs=["clientjs/appauth.js"])
return dict(js=["js/appkeys.js"],
clientjs=["clientjs/appkeys.js"],
less=["less/appkeys.less"],
css=["css/appkeys.css"])
##~~ BlueprintPlugin mixin
@@ -161,7 +169,7 @@ class AppAuthPlugin(octoprint.plugin.AssetPlugin,
if not app_name:
return flask.abort(400)
self._add_api_key(user_id, app_name.trim())
self._add_api_key(user_id, app_name.strip())
return NO_CONTENT
@@ -261,10 +269,10 @@ class AppAuthPlugin(octoprint.plugin.AssetPlugin,
def _generate_key(self):
return hexlify(os.urandom(16))
__plugin_name__ = "AppAuth Plugin"
__plugin_name__ = "Application Keys Plugin"
__plugin_description__ = "TODO"
__plugin_author__ = "Gina Häußge, Aldo Hoeben"
__plugin_implementation__ = AppAuthPlugin()
__plugin_implementation__ = AppKeysPlugin()
__plugin_hooks__ = {
"octoprint.accesscontrol.keyvalidator": __plugin_implementation__.validate_api_key
}
@@ -5,39 +5,39 @@
factory(global.OctoPrintClient);
}
})(this, function(OctoPrintClient) {
var OctoPrintAppAuthClient = function(base) {
var OctoPrintAppKeysClient = function(base) {
this.base = base;
};
OctoPrintAppAuthClient.prototype.getKeys = function(opts) {
return this.base.simpleApiGet("appauth", opts);
OctoPrintAppKeysClient.prototype.getKeys = function(opts) {
return this.base.simpleApiGet("appkeys", opts);
};
OctoPrintAppAuthClient.prototype.generateKey = function(app, opts) {
return this.base.simpleApiCommand("appauth", "generate", {"app": app}, opts);
OctoPrintAppKeysClient.prototype.generateKey = function(app, opts) {
return this.base.simpleApiCommand("appkeys", "generate", {"app": app}, opts);
};
OctoPrintAppAuthClient.prototype.revokeKey = function(key, opts) {
return this.base.simpleApiCommand("appauth", "revoke", {"key": key}, opts);
OctoPrintAppKeysClient.prototype.revokeKey = function(key, opts) {
return this.base.simpleApiCommand("appkeys", "revoke", {"key": key}, opts);
};
OctoPrintAppAuthClient.prototype.decide = function(token, decision, opts) {
return this.base.postJson(this.base.getBlueprintUrl("appauth") + "decision/" + token, {decision: !!decision}, opts);
OctoPrintAppKeysClient.prototype.decide = function(token, decision, opts) {
return this.base.postJson(this.base.getBlueprintUrl("appkeys") + "decision/" + token, {decision: !!decision}, opts);
};
OctoPrintAppAuthClient.prototype.request = function(app, opts) {
OctoPrintAppKeysClient.prototype.request = function(app, opts) {
return this.requestForUser(app, undefined, opts);
};
OctoPrintAppAuthClient.prototype.requestForUser = function(app, user, opts) {
return this.base.postJson(this.base.getBlueprintUrl("appauth") + "request", {app: app, user: user}, opts);
OctoPrintAppKeysClient.prototype.requestForUser = function(app, user, opts) {
return this.base.postJson(this.base.getBlueprintUrl("appkeys") + "request", {app: app, user: user}, opts);
};
OctoPrintAppAuthClient.prototype.checkDecision = function(token, opts) {
return this.base.get(this.base.getBlueprintUrl("appauth") + "request/" + token, opts);
OctoPrintAppKeysClient.prototype.checkDecision = function(token, opts) {
return this.base.get(this.base.getBlueprintUrl("appkeys") + "request/" + token, opts);
};
OctoPrintAppAuthClient.prototype.authenticate = function(app, user) {
OctoPrintAppKeysClient.prototype.authenticate = function(app, user) {
var deferred = $.Deferred();
var client = this;
@@ -78,6 +78,6 @@
return deferred.promise();
};
OctoPrintClient.registerPluginComponent("appauth", OctoPrintAppAuthClient);
return OctoPrintAppAuthClient;
OctoPrintClient.registerPluginComponent("appkeys", OctoPrintAppKeysClient);
return OctoPrintAppKeysClient;
});
@@ -0,0 +1 @@
#settings_plugin_appauth_keys_table .settings_plugin_appauth_keys_actions{width:75px;text-align:center}#settings_plugin_appauth_keys_table .settings_plugin_appauth_keys_actions a{color:#000}
@@ -1,10 +1,10 @@
$(function() {
function AppAuthViewModel(parameters) {
function AppKeysViewModel(parameters) {
var self = this;
self.loginState = parameters[0];
self.keys = new ItemListHelper(
"plugin.appauth.keys",
"plugin.appkeys.keys",
{
"app": function (a, b) {
// sorts descending
@@ -26,7 +26,7 @@ $(function() {
self.editorApp = ko.observable();
self.requestData = function() {
OctoPrint.plugins.appauth.getKeys()
OctoPrint.plugins.appkeys.getKeys()
.done(self.fromResponse);
};
@@ -39,22 +39,22 @@ $(function() {
};
self.generateKey = function() {
return OctoPrint.plugins.appauth.generateKey(self.editorApp())
return OctoPrint.plugins.appkeys.generateKey(self.editorApp())
.done(self.requestData);
};
self.revokeKey = function(key) {
return OctoPrint.plugins.appauth.revokeKey(key)
return OctoPrint.plugins.appkeys.revokeKey(key)
.done(self.requestData);
};
self.allowApp = function(token) {
return OctoPrint.plugins.appauth.decide(token, true)
return OctoPrint.plugins.appkeys.decide(token, true)
.done(self.requestData);
};
self.denyApp = function(token) {
return OctoPrint.plugins.appauth.decide(token, false)
return OctoPrint.plugins.appkeys.decide(token, false)
.done(self.requestData);
};
@@ -99,7 +99,7 @@ $(function() {
};
self.onDataUpdaterPluginMessage = function(plugin, data) {
if (plugin !== "appauth") {
if (plugin !== "appkeys") {
return;
}
@@ -135,8 +135,8 @@ $(function() {
}
OCTOPRINT_VIEWMODELS.push([
AppAuthViewModel,
AppKeysViewModel,
["loginStateViewModel"],
["#usersettings_plugin_appauth"]
["#usersettings_plugin_appkeys"]
]);
});
@@ -0,0 +1,12 @@
#settings_plugin_appauth_keys_table {
.settings_plugin_appauth_keys_app {
}
.settings_plugin_appauth_keys_actions {
width: 75px;
text-align: center;
a {
color: black;
}
}
}
@@ -0,0 +1,49 @@
<legend>{{ _('Registered application keys') }}</legend>
<div data-bind="visible: keys.allSize() <= 0">
<p>{{ _('There are no application keys registered yet.') }}</p>
</div>
<div data-bind="visible: keys.allSize() > 0">
<table class="table table-condensed table-hover" id="settings_plugin_appauth_keys_table">
<thead>
<tr>
<th class="settings_plugin_appauth_keys_app">{{ _('Application identifier') }}</th>
<th class="settings_plugin_appauth_keys_actions">{{ _('Action') }}</th>
</tr>
</thead>
<tbody data-bind="foreach: keys.paginatedItems">
<tr>
<td class="settings_plugin_appauth_keys_app"><span data-bind="text: app_id"></span><br /><small class="muted">{{ _('API Key') }}: <span data-bind="text: api_key"></span></small></td>
<td class="settings_plugin_appauth_keys_actions"><a href="javascript:void(0)" title="{{ _('Revoke') }}" class="fa fa-trash-o" data-bind="click: function() { $parent.revokeKey($data.api_key) }"></a></td>
</tr>
</tbody>
</table>
<div class="pagination pagination-mini pagination-centered">
<ul>
<li data-bind="css: {disabled: keys.currentPage() === 0}"><a href="javascript:void(0)" data-bind="click: keys.prevPage">«</a></li>
</ul>
<ul data-bind="foreach: keys.pages">
<li data-bind="css: { active: $data.number === $root.keys.currentPage(), disabled: $data.number === -1 }"><a href="javascript:void(0)" data-bind="text: $data.text, click: function() { $root.keys.changePage($data.number); }"></a></li>
</ul>
<ul>
<li data-bind="css: {disabled: keys.currentPage() === keys.lastPage()}"><a href="javascript:void(0)" data-bind="click: keys.nextPage">»</a></li>
</ul>
</div>
</div>
<legend>{{ _('Manually generate an application key') }}</legend>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label">{{ _('Application identifier') }}</label>
<div class="controls">
<input type="text" data-bind="value: editorApp">
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn btn-primary" data-bind="click: generateKey">{{ _('Generate') }}</button>
</div>
</div>
</form>