|
5 | 5 |
|
6 | 6 | import * as vscode from 'vscode'
|
7 | 7 | import * as packageJson from '../../package.json'
|
| 8 | +import * as codecatalyst from './clients/codecatalystClient' |
8 | 9 | import { getLogger } from './logger'
|
9 | 10 | import { cast, FromDescriptor, Record, TypeConstructor, TypeDescriptor } from './utilities/typeConstructors'
|
10 |
| -import { ClassToInterfaceType, keys } from './utilities/tsUtils' |
| 11 | +import { assertHasProps, ClassToInterfaceType, keys } from './utilities/tsUtils' |
11 | 12 | import { toRecord } from './utilities/collectionUtils'
|
12 | 13 | import { isNameMangled } from './vscode/env'
|
13 |
| -import { once } from './utilities/functionUtils' |
| 14 | +import { once, onceChanged } from './utilities/functionUtils' |
14 | 15 | import { ToolkitError } from './errors'
|
15 | 16 |
|
16 | 17 | type Workspace = Pick<typeof vscode.workspace, 'getConfiguration' | 'onDidChangeConfiguration'>
|
@@ -648,7 +649,7 @@ const devSettings = {
|
648 | 649 | telemetryUserPool: String,
|
649 | 650 | renderDebugDetails: Boolean,
|
650 | 651 | endpoints: Record(String, String),
|
651 |
| - cawsStage: String, |
| 652 | + codecatalystService: Record(String, String), |
652 | 653 | ssoCacheDirectory: String,
|
653 | 654 | }
|
654 | 655 | type ResolvedDevSettings = FromDescriptor<typeof devSettings>
|
@@ -708,6 +709,28 @@ export class DevSettings extends Settings.define('aws.dev', devSettings) {
|
708 | 709 | return Object.keys(this.activeSettings).length > 0
|
709 | 710 | }
|
710 | 711 |
|
| 712 | + public getCodeCatalystConfig( |
| 713 | + defaultConfig: codecatalyst.CodeCatalystConfig |
| 714 | + ): Readonly<codecatalyst.CodeCatalystConfig> { |
| 715 | + const devSetting = 'codecatalystService' |
| 716 | + const devConfig = this.get(devSetting, {}) |
| 717 | + |
| 718 | + if (Object.keys(devConfig).length === 0) { |
| 719 | + this.logCodeCatalystConfigOnce('default') |
| 720 | + return defaultConfig |
| 721 | + } |
| 722 | + |
| 723 | + try { |
| 724 | + // The configuration in dev settings should explicitly override the entire default configuration. |
| 725 | + assertHasProps(devConfig, ...Object.keys(defaultConfig)) |
| 726 | + } catch (err) { |
| 727 | + throw ToolkitError.chain(err, `Dev setting '${devSetting}' has missing or invalid properties.`) |
| 728 | + } |
| 729 | + |
| 730 | + this.logCodeCatalystConfigOnce(JSON.stringify(devConfig, undefined, 4)) |
| 731 | + return devConfig as unknown as codecatalyst.CodeCatalystConfig |
| 732 | + } |
| 733 | + |
711 | 734 | public override get<K extends AwsDevSetting>(key: K, defaultValue: ResolvedDevSettings[K]) {
|
712 | 735 | if (!this.isSet(key)) {
|
713 | 736 | this.unset(key)
|
@@ -735,6 +758,10 @@ export class DevSettings extends Settings.define('aws.dev', devSettings) {
|
735 | 758 | }
|
736 | 759 | }
|
737 | 760 |
|
| 761 | + private logCodeCatalystConfigOnce = onceChanged(val => { |
| 762 | + getLogger().info(`using CodeCatalyst service configuration: ${val}`) |
| 763 | + }) |
| 764 | + |
738 | 765 | static #instance: DevSettings
|
739 | 766 |
|
740 | 767 | public static get instance() {
|
|
0 commit comments