@codiac.io/codiac-cli 1.2.126 → 1.2.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apis/codiac-relay/gen/client.d.ts +1 -1
- package/lib/apis/codiac-relay/gen/client.js +13 -13
- package/lib/apis/codiac-relay/gen/client.js.map +1 -1
- package/lib/cli-common/ImagesList.d.ts +0 -0
- package/lib/cli-common/ImagesList.js +67 -0
- package/lib/cli-common/ImagesList.js.map +1 -0
- package/lib/cli-common/argument-manager.d.ts +28 -0
- package/lib/cli-common/argument-manager.js +195 -0
- package/lib/cli-common/argument-manager.js.map +1 -0
- package/lib/cli-common/built-in-cli-user-input.d.ts +18 -0
- package/lib/cli-common/built-in-cli-user-input.js +310 -0
- package/lib/cli-common/built-in-cli-user-input.js.map +1 -0
- package/lib/cli-common/cli-interfaces.d.ts +0 -0
- package/lib/cli-common/cli-interfaces.js +7 -0
- package/lib/cli-common/cli-interfaces.js.map +1 -0
- package/lib/cli-common/command-base.d.ts +74 -0
- package/lib/cli-common/command-base.js +173 -0
- package/lib/cli-common/command-base.js.map +1 -0
- package/lib/cli-common/entities/index.d.ts +1 -0
- package/lib/cli-common/entities/index.js +5 -0
- package/lib/cli-common/entities/index.js.map +1 -0
- package/lib/cli-common/entities/prompt-choice.d.ts +7 -0
- package/lib/cli-common/entities/prompt-choice.js +3 -0
- package/lib/cli-common/entities/prompt-choice.js.map +1 -0
- package/lib/cli-common/file-selector.d.ts +48 -0
- package/lib/cli-common/file-selector.js +187 -0
- package/lib/cli-common/file-selector.js.map +1 -0
- package/lib/cli-common/i-user-input-provider.d.ts +0 -0
- package/lib/cli-common/i-user-input-provider.js +19 -0
- package/lib/cli-common/i-user-input-provider.js.map +1 -0
- package/lib/cli-common/index.d.ts +4 -0
- package/lib/cli-common/index.js +11 -0
- package/lib/cli-common/index.js.map +1 -0
- package/lib/cli-common/mock-ui.d.ts +27 -0
- package/lib/cli-common/mock-ui.js +83 -0
- package/lib/cli-common/mock-ui.js.map +1 -0
- package/lib/cli-common/prompt-select-fuzzy.d.ts +19 -0
- package/lib/cli-common/prompt-select-fuzzy.js +119 -0
- package/lib/cli-common/prompt-select-fuzzy.js.map +1 -0
- package/lib/cli-common/tenant-contextualizer.d.ts +0 -0
- package/lib/cli-common/tenant-contextualizer.js +436 -0
- package/lib/cli-common/tenant-contextualizer.js.map +1 -0
- package/lib/cli-common/test/tenant-contextualizer.spec.d.ts +0 -0
- package/lib/cli-common/test/tenant-contextualizer.spec.js +143 -0
- package/lib/cli-common/test/tenant-contextualizer.spec.js.map +1 -0
- package/lib/command-base-enterprise.d.ts +3 -18
- package/lib/command-base-enterprise.js +8 -69
- package/lib/command-base-enterprise.js.map +1 -1
- package/lib/command-base-tenantless.d.ts +3 -3
- package/lib/command-base-tenantless.js +16 -16
- package/lib/command-base-tenantless.js.map +1 -1
- package/lib/commands/asset/create.js +2 -2
- package/lib/commands/asset/create.js.map +1 -1
- package/lib/commands/build.js +2 -2
- package/lib/commands/build.js.map +1 -1
- package/lib/commands/cabinet/create.js +2 -2
- package/lib/commands/cabinet/create.js.map +1 -1
- package/lib/commands/cabinet/obliterate.js +1 -1
- package/lib/commands/cabinet/obliterate.js.map +1 -1
- package/lib/commands/commit.js +1 -1
- package/lib/commands/commit.js.map +1 -1
- package/lib/commands/enterprise/create.js +2 -2
- package/lib/commands/enterprise/create.js.map +1 -1
- package/lib/commands/environment/create.js +2 -2
- package/lib/commands/environment/create.js.map +1 -1
- package/lib/commands/filestore/capture.d.ts +0 -2
- package/lib/commands/filestore/capture.js +34 -31
- package/lib/commands/filestore/capture.js.map +1 -1
- package/lib/commands/identity/delete.js +2 -2
- package/lib/commands/identity/delete.js.map +1 -1
- package/lib/commands/identity.js +3 -3
- package/lib/commands/identity.js.map +1 -1
- package/lib/commands/init.js +4 -4
- package/lib/commands/init.js.map +1 -1
- package/lib/commands/login.js +1 -1
- package/lib/commands/login.js.map +1 -1
- package/lib/commands/publish.d.ts +3 -0
- package/lib/commands/publish.js +7 -3
- package/lib/commands/publish.js.map +1 -1
- package/lib/commands/pull.js +1 -1
- package/lib/commands/pull.js.map +1 -1
- package/lib/commands/push.js +1 -1
- package/lib/commands/push.js.map +1 -1
- package/lib/commands/run.js +6 -6
- package/lib/commands/run.js.map +1 -1
- package/lib/commands/sync.js +1 -1
- package/lib/commands/sync.js.map +1 -1
- package/lib/commands/tenant/create.js +4 -4
- package/lib/commands/tenant/create.js.map +1 -1
- package/lib/commands/tenant/switch.js +4 -4
- package/lib/commands/tenant/switch.js.map +1 -1
- package/lib/ops/INTERFACES_CLI.d.ts +3 -0
- package/lib/ops/INTERFACES_CLI.js +8 -0
- package/lib/ops/INTERFACES_CLI.js.map +1 -0
- package/lib/ops/LocalOps.d.ts +444 -0
- package/lib/ops/LocalOps.js +3184 -0
- package/lib/ops/LocalOps.js.map +1 -0
- package/lib/ops/azure-container-registry-client/azure-container-registry-client.d.ts +0 -0
- package/lib/ops/azure-container-registry-client/azure-container-registry-client.js +148 -0
- package/lib/ops/azure-container-registry-client/azure-container-registry-client.js.map +1 -0
- package/lib/ops/cli-path-walker.d.ts +0 -0
- package/lib/ops/cli-path-walker.js +55 -0
- package/lib/ops/cli-path-walker.js.map +1 -0
- package/lib/ops/codiac-entities/dependency.d.ts +5 -0
- package/lib/ops/codiac-entities/dependency.js +11 -0
- package/lib/ops/codiac-entities/dependency.js.map +1 -0
- package/lib/ops/codiac-entities/index.d.ts +1 -0
- package/lib/ops/codiac-entities/index.js +5 -0
- package/lib/ops/codiac-entities/index.js.map +1 -0
- package/lib/ops/composite-image-registry-client.d.ts +0 -0
- package/lib/ops/composite-image-registry-client.js +74 -0
- package/lib/ops/composite-image-registry-client.js.map +1 -0
- package/lib/ops/data/cli-context-repo.d.ts +61 -0
- package/lib/ops/data/cli-context-repo.js +270 -0
- package/lib/ops/data/cli-context-repo.js.map +1 -0
- package/lib/ops/data/index.d.ts +2 -0
- package/lib/ops/data/index.js +6 -0
- package/lib/ops/data/index.js.map +1 -0
- package/lib/ops/data/npm-config-repo.d.ts +13 -0
- package/lib/ops/data/npm-config-repo.js +65 -0
- package/lib/ops/data/npm-config-repo.js.map +1 -0
- package/lib/ops/docker-config.d.ts +0 -0
- package/lib/ops/docker-config.js +131 -0
- package/lib/ops/docker-config.js.map +1 -0
- package/lib/ops/docker-constants.d.ts +0 -0
- package/lib/ops/docker-constants.js +22 -0
- package/lib/ops/docker-constants.js.map +1 -0
- package/lib/ops/docker-credentials-store.d.ts +0 -0
- package/lib/ops/docker-credentials-store.js +238 -0
- package/lib/ops/docker-credentials-store.js.map +1 -0
- package/lib/ops/docker-registry-api-client/docker-registry-api-client.d.ts +0 -0
- package/lib/ops/docker-registry-api-client/docker-registry-api-client.js +289 -0
- package/lib/ops/docker-registry-api-client/docker-registry-api-client.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/blob-sum.d.ts +7 -0
- package/lib/ops/docker-registry-api-client/entities/blob-sum.js +13 -0
- package/lib/ops/docker-registry-api-client/entities/blob-sum.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/docker-access-actions-enum.d.ts +5 -0
- package/lib/ops/docker-registry-api-client/entities/docker-access-actions-enum.js +10 -0
- package/lib/ops/docker-registry-api-client/entities/docker-access-actions-enum.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/docker-auth-token-criteria.d.ts +30 -0
- package/lib/ops/docker-registry-api-client/entities/docker-auth-token-criteria.js +36 -0
- package/lib/ops/docker-registry-api-client/entities/docker-auth-token-criteria.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/i-docker-error-response.d.ts +55 -0
- package/lib/ops/docker-registry-api-client/entities/i-docker-error-response.js +52 -0
- package/lib/ops/docker-registry-api-client/entities/i-docker-error-response.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/i-docker-list-response.d.ts +7 -0
- package/lib/ops/docker-registry-api-client/entities/i-docker-list-response.js +3 -0
- package/lib/ops/docker-registry-api-client/entities/i-docker-list-response.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/image-repository.d.ts +31 -0
- package/lib/ops/docker-registry-api-client/entities/image-repository.js +30 -0
- package/lib/ops/docker-registry-api-client/entities/image-repository.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/image-tag-criteria.d.ts +8 -0
- package/lib/ops/docker-registry-api-client/entities/image-tag-criteria.js +14 -0
- package/lib/ops/docker-registry-api-client/entities/image-tag-criteria.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/image-tag-list.d.ts +7 -0
- package/lib/ops/docker-registry-api-client/entities/image-tag-list.js +13 -0
- package/lib/ops/docker-registry-api-client/entities/image-tag-list.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/manifest-criteria.d.ts +9 -0
- package/lib/ops/docker-registry-api-client/entities/manifest-criteria.js +15 -0
- package/lib/ops/docker-registry-api-client/entities/manifest-criteria.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/manifest.d.ts +15 -0
- package/lib/ops/docker-registry-api-client/entities/manifest.js +21 -0
- package/lib/ops/docker-registry-api-client/entities/manifest.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/repository-criteria.d.ts +16 -0
- package/lib/ops/docker-registry-api-client/entities/repository-criteria.js +24 -0
- package/lib/ops/docker-registry-api-client/entities/repository-criteria.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/token-response.d.ts +15 -0
- package/lib/ops/docker-registry-api-client/entities/token-response.js +15 -0
- package/lib/ops/docker-registry-api-client/entities/token-response.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/token.d.ts +17 -0
- package/lib/ops/docker-registry-api-client/entities/token.js +22 -0
- package/lib/ops/docker-registry-api-client/entities/token.js.map +1 -0
- package/lib/ops/docker-registry-api-client/entities/version-check-criteria.d.ts +4 -0
- package/lib/ops/docker-registry-api-client/entities/version-check-criteria.js +10 -0
- package/lib/ops/docker-registry-api-client/entities/version-check-criteria.js.map +1 -0
- package/lib/ops/dx-constants.d.ts +26 -0
- package/lib/ops/dx-constants.js +43 -0
- package/lib/ops/dx-constants.js.map +1 -0
- package/lib/ops/entities/ImageBuildContext.d.ts +12 -0
- package/lib/ops/entities/ImageBuildContext.js +19 -0
- package/lib/ops/entities/ImageBuildContext.js.map +1 -0
- package/lib/ops/entities/PipelineContext.d.ts +21 -0
- package/lib/ops/entities/PipelineContext.js +23 -0
- package/lib/ops/entities/PipelineContext.js.map +1 -0
- package/lib/ops/entities/TenantContext.d.ts +10 -0
- package/lib/ops/entities/TenantContext.js +16 -0
- package/lib/ops/entities/TenantContext.js.map +1 -0
- package/lib/ops/entities/ThaulConfig.d.ts +0 -0
- package/lib/ops/entities/ThaulConfig.js +30 -0
- package/lib/ops/entities/ThaulConfig.js.map +1 -0
- package/lib/ops/entities/azure-service-principal.d.ts +23 -0
- package/lib/ops/entities/azure-service-principal.js +24 -0
- package/lib/ops/entities/azure-service-principal.js.map +1 -0
- package/lib/ops/entities/better-logger.d.ts +0 -0
- package/lib/ops/entities/better-logger.js +2 -0
- package/lib/ops/entities/better-logger.js.map +1 -0
- package/lib/ops/entities/branch.d.ts +13 -0
- package/lib/ops/entities/branch.js +16 -0
- package/lib/ops/entities/branch.js.map +1 -0
- package/lib/ops/entities/cli-config.d.ts +48 -0
- package/lib/ops/entities/cli-config.js +61 -0
- package/lib/ops/entities/cli-config.js.map +1 -0
- package/lib/ops/entities/docker-image.d.ts +60 -0
- package/lib/ops/entities/docker-image.js +3 -0
- package/lib/ops/entities/docker-image.js.map +1 -0
- package/lib/ops/entities/helm-spec.d.ts +15 -0
- package/lib/ops/entities/helm-spec.js +23 -0
- package/lib/ops/entities/helm-spec.js.map +1 -0
- package/lib/ops/entities/index.d.ts +3 -0
- package/lib/ops/entities/index.js +11 -0
- package/lib/ops/entities/index.js.map +1 -0
- package/lib/ops/entities/scaffolding.d.ts +19 -0
- package/lib/ops/entities/scaffolding.js +21 -0
- package/lib/ops/entities/scaffolding.js.map +1 -0
- package/lib/ops/extensions/azart-identity-adapter.d.ts +19 -0
- package/lib/ops/extensions/azart-identity-adapter.js +97 -0
- package/lib/ops/extensions/azart-identity-adapter.js.map +1 -0
- package/lib/ops/extensions/npm-identity-adapter-base.d.ts +13 -0
- package/lib/ops/extensions/npm-identity-adapter-base.js +3 -0
- package/lib/ops/extensions/npm-identity-adapter-base.js.map +1 -0
- package/lib/ops/extensions/npmjs-identity-adapter.d.ts +13 -0
- package/lib/ops/extensions/npmjs-identity-adapter.js +64 -0
- package/lib/ops/extensions/npmjs-identity-adapter.js.map +1 -0
- package/lib/ops/git-ops.d.ts +8 -0
- package/lib/ops/git-ops.js +14 -0
- package/lib/ops/git-ops.js.map +1 -0
- package/lib/ops/i-client-for-image-registry.d.ts +0 -0
- package/lib/ops/i-client-for-image-registry.js +17 -0
- package/lib/ops/i-client-for-image-registry.js.map +1 -0
- package/lib/ops/i-identity-handler.d.ts +33 -0
- package/lib/ops/i-identity-handler.js +165 -0
- package/lib/ops/i-identity-handler.js.map +1 -0
- package/lib/ops/i-output-styler.d.ts +0 -0
- package/lib/ops/i-output-styler.js +17 -0
- package/lib/ops/i-output-styler.js.map +1 -0
- package/lib/ops/index.d.ts +12 -0
- package/lib/ops/index.js +15 -0
- package/lib/ops/index.js.map +1 -0
- package/lib/ops/json-utils.d.ts +0 -0
- package/lib/ops/json-utils.js +59 -0
- package/lib/ops/json-utils.js.map +1 -0
- package/lib/ops/no-style-output-styler.d.ts +0 -0
- package/lib/ops/no-style-output-styler.js +30 -0
- package/lib/ops/no-style-output-styler.js.map +1 -0
- package/lib/ops/oauth2-client.ts/oauth2-client.d.ts +23 -0
- package/lib/ops/oauth2-client.ts/oauth2-client.js +64 -0
- package/lib/ops/oauth2-client.ts/oauth2-client.js.map +1 -0
- package/lib/ops/project-initializer.d.ts +36 -0
- package/lib/ops/project-initializer.js +219 -0
- package/lib/ops/project-initializer.js.map +1 -0
- package/lib/ops/scaffolding/base-scaffolding.d.ts +7 -0
- package/lib/ops/scaffolding/base-scaffolding.js +21 -0
- package/lib/ops/scaffolding/base-scaffolding.js.map +1 -0
- package/lib/ops/scaffolding/codiac-api-scaffolding.d.ts +7 -0
- package/lib/ops/scaffolding/codiac-api-scaffolding.js +64 -0
- package/lib/ops/scaffolding/codiac-api-scaffolding.js.map +1 -0
- package/lib/ops/scaffolding/typescript-scaffolding.d.ts +15 -0
- package/lib/ops/scaffolding/typescript-scaffolding.js +163 -0
- package/lib/ops/scaffolding/typescript-scaffolding.js.map +1 -0
- package/lib/ops/test/mock-ui.d.ts +26 -0
- package/lib/ops/test/mock-ui.js +88 -0
- package/lib/ops/test/mock-ui.js.map +1 -0
- package/lib/ops/test/test-extensions.d.ts +13 -0
- package/lib/ops/test/test-extensions.js +71 -0
- package/lib/ops/test/test-extensions.js.map +1 -0
- package/lib/ops/test/when-a-recursive-file-search-is-run.spec.d.ts +2 -0
- package/lib/ops/test/when-a-recursive-file-search-is-run.spec.js +55 -0
- package/lib/ops/test/when-a-recursive-file-search-is-run.spec.js.map +1 -0
- package/lib/ops/test/when-git-branchline-is-attempted.spec.d.ts +2 -0
- package/lib/ops/test/when-git-branchline-is-attempted.spec.js +38 -0
- package/lib/ops/test/when-git-branchline-is-attempted.spec.js.map +1 -0
- package/lib/ops/test/when-versions-are-parsed.spec.d.ts +2 -0
- package/lib/ops/test/when-versions-are-parsed.spec.js +60 -0
- package/lib/ops/test/when-versions-are-parsed.spec.js.map +1 -0
- package/lib/ops/throwing-user-input-provider.d.ts +0 -0
- package/lib/ops/throwing-user-input-provider.js +37 -0
- package/lib/ops/throwing-user-input-provider.js.map +1 -0
- package/lib/relay/relay-container.js +1 -1
- package/lib/uilogic/build-configurator.d.ts +1 -1
- package/lib/uilogic/build-configurator.js +2 -2
- package/lib/uilogic/build-configurator.js.map +1 -1
- package/lib/uilogic/cloud-provider-contextualizer.d.ts +2 -1
- package/lib/uilogic/cloud-provider-contextualizer.js +8 -4
- package/lib/uilogic/cloud-provider-contextualizer.js.map +1 -1
- package/lib/uilogic/cloud-resource-configurators/aws-resource-configurator.d.ts +1 -1
- package/lib/uilogic/cloud-resource-configurators/aws-resource-configurator.js +1 -1
- package/lib/uilogic/cloud-resource-configurators/aws-resource-configurator.js.map +1 -1
- package/lib/uilogic/cloud-resource-configurators/az-acr-cli-authenticator.d.ts +0 -16
- package/lib/uilogic/cloud-resource-configurators/az-acr-cli-authenticator.js +76 -83
- package/lib/uilogic/cloud-resource-configurators/az-acr-cli-authenticator.js.map +1 -1
- package/lib/uilogic/cloud-resource-configurators/azure-resource-configurator.d.ts +1 -1
- package/lib/uilogic/cloud-resource-configurators/azure-resource-configurator.js +4 -4
- package/lib/uilogic/cloud-resource-configurators/azure-resource-configurator.js.map +1 -1
- package/lib/uilogic/cloud-resource-configurators/docker-hub-resource-configurator.d.ts +1 -1
- package/lib/uilogic/cloud-resource-configurators/docker-hub-resource-configurator.js +1 -1
- package/lib/uilogic/cloud-resource-configurators/docker-hub-resource-configurator.js.map +1 -1
- package/lib/uilogic/enterprise-contextualizer.d.ts +1 -1
- package/lib/uilogic/enterprise-contextualizer.js +6 -1
- package/lib/uilogic/enterprise-contextualizer.js.map +1 -1
- package/lib/uilogic/i-login-configurator.d.ts +1 -1
- package/lib/uilogic/image-configurator.d.ts +0 -1
- package/lib/uilogic/image-configurator.js +27 -47
- package/lib/uilogic/image-configurator.js.map +1 -1
- package/lib/uilogic/image-contextualizer.js +2 -2
- package/lib/uilogic/image-contextualizer.js.map +1 -1
- package/lib/uilogic/tenant-contextualizer.d.ts +1 -1
- package/lib/uilogic/tenant-contextualizer.js +3 -3
- package/lib/uilogic/tenant-contextualizer.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// COMMENTED OUT BC: Moved to cli
|
|
3
|
+
// import path = require('path');
|
|
4
|
+
// import chalk = require('chalk');
|
|
5
|
+
// import * as Case from 'case';
|
|
6
|
+
// import { TenantUser, AuthTenant } from '@codiac.io/codiac-common/security/auth-entities';
|
|
7
|
+
// import { isFuture } from "@codiac.io/codiac-common/utilities";
|
|
8
|
+
// import { CodiacClient, CodiacClient as AuthClient } from '@codiac.io/codiac-api-client';
|
|
9
|
+
// import { ProjectConfig, UserContext } from '@codiac.io/codiac-relay-contracts';
|
|
10
|
+
// import { IBetterLogger } from '@codiac.io/codiac-common/IBetterLogger';
|
|
11
|
+
// import { IUserInputProvider, IOutputStyler } from '@codiac.io/codiac-ops-common';
|
|
12
|
+
// import { ProjectContextRepo, LocalOps, DxConstants } from '../ops';
|
|
13
|
+
// import { UserContextLoader, UserContextManager } from '@codiac.io/codiac-ops-enterprise';
|
|
14
|
+
// /** Interfaces with CLI user to establish a tenant context. */
|
|
15
|
+
// export class TenantContextualizer {
|
|
16
|
+
// static readonly CODE_FOR_NEW_TENANT="** create new **";
|
|
17
|
+
// /**
|
|
18
|
+
// * @param projCfg The In-memory representation of the project's thaulconfig file.
|
|
19
|
+
// */
|
|
20
|
+
// constructor(private projCfg: ProjectConfig, private authClient: AuthClient, apiClient: CodiacClient,
|
|
21
|
+
// private _projCfgRepo: ProjectContextRepo,
|
|
22
|
+
// private ui: IUserInputProvider, private styler: IOutputStyler, private logger: IBetterLogger
|
|
23
|
+
// ) {
|
|
24
|
+
// this.userContextLoader = new UserContextLoader(logger);
|
|
25
|
+
// this.userContextRepo = new UserContextManager(apiClient, logger);
|
|
26
|
+
// }
|
|
27
|
+
// private userContextLoader: UserContextLoader;
|
|
28
|
+
// private userContextRepo: UserContextManager;
|
|
29
|
+
// /** An authenticated user, freshly retrieved during this process. */
|
|
30
|
+
// private _user: TenantUser|undefined;
|
|
31
|
+
// /** Ensures that a valid tenant is assigned
|
|
32
|
+
// * and the user has a valid tenant contributor token. */
|
|
33
|
+
// public async establishTenantContext(currentContext?: UserContext): Promise<UserContext> {
|
|
34
|
+
// return new Promise<UserContext>(async (resolve,reject) => {
|
|
35
|
+
// try {
|
|
36
|
+
// // STEP a: Load any locally cached user and tenant profiles
|
|
37
|
+
// /** Defaults to anonymous */
|
|
38
|
+
// let cachedUserContext = currentContext ?? this.userContextLoader.loadUserContext(this.projCfg.tenantCode);
|
|
39
|
+
// this.logger.trace(`After loadUserContext(${this.projCfg.tenantCode})`);
|
|
40
|
+
// // STEP b: Gather up whatever we have stored for user and tenant tokens
|
|
41
|
+
// let projTenantCode = (this.projCfg.tenantCode && this.projCfg.tenantCode != DxConstants.UNREGISTERED_TENANT_CODE) ? this.projCfg.tenantCode : undefined;
|
|
42
|
+
// let ultimateUserContext:UserContext|undefined;
|
|
43
|
+
// this.logger.trace(`Project tenantCode: ${projTenantCode}`);
|
|
44
|
+
// if (cachedUserContext && projTenantCode) {
|
|
45
|
+
// ultimateUserContext = ultimateUserContext || this.tryUseCurrentToken(cachedUserContext, projTenantCode);
|
|
46
|
+
// this.logger.trace(`Ultimate UserContext after tryUseCurrentToken: `, ultimateUserContext);
|
|
47
|
+
// ultimateUserContext = ultimateUserContext || await this.trySwitchTenant(cachedUserContext, projTenantCode);
|
|
48
|
+
// }
|
|
49
|
+
// this.logger.trace(`Cached UserContext before user interaction: `, cachedUserContext);
|
|
50
|
+
// this.logger.trace(`Ultimate UserContext before user interaction: `, ultimateUserContext);
|
|
51
|
+
// // Methods below call out for user input.
|
|
52
|
+
// if (projTenantCode) {
|
|
53
|
+
// ultimateUserContext = ultimateUserContext || await this.tryAuthenticateUnderTenant(projTenantCode, cachedUserContext?.userName);
|
|
54
|
+
// } else { // this is an "else" because we are not going to allow this command to change the project tenant assignment (only add one if it hasnt been assigned).
|
|
55
|
+
// ultimateUserContext = ultimateUserContext || await this.trySelectFromMyTenants(cachedUserContext);
|
|
56
|
+
// ultimateUserContext = ultimateUserContext || await this.tryRegisterNewTenant(cachedUserContext);
|
|
57
|
+
// }
|
|
58
|
+
// resolve(ultimateUserContext!);
|
|
59
|
+
// } catch (err) {
|
|
60
|
+
// reject(err);
|
|
61
|
+
// }
|
|
62
|
+
// });
|
|
63
|
+
// }
|
|
64
|
+
// // ==========================================================================
|
|
65
|
+
// // PRIVATE SUPPORTING METHODS
|
|
66
|
+
// // ==========================================================================
|
|
67
|
+
// /** Returns a valid tenant context if the given tenant is already current on the given context and the token isnt expired. */
|
|
68
|
+
// public tryUseCurrentToken(currentContext: UserContext, tenantCode: string): UserContext|undefined {
|
|
69
|
+
// if (currentContext.userName != UserContext.ANONYMOUS_USERNAME
|
|
70
|
+
// && currentContext.currentTenantCode == tenantCode
|
|
71
|
+
// && currentContext.currentToken
|
|
72
|
+
// && currentContext.tokenExpiration
|
|
73
|
+
// && isFuture(currentContext.tokenExpiration)) {
|
|
74
|
+
// return currentContext;
|
|
75
|
+
// } else {
|
|
76
|
+
// return undefined;
|
|
77
|
+
// }
|
|
78
|
+
// }
|
|
79
|
+
// /** Attempts to switch the userContext to a locally cached profile for the given tenant,
|
|
80
|
+
// * and if not found, requests a switch from the auth service.
|
|
81
|
+
// * The current userContext will only be modified if the switch is successfully made.
|
|
82
|
+
// * throws is the userContext does not already contain at least one token that will identify the user (regardless of tenant).
|
|
83
|
+
// * SIDE-EFFECT: This may refresh the currentToken on the current user context and cache it to the user context file. */
|
|
84
|
+
// private async trySwitchTenant(currentContext: UserContext, newTenantCode: string): Promise<UserContext|undefined> {
|
|
85
|
+
// return new Promise<UserContext|undefined>(async (resolve,reject) => {
|
|
86
|
+
// try {
|
|
87
|
+
// let ultimate: UserContext|undefined;
|
|
88
|
+
// if (currentContext.userName != UserContext.ANONYMOUS_USERNAME) {
|
|
89
|
+
// if (currentContext.tokens && currentContext.tokens[newTenantCode] && !this.authClient.isExpired(currentContext.tokens[newTenantCode])) { // Use the locally cached token
|
|
90
|
+
// // We already have an unexpired profile cached for this tenant. Just make it the current one on the userContext object.
|
|
91
|
+
// ultimate = currentContext;
|
|
92
|
+
// ultimate.currentTenantCode = newTenantCode;
|
|
93
|
+
// ultimate.currentToken = currentContext.tokens[newTenantCode];
|
|
94
|
+
// ultimate.tokenExpiration = this.authClient.extractTokenExpiration(ultimate.currentToken);
|
|
95
|
+
// this.userContextRepo.writeUserContext(ultimate);
|
|
96
|
+
// this.logger.trace(`Found an unexpired token for [${currentContext.userName}] under tenant: [${newTenantCode}].`);
|
|
97
|
+
// } else { // See if the remote service will let us switch
|
|
98
|
+
// // Get ANY unexpired token to authenticate with
|
|
99
|
+
// // (cuz we're gonna talk to the server and have IT switch our tenant)
|
|
100
|
+
// let token = (!currentContext.tokenExpiration || isFuture(currentContext.tokenExpiration)) ? currentContext.currentToken : undefined;
|
|
101
|
+
// if (!token && currentContext.tokens) {
|
|
102
|
+
// // Use one from another profile... (any unexpired tenant token will do - we just need to identify the user)
|
|
103
|
+
// for (let tc in currentContext.tokens) {
|
|
104
|
+
// if (!this.authClient.isExpired(currentContext.tokens[tc])) {
|
|
105
|
+
// token = currentContext.tokens[tc];
|
|
106
|
+
// this.logger.trace(`Found an unexpired token for [${currentContext.userName}] under tenant: [${tc}]. Using this to authenticate with the api to attempt a tenant switch.`);
|
|
107
|
+
// break;
|
|
108
|
+
// }
|
|
109
|
+
// }
|
|
110
|
+
// }
|
|
111
|
+
// if (token) {
|
|
112
|
+
// // Ask the server...
|
|
113
|
+
// this.logger.trace(`Asking api to switch tenant.`);
|
|
114
|
+
// let switchResult = await this.authClient.switchTenant(token, newTenantCode);
|
|
115
|
+
// if (switchResult.success && switchResult.output) {
|
|
116
|
+
// this._user = switchResult.output.user;
|
|
117
|
+
// ultimate = currentContext;
|
|
118
|
+
// ultimate.currentTenantCode = switchResult.output.user.tenantCode;
|
|
119
|
+
// ultimate.currentToken = switchResult.output.token;
|
|
120
|
+
// ultimate.tokenExpiration = switchResult.output.expiration;
|
|
121
|
+
// if (ultimate.currentTenantCode) {
|
|
122
|
+
// ultimate.tokens[ultimate.currentTenantCode] = ultimate.currentToken;
|
|
123
|
+
// }
|
|
124
|
+
// this.userContextRepo.writeUserContext(ultimate);
|
|
125
|
+
// this.logger.trace(`Successfully Switched user context to tenant [${ultimate.currentTenantCode}] via api.`);
|
|
126
|
+
// } else if (switchResult.output) {
|
|
127
|
+
// // We got back a failure but refreshed the token we were using.
|
|
128
|
+
// if (token == currentContext.currentToken) /* ie: if we used the token from the original context */ {
|
|
129
|
+
// this._user = switchResult.output.user;
|
|
130
|
+
// currentContext.currentToken = switchResult.output.token; // is currentContext passed in byRef? Will this assignment be honored outside this method?
|
|
131
|
+
// currentContext.tokenExpiration = switchResult.output.expiration;
|
|
132
|
+
// } else if (this._user) {
|
|
133
|
+
// this._user.profiles = switchResult.output.user.profiles; // The token was from a random tenant, so dont switch the current users tenant, just update its list of tenant profiles.
|
|
134
|
+
// }
|
|
135
|
+
// currentContext.tokens[switchResult.output.user.tenantCode] = switchResult.output.token;
|
|
136
|
+
// this.userContextRepo.writeUserContext(currentContext);
|
|
137
|
+
// // We arent registered for the project tenant (http 403 ?) <--- We need to prompt for new login creds (they may want to try another user account) OR fail loudly here.
|
|
138
|
+
// this.renderNotAMember(currentContext.userName, newTenantCode);
|
|
139
|
+
// } else {
|
|
140
|
+
// // Our current token was invalid or expired, (http 422 ?) <-- we need to prompt for just password. (NOTE: That'll be server hit #2 in this sequence)
|
|
141
|
+
// }
|
|
142
|
+
// } else {
|
|
143
|
+
// // We didnt have an unexpired token to use for this.
|
|
144
|
+
// }
|
|
145
|
+
// }
|
|
146
|
+
// }
|
|
147
|
+
// resolve(ultimate);
|
|
148
|
+
// } catch (err) {
|
|
149
|
+
// reject(err);
|
|
150
|
+
// }
|
|
151
|
+
// });
|
|
152
|
+
// }
|
|
153
|
+
// /** Only diff betw this an authenticate is that
|
|
154
|
+
// * this method only returns a valid tenant context
|
|
155
|
+
// * (whereas authenticate returns a user or tenant context). */
|
|
156
|
+
// private async tryAuthenticateUnderTenant(tenantCode: string, defaultUserName?: string): Promise<UserContext|undefined> {
|
|
157
|
+
// return new Promise<UserContext|undefined>(async (resolve,reject) => {
|
|
158
|
+
// try {
|
|
159
|
+
// let ultimate: UserContext|undefined;
|
|
160
|
+
// let newContext = await this.authenticate(tenantCode, defaultUserName);
|
|
161
|
+
// if (newContext) {
|
|
162
|
+
// if (newContext.currentTenantCode == tenantCode) {
|
|
163
|
+
// ultimate = newContext;
|
|
164
|
+
// } else {
|
|
165
|
+
// this.renderNotAMember(newContext.userName, tenantCode);
|
|
166
|
+
// }
|
|
167
|
+
// }
|
|
168
|
+
// resolve(ultimate);
|
|
169
|
+
// } catch (err) {
|
|
170
|
+
// reject(err);
|
|
171
|
+
// }
|
|
172
|
+
// });
|
|
173
|
+
// }
|
|
174
|
+
// private async trySelectFromMyTenants(currentContext: UserContext|undefined): Promise<UserContext|undefined> {
|
|
175
|
+
// return new Promise<UserContext|undefined>(async (resolve,reject) => {
|
|
176
|
+
// try {
|
|
177
|
+
// let ultimate: UserContext|undefined;
|
|
178
|
+
// // Step 1: GET THE USER'S LIST OF TENANTS (se we can access an updated list of profiles.
|
|
179
|
+
// // They gotta be up to date cuz access to that tenant may have been granted just seconds ago).
|
|
180
|
+
// // We may need to authenticate here. Or perhaps refresh token. Where can we store the user from a previous server trip? do we need to?
|
|
181
|
+
// if (currentContext)
|
|
182
|
+
// this.logger.trace("currentContext token BEFORE getUserTenants...", currentContext.currentToken)
|
|
183
|
+
// else
|
|
184
|
+
// this.logger.trace("No currentContext BEFORE getUserTenants")
|
|
185
|
+
// currentContext = await this.establishPrincipalContext(currentContext); // shouldnt we do this before we do anything else in this class?
|
|
186
|
+
// let myTenants: AuthTenant[] = [];
|
|
187
|
+
// if (currentContext?.currentToken) {
|
|
188
|
+
// myTenants = await this.getUserTenants(this._user);
|
|
189
|
+
// }
|
|
190
|
+
// if (currentContext)
|
|
191
|
+
// this.logger.trace("currentContext token AFTER getUserTenants...", currentContext.currentToken)
|
|
192
|
+
// else
|
|
193
|
+
// this.logger.trace("No currentContext AFTER getUserTenants")
|
|
194
|
+
// if (myTenants && myTenants.length > 0) {
|
|
195
|
+
// let tenantCode = await this.promptToSelectTenant(myTenants);
|
|
196
|
+
// if (tenantCode) {
|
|
197
|
+
// if (tenantCode == TenantContextualizer.CODE_FOR_NEW_TENANT) {
|
|
198
|
+
// tenantCode = undefined; // this will lead us to createNewTenant while still allowing us to recognize a cancel.
|
|
199
|
+
// } else {
|
|
200
|
+
// if (!currentContext) currentContext = await this.authenticate(); // this should never happen - we already did so to get the list of tenant profiles.
|
|
201
|
+
// if (currentContext) {
|
|
202
|
+
// ultimate = await this.trySwitchTenant(currentContext, tenantCode); // Call server if we dont already have a token for the selected tenant.
|
|
203
|
+
// if (ultimate) {
|
|
204
|
+
// // Commented out bc: TenantContextulizer should NOT be creating a proj cfg where there wasnt one. The init command has the sole responsibility there.
|
|
205
|
+
// // if (!this.projCfg) this.projCfg = this.createDefaultProjectConfig(); // This is avoiding a corrupted project folder.
|
|
206
|
+
// // Update the project config if available
|
|
207
|
+
// if (this.projCfg) {
|
|
208
|
+
// this.projCfg.tenantCode = tenantCode;
|
|
209
|
+
// await this._projCfgRepo.updateProjectConfigFile(this.projCfg);
|
|
210
|
+
// }
|
|
211
|
+
// }
|
|
212
|
+
// }
|
|
213
|
+
// }
|
|
214
|
+
// } else {
|
|
215
|
+
// this.cancel(); // user gave up: stop the bus.
|
|
216
|
+
// }
|
|
217
|
+
// }
|
|
218
|
+
// resolve(ultimate);
|
|
219
|
+
// } catch (err) {
|
|
220
|
+
// reject(err);
|
|
221
|
+
// }
|
|
222
|
+
// });
|
|
223
|
+
// }
|
|
224
|
+
// /** Side effect: Overwrites this._user if it s able to refresh it from the auth api */
|
|
225
|
+
// private async establishPrincipalContext(context: UserContext|undefined): Promise<UserContext|undefined> {
|
|
226
|
+
// return new Promise<UserContext|undefined>(async (resolve,reject) => {
|
|
227
|
+
// try {
|
|
228
|
+
// if (!this._user) {
|
|
229
|
+
// if (context && context.userName != UserContext.ANONYMOUS_USERNAME && (!context.tokenExpiration || isFuture(context.tokenExpiration))) {
|
|
230
|
+
// let refreshResult: {context?: UserContext, user?: TenantUser }|undefined;
|
|
231
|
+
// try {
|
|
232
|
+
// refreshResult = await this.userContextRepo.refreshUserContext(context);
|
|
233
|
+
// } catch (err) {
|
|
234
|
+
// this.logger.warn(`Failed to refresh your user context, leaving your api token potentially stale, preventing further communications: ${err.message||""}`, err);
|
|
235
|
+
// }
|
|
236
|
+
// // ----------------------------------------------------------------------------------
|
|
237
|
+
// // TODO: Review this logic for refresh/expiration fails
|
|
238
|
+
// // that should run an authenticate but arent...
|
|
239
|
+
// // ----------------------------------------------------------------------------------
|
|
240
|
+
// if (refreshResult) {
|
|
241
|
+
// if (refreshResult.user) {
|
|
242
|
+
// this.logger.debug("Setting this.User from refresh output...")
|
|
243
|
+
// this._user = refreshResult.user;
|
|
244
|
+
// this.logger.debug(`this._user profile count: ${this._user.profiles.length}`)
|
|
245
|
+
// }
|
|
246
|
+
// if (refreshResult.context) {
|
|
247
|
+
// this.logger.debug("Setting context from refresh output...");
|
|
248
|
+
// context = refreshResult.context;
|
|
249
|
+
// }
|
|
250
|
+
// // } else {
|
|
251
|
+
// // if (context.currentToken && context.currentTenantCode && context.userName) {
|
|
252
|
+
// // // Allow for use while disconnected.
|
|
253
|
+
// // // TODO: retrieve a locally cached user object.
|
|
254
|
+
// // this._user = new User(context.currentTenantCode, "", "", "", context.userName);
|
|
255
|
+
// // this._user.profiles = [];
|
|
256
|
+
// // for (let tenantCode in context.tokens) {
|
|
257
|
+
// // this._user.profiles.push(new AccessProfile(tenantCode));
|
|
258
|
+
// // }
|
|
259
|
+
// // this.logger.warn(`Using an instance of the current user sparsely populated from cache.`);
|
|
260
|
+
// // }
|
|
261
|
+
// }
|
|
262
|
+
// }
|
|
263
|
+
// if (!this._user) {
|
|
264
|
+
// let defaultUserName = (context && context.userName != UserContext.ANONYMOUS_USERNAME) ? context.userName : undefined;
|
|
265
|
+
// let currentTenantCode = (context && context.currentTenantCode) || undefined;
|
|
266
|
+
// context = await this.authenticate(currentTenantCode, defaultUserName);
|
|
267
|
+
// }
|
|
268
|
+
// }
|
|
269
|
+
// resolve(context);
|
|
270
|
+
// } catch (err) {
|
|
271
|
+
// reject(err);
|
|
272
|
+
// }
|
|
273
|
+
// });
|
|
274
|
+
// }
|
|
275
|
+
// private async getUserTenants(user: TenantUser|undefined): Promise<AuthTenant[]> {
|
|
276
|
+
// return new Promise<AuthTenant[]>(async (resolve,reject) => {
|
|
277
|
+
// try {
|
|
278
|
+
// let myTenants: AuthTenant[] = [];
|
|
279
|
+
// this.logger.write(`Retrieving tenants of user [${user?.login || "anonymous"}]`);
|
|
280
|
+
// let myAcctResult = await this.authClient.whoAmI();
|
|
281
|
+
// if (myAcctResult.error) throw myAcctResult.error;
|
|
282
|
+
// if (myAcctResult.output?.profiles && myAcctResult.output?.profiles.length > 0) {
|
|
283
|
+
// let myProfiles = myAcctResult.output.profiles;
|
|
284
|
+
// // We're gonna put the tenantCode in place of the name for now cuz that's all that we get with whoami.
|
|
285
|
+
// // TODO: Consider storing AuthTenant.name with the AccessProfile entity so we can make it readable without an extra db hit.
|
|
286
|
+
// myTenants = myProfiles.map(ap => new AuthTenant(ap.tenantCode, ap.tenantCode));
|
|
287
|
+
// // If we want the tenant names...
|
|
288
|
+
// // let codesCsv = myProfiles.map(p => p.tenantCode).join(",");
|
|
289
|
+
// // let criteria: TenantCriteria = { mine: true }; // <----- TODO !!! (works off current user)
|
|
290
|
+
// // let result = await this.apiClient.tryReadMany(AuthTenant, TenantCriteria, criteria);
|
|
291
|
+
// // OR
|
|
292
|
+
// // let result = await this.authClient.getMyTenants();
|
|
293
|
+
// // this.logger.trace("Result of attempt to get user tenants",result)
|
|
294
|
+
// }
|
|
295
|
+
// resolve(myTenants);
|
|
296
|
+
// } catch (err) {
|
|
297
|
+
// reject(err);
|
|
298
|
+
// }
|
|
299
|
+
// });
|
|
300
|
+
// }
|
|
301
|
+
// /** Prompts the user to select a tenant from the given list of tenantCodes.
|
|
302
|
+
// * Returns undefined if cancelled, and TenantContextualizer.CODE_FOR_NEW_TENANT if "register new" is selected.
|
|
303
|
+
// * @param tenants List of tenants from which to select.
|
|
304
|
+
// * @param allowAddNew Inserts an option to add a new tenant. (NOTE: this method DOES NOT perform the add new action itself!)
|
|
305
|
+
// */
|
|
306
|
+
// async promptToSelectTenant(tenants: AuthTenant[], allowAddNew: boolean = true): Promise<string|undefined> {
|
|
307
|
+
// return new Promise<string|undefined>(async (resolve,reject) => {
|
|
308
|
+
// try {
|
|
309
|
+
// let choices = tenants.map(t => {
|
|
310
|
+
// return { name: t.name, value: t.code };
|
|
311
|
+
// });
|
|
312
|
+
// if (allowAddNew) {
|
|
313
|
+
// choices.push({ name: "(Register new tenant)", value: TenantContextualizer.CODE_FOR_NEW_TENANT});
|
|
314
|
+
// }
|
|
315
|
+
// this.logger.notice(`Your project is not assigned to a tenant.`);
|
|
316
|
+
// this.logger.notice(`Please assign it to one of your organizations or register a new organization...`);
|
|
317
|
+
// let selected = await this.ui.promptSelect('tenantCode', 'Select a Tenant:', choices);
|
|
318
|
+
// // let result = await inquirer.prompt({ type: 'list', name: 'tenantCode', message: 'Select a Tenant:', choices: choices});
|
|
319
|
+
// // let selected: string|undefined = result.tenantCode;
|
|
320
|
+
// resolve(selected);
|
|
321
|
+
// } catch (err) {
|
|
322
|
+
// reject(err);
|
|
323
|
+
// }
|
|
324
|
+
// });
|
|
325
|
+
// }
|
|
326
|
+
// /** Returns a tenant context, a user context, or undefined if operation cancelled.
|
|
327
|
+
// * Caches the new user context.
|
|
328
|
+
// * Throws any exceptions.
|
|
329
|
+
// *
|
|
330
|
+
// * `unregistered` tenant code gets ignored.
|
|
331
|
+
// *
|
|
332
|
+
// * @param login
|
|
333
|
+
// * @param silent (optional: defaults to false) When set to true, suppresses the prompts to confirm the given defaults. Requires defaultLogin and defaultPassword to be set. Also requires tenantCode if the current user has more than one tenant profile and it cannot be derived decisively from the current context.
|
|
334
|
+
// */
|
|
335
|
+
// public async authenticate(tenantCode?: string, login?: string, password?: string, silent: boolean = false): Promise<UserContext|undefined> {
|
|
336
|
+
// return new Promise<UserContext>(async (resolve,reject) => {
|
|
337
|
+
// try {
|
|
338
|
+
// let defaults = { u: login, p: password, t: tenantCode };
|
|
339
|
+
// let newContext: UserContext|undefined;
|
|
340
|
+
// while (!newContext) {
|
|
341
|
+
// newContext = undefined;
|
|
342
|
+
// defaults.t = (defaults.t !== undefined && defaults.t !== DxConstants.UNREGISTERED_TENANT_CODE) ? defaults.t : undefined;
|
|
343
|
+
// if (!silent) {
|
|
344
|
+
// this.ui.userMessage(`Please authenticate with Codiac ${(defaults.t !== undefined) ? " under tenant " + this.styler.hilite(defaults.t) : ""} (CTRL-C to cancel)`);
|
|
345
|
+
// defaults.u = await this.ui.prompt("userName", `Username: `, true, defaults.u);
|
|
346
|
+
// }
|
|
347
|
+
// if (defaults.u) {
|
|
348
|
+
// if (!silent) {
|
|
349
|
+
// defaults.p = defaults.p ?? await this.ui.promptPassword("password", "Password ");
|
|
350
|
+
// }
|
|
351
|
+
// if (defaults.p) {
|
|
352
|
+
// this.logger.debug(`Authenticating against ${this.authClient!.apiRootUrl}`);
|
|
353
|
+
// let authResult = await this.authClient!.authenticate(defaults.u, defaults.p, defaults.t);
|
|
354
|
+
// this.logger.debug("", JSON.stringify(authResult, undefined, ' '));
|
|
355
|
+
// if (authResult.output) {
|
|
356
|
+
// let token = authResult.output.token;
|
|
357
|
+
// let userName = authResult.output.user.login;
|
|
358
|
+
// let tenantCode = authResult.output.user.tenantCode;
|
|
359
|
+
// let exp = authResult.output.expiration;
|
|
360
|
+
// // this.passwordLastEntered = password; // we're gonna need this later if we need to register a new tenant (cuz the tenantRegn endpoint doent support a user token yet.)
|
|
361
|
+
// newContext = await this.userContextRepo.saveToUserContext(newContext, userName, token, tenantCode, exp);
|
|
362
|
+
// this._user = authResult.output.user;
|
|
363
|
+
// }
|
|
364
|
+
// if (authResult.error) {
|
|
365
|
+
// throw authResult.error;
|
|
366
|
+
// }
|
|
367
|
+
// }
|
|
368
|
+
// }
|
|
369
|
+
// // Dump em if they didnt get fully hydrated by this point.
|
|
370
|
+
// if (silent && (defaults.u === undefined || defaults.p === undefined)) {
|
|
371
|
+
// throw new Error(`Cannot authenticate using "silent": both login and password must be provided.`);
|
|
372
|
+
// }
|
|
373
|
+
// }
|
|
374
|
+
// resolve(newContext);
|
|
375
|
+
// } catch (err) {
|
|
376
|
+
// reject(err);
|
|
377
|
+
// }
|
|
378
|
+
// });
|
|
379
|
+
// }
|
|
380
|
+
// private isNullOrEmpty(value: string|undefined): boolean {
|
|
381
|
+
// return (value == undefined || value == "");
|
|
382
|
+
// }
|
|
383
|
+
// async tryRegisterNewTenant(currentContext: UserContext|undefined): Promise<UserContext|undefined> {
|
|
384
|
+
// return new Promise<UserContext|undefined>(async (resolve,reject) => {
|
|
385
|
+
// try {
|
|
386
|
+
// let ultimate:UserContext|undefined;
|
|
387
|
+
// let tenantName = await this.ui.prompt<string>("tenantName", "Enter the full name of the organization: ", true);
|
|
388
|
+
// // HACK: We happen to know that the authenticate will have necessarily been run before this was called,
|
|
389
|
+
// // and we're keeping the pwd from that run in memory just so we can fire this request.
|
|
390
|
+
// if (!this._user) {
|
|
391
|
+
// // Wanna authenticate here?
|
|
392
|
+
// throw new Error("RegisterTenant failed: No user was provided.");
|
|
393
|
+
// } else if (!tenantName) {
|
|
394
|
+
// // this is a null gate - it can never happen bc the prompt is required;
|
|
395
|
+
// throw new Error("RegisterTenant failed: No tenant name was provided.");
|
|
396
|
+
// } else {
|
|
397
|
+
// let createNewUser = this.isNullOrEmpty(currentContext?.currentToken); // we will have already established the user context
|
|
398
|
+
// let tenantResult = await this.authClient.registerTenant(tenantName, createNewUser, this._user.login, this._user.password!, undefined, currentContext!.currentToken || this.authClient.authToken);
|
|
399
|
+
// if (tenantResult.error) {
|
|
400
|
+
// throw tenantResult.error;
|
|
401
|
+
// } else if (tenantResult.success && tenantResult.output) {
|
|
402
|
+
// let token = this.authClient.authToken!; // thats a valid force - we will def have one if the register call succeeded
|
|
403
|
+
// ultimate = await this.userContextRepo.saveToUserContext(currentContext, this._user.login, token, tenantResult.output.code);
|
|
404
|
+
// this.projCfg.tenantCode = tenantResult.output.code;
|
|
405
|
+
// await this._projCfgRepo.updateProjectConfigFile(this.projCfg);
|
|
406
|
+
// } else {
|
|
407
|
+
// // ?? Fail? Is this a valid scenario?
|
|
408
|
+
// throw new Error("RegisterTenant failed: " + tenantResult.message + tenantResult.error);
|
|
409
|
+
// }
|
|
410
|
+
// }
|
|
411
|
+
// resolve(ultimate);
|
|
412
|
+
// } catch (err) {
|
|
413
|
+
// this.logger.debug(`Error attempting to register new tenant: ${err.message||""}${err.response?.data?.message||""}`, (err.toJSON) ? err.toJSON() : err);
|
|
414
|
+
// reject(err);
|
|
415
|
+
// }
|
|
416
|
+
// });
|
|
417
|
+
// }
|
|
418
|
+
// cancel() {
|
|
419
|
+
// throw new Error("Action cancelled. No work was done.");
|
|
420
|
+
// // this.logger.notice("Action cancelled. No work was done.");
|
|
421
|
+
// // this.exit();
|
|
422
|
+
// }
|
|
423
|
+
// /** logs a user message stating that the current user
|
|
424
|
+
// * is not a member of the given tenant,
|
|
425
|
+
// * with instructions for what to do next. */
|
|
426
|
+
// private renderNotAMember(username: string, tenantCode: string): void {
|
|
427
|
+
// this.logger.notice(`You are currently logged in as '${this.styler.hilite(username)}',`);
|
|
428
|
+
// this.logger.notice(`but you are not a member of the tenant '${this.styler.hilite(tenantCode)}'.`);
|
|
429
|
+
// this.logger.notice(`You will need to:`);
|
|
430
|
+
// this.logger.notice(` EITHER) Log in as a different user, using...`);
|
|
431
|
+
// this.logger.notice(` ${this.styler.hilite("cod login [yourUsername] -p [yourPassword]")},`);
|
|
432
|
+
// this.logger.notice(` OR) Cancel and send a request to be added, using...`);
|
|
433
|
+
// this.logger.notice(` ${this.styler.hilite(`cod request-access ${tenantCode} --role publisher`)}`);
|
|
434
|
+
// }
|
|
435
|
+
// }
|
|
436
|
+
//# sourceMappingURL=tenant-contextualizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-contextualizer.js","sourceRoot":"","sources":["../../src/cli-common/tenant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yGAAyG;AACzG,+CAA+C;AAC/C,4EAA4E;AAC5E,sGAAsG;AACtG,mFAAmF;AACnF,4GAA4G;AAC5G,MAAM;AAIN,IAAI"}
|
|
File without changes
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// COMMENTED OUT BC: Moved to cli
|
|
3
|
+
// import * as path from "path";
|
|
4
|
+
// import "mocha";
|
|
5
|
+
// import "chai";
|
|
6
|
+
// import { expect } from "chai";
|
|
7
|
+
// import { ProjectConfig } from "@codiac.io/codiac-relay-contracts";
|
|
8
|
+
// import { IBetterLogger, LogLevel } from '@codiac.io/codiac-common/IBetterLogger';
|
|
9
|
+
// import { BetterConsoleLogger } from "@codiac.io/codiac-common/better-logger"
|
|
10
|
+
// import { CodiacClient } from "@codiac.io/codiac-api-client";
|
|
11
|
+
// import { LocalOps, ProjectContextRepo, DxConstants, CliEnviro, ProjectEnviro, CliGlobalConfigRepo } from "../../ops";
|
|
12
|
+
// import { MockUi } from "../mock-ui";
|
|
13
|
+
// import { TenantContextualizer } from "../tenant-contextualizer";
|
|
14
|
+
// import { Container } from "inversify";
|
|
15
|
+
// import { INTERFACES } from "@codiac.io/codiac-common";
|
|
16
|
+
// import { cwd } from "process";
|
|
17
|
+
// import { INTERFACES_OPS } from "@codiac.io/codiac-ops-common";
|
|
18
|
+
// import { TtyOutputStyler } from "@codiac.io/cli-tools";
|
|
19
|
+
// export type CliTestContext = {
|
|
20
|
+
// ioc: Container,
|
|
21
|
+
// logger: IBetterLogger,
|
|
22
|
+
// projCfg: ProjectConfig,
|
|
23
|
+
// codiacVersion: string,
|
|
24
|
+
// codeRoot: string,
|
|
25
|
+
// projectRoot: string,
|
|
26
|
+
// cliConfigDir: string,
|
|
27
|
+
// projCfgRepo: ProjectContextRepo,
|
|
28
|
+
// localOps: LocalOps,
|
|
29
|
+
// apiUrl: string,
|
|
30
|
+
// apiClient: CodiacClient,
|
|
31
|
+
// mockUi: MockUi,
|
|
32
|
+
// outputStyler: TtyOutputStyler
|
|
33
|
+
// }
|
|
34
|
+
// function harness(): CliTestContext {
|
|
35
|
+
// let ctx = <CliTestContext>{ };
|
|
36
|
+
// ctx.ioc = new Container();
|
|
37
|
+
// ctx.logger = new BetterConsoleLogger({ LogLevelsToShow: [LogLevel.trace, LogLevel.debug, LogLevel.error, LogLevel.warn, LogLevel.detail, LogLevel.detail] });
|
|
38
|
+
// ctx.projCfg = new ProjectConfig("myTestProj", DxConstants.UNREGISTERED_TENANT_CODE, ctx.projCfg.codeVersion);
|
|
39
|
+
// ctx.codiacVersion = "0.0.0";
|
|
40
|
+
// ctx.codeRoot = process.cwd();
|
|
41
|
+
// ctx.projectRoot = path.join(ctx.codeRoot, "src/test/my-test-proj");
|
|
42
|
+
// ctx.cliConfigDir = path.join(ctx.codeRoot, "src/test/mock-cli-config");
|
|
43
|
+
// ctx.projCfgRepo = new ProjectContextRepo({ projectRoot: ctx.projectRoot });
|
|
44
|
+
// // ctx.cliCfgRepo = new CliGlobalConfigRepo({ cliConfigDir: ctx.cliConfigDir, version: "1.0.1" });
|
|
45
|
+
// ctx.mockUi = new MockUi();
|
|
46
|
+
// ctx.outputStyler = new TtyOutputStyler();
|
|
47
|
+
// ctx.ioc.bind(INTERFACES.IBetterLogger).toConstantValue(ctx.logger);
|
|
48
|
+
// ctx.ioc.bind(CliEnviro).toConstantValue({ cliConfigDir: cwd(), version: "1.0.1" });
|
|
49
|
+
// ctx.ioc.bind(ProjectEnviro).toConstantValue({ projectRoot: ctx.projectRoot });
|
|
50
|
+
// ctx.ioc.bind(ProjectContextRepo).toConstantValue(ctx.projCfgRepo);
|
|
51
|
+
// ctx.ioc.bind(INTERFACES_OPS.IUserInputProvider).toConstantValue(ctx.mockUi);
|
|
52
|
+
// ctx.ioc.bind(INTERFACES_OPS.IOutputStyler).toConstantValue(ctx.outputStyler);
|
|
53
|
+
// ctx.localOps = new LocalOps(ctx.ioc); // , ctx.codiacVersion, ctx.projectRoot, ctx.cfgRepo, ctx.mockUi, ctx.mockUi, ctx.logger)
|
|
54
|
+
// ctx.apiUrl = "http://localhost:5775/"; // "https://toybox01.codiac.io/api/"; // CodiacClient.DEFAULT_API_URL;
|
|
55
|
+
// ctx.apiClient = CodiacClient.create(ctx.logger, ctx.apiUrl);
|
|
56
|
+
// return ctx;
|
|
57
|
+
// }
|
|
58
|
+
// describe("When tenant context is needed on a project without a tenant assigned", () => {
|
|
59
|
+
// it("then user chooosing to create new shall register a new tenant", async () => {
|
|
60
|
+
// return new Promise<void>(async (resolve,reject) => {
|
|
61
|
+
// try {
|
|
62
|
+
// let ctx = harness();
|
|
63
|
+
// let tenCon = new TenantContextualizer(ctx.projCfg, ctx.apiClient, ctx.apiClient, ctx.projCfgRepo, ctx.mockUi, ctx.mockUi, ctx.logger);
|
|
64
|
+
// ctx.mockUi.setValue("userName", "mark.freydl@codiac.io");
|
|
65
|
+
// ctx.mockUi.setValue("password", "abc123");
|
|
66
|
+
// ctx.mockUi.setValue("tenantCode", TenantContextualizer.CODE_FOR_NEW_TENANT);
|
|
67
|
+
// ctx.mockUi.setValue("tenantName", "Test MCF Tenant Inc.")
|
|
68
|
+
// let context = await tenCon.establishTenantContext();
|
|
69
|
+
// console.log(JSON.stringify(context));
|
|
70
|
+
// expect(ctx.mockUi.responses["tenantCode"]).to.not.equal(undefined, "the contextualizer must prompt for tenantCode");
|
|
71
|
+
// expect(context.userName).to.equal("mark.freydl@codiac.io", "username must match the username in the original context");
|
|
72
|
+
// expect(context.currentTenantCode).to.not.equal(undefined, "tenantCode cannot be undefined");
|
|
73
|
+
// expect(context.currentTenantCode).to.not.equal("cod", "tenantCode must NOT match the original value");
|
|
74
|
+
// expect(ctx.projCfg.tenantCode).to.equal(context.currentTenantCode, "The new tenant code must be written to the project config instance in memory.")
|
|
75
|
+
// let fromFile = await ctx.projCfgRepo.readProjectConfig();
|
|
76
|
+
// expect(fromFile.tenantCode).to.equal(context.currentTenantCode, "The new tenant code must be written to the project config file.")
|
|
77
|
+
// resolve();
|
|
78
|
+
// // done();
|
|
79
|
+
// } catch (err) {
|
|
80
|
+
// // console.log(err);
|
|
81
|
+
// // resolve();
|
|
82
|
+
// reject(err);
|
|
83
|
+
// // done(err);
|
|
84
|
+
// }
|
|
85
|
+
// });
|
|
86
|
+
// });
|
|
87
|
+
// it("then user context with a current tenant shall prompt for selection", async () => {
|
|
88
|
+
// return new Promise<void>(async (resolve,reject) => {
|
|
89
|
+
// try {
|
|
90
|
+
// let ctx = harness();
|
|
91
|
+
// let tenCon = new TenantContextualizer(ctx.projCfg, ctx.apiClient, ctx.apiClient, ctx.projCfgRepo, ctx.mockUi, ctx.mockUi, ctx.logger);
|
|
92
|
+
// ctx.mockUi.setValue("userName", "mark.freydl@codiac.io");
|
|
93
|
+
// ctx.mockUi.setValue("password", "abc123");
|
|
94
|
+
// ctx.mockUi.setValue("tenantCode", "cod")
|
|
95
|
+
// // mockUi.setValue("tenantName", "Test MCF Tenant Inc.")
|
|
96
|
+
// let context = await tenCon.establishTenantContext();
|
|
97
|
+
// console.log(JSON.stringify(context));
|
|
98
|
+
// expect(ctx.mockUi.responses["tenantCode"]).to.not.equal(undefined, "the contextualizer must prompt for tenantCode");
|
|
99
|
+
// expect(context.userName).to.equal("mark.freydl@codiac.io", "username must match the username in the original context");
|
|
100
|
+
// expect(context.currentTenantCode).to.not.equal(undefined, "tenatnCode cannot be undefined");
|
|
101
|
+
// expect(context.currentTenantCode).to.equal("cod", "tenantCode must match the given value");
|
|
102
|
+
// resolve();
|
|
103
|
+
// // done();
|
|
104
|
+
// } catch (err) {
|
|
105
|
+
// // console.log(err);
|
|
106
|
+
// // resolve();
|
|
107
|
+
// reject(err);
|
|
108
|
+
// // done(err);
|
|
109
|
+
// }
|
|
110
|
+
// });
|
|
111
|
+
// });
|
|
112
|
+
// it("Then user context shall be switched to project tenant", async () => {
|
|
113
|
+
// return new Promise<void>(async (resolve,reject) => {
|
|
114
|
+
// try {
|
|
115
|
+
// let ctx = harness();
|
|
116
|
+
// ctx.projCfg.tenantCode = "bid";
|
|
117
|
+
// ctx.mockUi.setValue("userName", "mark.freydl@codiac.io");
|
|
118
|
+
// // ctx.mockUi.setValue("tenantCode", "cod")
|
|
119
|
+
// // mockUi.setValue("tenantName", "Test MCF Tenant Inc.")
|
|
120
|
+
// ctx.mockUi.setValue("password", "abc123");
|
|
121
|
+
// let tenCon = new TenantContextualizer(ctx.projCfg, ctx.apiClient, ctx.apiClient, ctx.projCfgRepo, ctx.mockUi, ctx.mockUi, ctx.logger);
|
|
122
|
+
// // Make sure User has tokens for each tenant
|
|
123
|
+
// let storedContext = await tenCon.authenticate("bid", "mark.freydl@codiac.io");
|
|
124
|
+
// let initialUserContext = await tenCon.authenticate("cod", "mark.freydl@codiac.io");
|
|
125
|
+
// if (!initialUserContext) expect.fail("Test invalid: Unable to set up an initial user context.");
|
|
126
|
+
// let context = await tenCon.establishTenantContext();
|
|
127
|
+
// console.log(JSON.stringify(context));
|
|
128
|
+
// expect(context.currentTenantCode).to.equal(ctx.projCfg.tenantCode, "User tenantCode must match the project config");
|
|
129
|
+
// expect(ctx.mockUi.responses["tenantCode"]).to.equal(undefined, "the contextualizer must NOT prompt for tenantCode");
|
|
130
|
+
// expect(context.userName).to.equal(initialUserContext.userName, "username must match the username in the original context");
|
|
131
|
+
// expect(context.currentTenantCode).to.not.equal(undefined, "tenantCode cannot be undefined");
|
|
132
|
+
// resolve();
|
|
133
|
+
// // done();
|
|
134
|
+
// } catch (err) {
|
|
135
|
+
// // console.log(err);
|
|
136
|
+
// // resolve();
|
|
137
|
+
// reject(err);
|
|
138
|
+
// // done(err);
|
|
139
|
+
// }
|
|
140
|
+
// });
|
|
141
|
+
// });
|
|
142
|
+
// });
|
|
143
|
+
//# sourceMappingURL=tenant-contextualizer.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-contextualizer.spec.js","sourceRoot":"","sources":["../../../src/cli-common/test/tenant-contextualizer.spec.ts"],"names":[],"mappings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