From 136a9812aa41a95fc8cf39618837923bbc1f1d1f Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Thu, 18 Jul 2024 19:49:16 +0800 Subject: [PATCH] v0.0.2 --- .../modals/create-registry-credentials.hbs | 5 + addon/controllers/developers/credentials.js | 106 +++++++++++++ addon/routes/developers/credentials.js | 9 +- addon/templates/application.hbs | 1 + addon/templates/developers/credentials.hbs | 14 +- .../modals/create-registry-credentials.js | 1 + app/controllers/developers/credentials.js | 1 + composer.json | 2 +- extension.json | 2 +- package.json | 2 +- server/config/registry-bridge.php | 3 +- ...h_token_column_to_registry_users_table.php | 28 ++++ .../Internal/v1/RegistryAuthController.php | 150 ++++++++++++++---- .../src/Http/Requests/RegistryAuthRequest.php | 4 +- server/src/Http/Resources/RegistryUser.php | 12 -- server/src/Models/RegistryExtension.php | 40 +++++ server/src/Models/RegistryUser.php | 112 ++++++++++++- .../RegistryBridgeServiceProvider.php | 1 - server/src/Support/Bridge.php | 123 ++++++++++++++ server/src/routes.php | 73 +++++---- .../create-registry-credentials-test.js | 26 +++ .../developers/credentials-test.js | 12 ++ 22 files changed, 648 insertions(+), 79 deletions(-) create mode 100644 addon/components/modals/create-registry-credentials.hbs create mode 100644 addon/controllers/developers/credentials.js create mode 100644 app/components/modals/create-registry-credentials.js create mode 100644 app/controllers/developers/credentials.js create mode 100644 server/migrations/2024_07_18_151000_add_auth_token_column_to_registry_users_table.php create mode 100644 tests/integration/components/modals/create-registry-credentials-test.js create mode 100644 tests/unit/controllers/developers/credentials-test.js diff --git a/addon/components/modals/create-registry-credentials.hbs b/addon/components/modals/create-registry-credentials.hbs new file mode 100644 index 0000000..a5720e3 --- /dev/null +++ b/addon/components/modals/create-registry-credentials.hbs @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/addon/controllers/developers/credentials.js b/addon/controllers/developers/credentials.js new file mode 100644 index 0000000..69f6910 --- /dev/null +++ b/addon/controllers/developers/credentials.js @@ -0,0 +1,106 @@ +import Controller from '@ember/controller'; +import { action } from '@ember/object'; +import { inject as service } from '@ember/service'; + +export default class DevelopersCredentialsController extends Controller { + @service modalsManager; + @service notifications; + @service hostRouter; + @service fetch; + + columns = [ + { + label: 'Owner', + valuePath: 'user.name', + width: '15%', + }, + { + label: 'Fleetbase Token', + valuePath: 'token', + cellComponent: 'click-to-copy', + width: '20%', + }, + { + label: 'Registry Token', + valuePath: 'registry_token', + cellComponent: 'click-to-reveal', + cellComponentArgs: { + clickToCopy: true, + }, + width: '25%', + }, + { + label: 'Expiry', + valuePath: 'expires_at', + width: '15%', + }, + { + label: 'Created', + valuePath: 'created_at', + width: '15%', + }, + { + label: '', + cellComponent: 'table/cell/dropdown', + ddButtonText: false, + ddButtonIcon: 'ellipsis-h', + ddButtonIconPrefix: 'fas', + ddMenuLabel: 'Credential Actions', + cellClassNames: 'overflow-visible', + wrapperClass: 'flex items-center justify-end mx-2', + width: '10%', + align: 'right', + actions: [ + { + label: 'Delete Credentials', + fn: this.deleteCredentials, + className: 'text-red-700 hover:text-red-800', + }, + ], + }, + ]; + + @action deleteCredentials(credentials) { + this.modalsManager.confirm({ + title: 'Delete extension registry credentials?', + body: 'Are you sure you wish to delete these credentials? Once deleted any service or user using these credentials will loose access to the registry.', + confirm: async (modal) => { + modal.startLoading(); + + try { + await this.fetch.delete(`auth/registry-tokens/${credentials.uuid}`, {}, { namespace: '~registry/v1' }); + this.notifications.success('Registry credentials deleted.'); + return this.hostRouter.refresh(); + } catch (error) { + this.notifications.serverError(error); + } + }, + }); + } + + @action createCredentials() { + this.modalsManager.show('modals/create-registry-credentials', { + title: 'Create new registry credentials', + acceptButtonText: 'Create', + acceptButtonIcon: 'check', + password: null, + confirm: async (modal) => { + modal.startLoading(); + + const password = modal.getOption('password'); + if (!password) { + this.notifications.warning('Password cannot be empty'); + return modal.stopLoading(); + } + + try { + await this.fetch.post('auth/registry-tokens', { password }, { namespace: '~registry/v1' }); + this.notifications.success('Registry credentials created.'); + return this.hostRouter.refresh(); + } catch (error) { + this.notifications.serverError(error); + } + }, + }); + } +} diff --git a/addon/routes/developers/credentials.js b/addon/routes/developers/credentials.js index 38af13f..f742388 100644 --- a/addon/routes/developers/credentials.js +++ b/addon/routes/developers/credentials.js @@ -1,3 +1,10 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; -export default class DevelopersCredentialsRoute extends Route {} +export default class DevelopersCredentialsRoute extends Route { + @service fetch; + + model() { + return this.fetch.get('auth/registry-tokens', {}, { namespace: '~registry/v1' }); + } +} diff --git a/addon/templates/application.hbs b/addon/templates/application.hbs index b575020..e05a394 100644 --- a/addon/templates/application.hbs +++ b/addon/templates/application.hbs @@ -17,6 +17,7 @@ Extensions Analytics Payments + Credentials diff --git a/addon/templates/developers/credentials.hbs b/addon/templates/developers/credentials.hbs index e2147ca..c54b465 100644 --- a/addon/templates/developers/credentials.hbs +++ b/addon/templates/developers/credentials.hbs @@ -1 +1,13 @@ -{{outlet}} \ No newline at end of file + +