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

refactor: re-arrange some globals and add clock #2343

Merged
merged 15 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ requests just from the model/types.
src/shared/foo.d.ts
```
4. To make requests with the SDK, pass the `*.api.json` service model to
`ext.sdkClientBuilder.createAndConfigureServiceClient` as a generic
`globals.sdkClientBuilder.createAndConfigureServiceClient` as a generic
`Service` with `apiConfig=require('foo.api.json')`.

```ts
Expand All @@ -282,7 +282,7 @@ requests just from the model/types.

...

const c = await ext.sdkClientBuilder.createAwsService(
const c = await globals.sdkClientBuilder.createAwsService(
opts => new Service(opts),
{
apiConfig: apiConfig,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/apigateway/commands/copyUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { RestApiNode } from '../explorer/apiNodes'
import * as picker from '../../shared/ui/picker'
import * as vscode from 'vscode'
import { ProgressLocation } from 'vscode'
import { ext } from '../../shared/extensionGlobals'

import { Stage } from 'aws-sdk/clients/apigateway'
import { ApiGatewayClient } from '../../shared/clients/apiGatewayClient'
import { RegionProvider } from '../../shared/regions/regionProvider'
Expand All @@ -19,6 +19,7 @@ import { COPY_TO_CLIPBOARD_INFO_TIMEOUT_MS } from '../../shared/constants'
import { getLogger } from '../../shared/logger'
import { recordApigatewayCopyUrl } from '../../shared/telemetry/telemetry'
import { addCodiconToString } from '../../shared/utilities/textUtilities'
import globals from '../../shared/extensionGlobals'

interface StageInvokeUrlQuickPick extends vscode.QuickPickItem {
// override declaration so this can't be undefined
Expand All @@ -33,7 +34,7 @@ export async function copyUrlCommand(
): Promise<void> {
const region = node.regionCode
const dnsSuffix = regionProvider.getDnsSuffixForRegion(region) || DEFAULT_DNS_SUFFIX
const client: ApiGatewayClient = ext.toolkitClientBuilder.createApiGatewayClient(region)
const client: ApiGatewayClient = globals.toolkitClientBuilder.createApiGatewayClient(region)

let stages: Stage[]
try {
Expand Down
7 changes: 4 additions & 3 deletions src/apigateway/commands/invokeRemoteRestApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode'
import { RestApiNode } from '../explorer/apiNodes'
import { getLogger, Logger } from '../../shared/logger'
import { BaseTemplates } from '../../shared/templates/baseTemplates'
import { ext } from '../../shared/extensionGlobals'

import { template } from 'lodash'
import { toArrayAsync, toMap } from '../../shared/utilities/collectionUtils'
import { ExtensionUtilities } from '../../shared/extensionUtilities'
Expand All @@ -16,6 +16,7 @@ import { ApiGatewayClient } from '../../shared/clients/apiGatewayClient'
import { APIG_REMOTE_INVOKE_TEMPLATE } from '../templates/apigTemplates'
import { localize } from '../../shared/utilities/vsCodeUtils'
import { recordApigatewayInvokeRemote, Result } from '../../shared/telemetry/telemetry'
import globals from '../../shared/extensionGlobals'

// All the commands that we receive
interface Command {
Expand Down Expand Up @@ -64,7 +65,7 @@ export async function invokeRemoteRestApi(params: { outputChannel: vscode.Output

const invokeTemplateFn = template(APIG_REMOTE_INVOKE_TEMPLATE)

const client = ext.toolkitClientBuilder.createApiGatewayClient(params.apiNode.regionCode)
const client = globals.toolkitClientBuilder.createApiGatewayClient(params.apiNode.regionCode)
logger.info(`Loading API Resources for API ${apiNode.name} (id: ${apiNode.id})`)

const resources: Map<string, Resource> = toMap(
Expand Down Expand Up @@ -109,7 +110,7 @@ export async function invokeRemoteRestApi(params: { outputChannel: vscode.Output
postMessage: message => view.webview.postMessage(message),
}),
undefined,
ext.context.subscriptions
globals.context.subscriptions
)
} catch (err) {
logger.error(err as Error)
Expand Down
5 changes: 3 additions & 2 deletions src/apigateway/explorer/apiGatewayNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()

import * as vscode from 'vscode'
import { ext } from '../../shared/extensionGlobals'

import { AWSTreeNodeBase } from '../../shared/treeview/nodes/awsTreeNodeBase'
import { PlaceholderNode } from '../../shared/treeview/nodes/placeholderNode'
import { makeChildrenNodes } from '../../shared/treeview/treeNodeUtilities'
Expand All @@ -16,6 +16,7 @@ import { ApiGatewayClient } from '../../shared/clients/apiGatewayClient'
import { RestApi } from 'aws-sdk/clients/apigateway'
import { toArrayAsync, toMap, updateInPlace } from '../../shared/utilities/collectionUtils'
import { RestApiNode } from './apiNodes'
import globals from '../../shared/extensionGlobals'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I changed the import it ended up getting placed at the bottom. All well I guess. I wonder if we can have prettier sort the imports or something.


/**
* An AWS Explorer node representing the API Gateway (v1) service.
Expand Down Expand Up @@ -46,7 +47,7 @@ export class ApiGatewayNode extends AWSTreeNodeBase {
}

public async updateChildren(): Promise<void> {
const client: ApiGatewayClient = ext.toolkitClientBuilder.createApiGatewayClient(this.regionCode)
const client: ApiGatewayClient = globals.toolkitClientBuilder.createApiGatewayClient(this.regionCode)
const apis: Map<string, RestApi> = toMap(
await toArrayAsync(client.listApis()),
configuration => `${configuration.name} (${configuration.id})`
Expand Down
5 changes: 3 additions & 2 deletions src/apprunner/commands/createServiceFromEcr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import * as telemetry from '../../shared/telemetry/telemetry'
import * as vscode from 'vscode'
import { EcrRepositoryNode } from '../../ecr/explorer/ecrRepositoryNode'
import { EcrTagNode } from '../../ecr/explorer/ecrTagNode'
import { ext } from '../../shared/extensionGlobals'

import { CreateAppRunnerServiceWizard } from '../wizards/apprunnerCreateServiceWizard'
import globals from '../../shared/extensionGlobals'

export async function createFromEcr(node: EcrTagNode | EcrRepositoryNode): Promise<void> {
let telemetryResult: telemetry.Result = 'Failed'

try {
const ecrNode = (node as any).tag === undefined ? (node as EcrRepositoryNode) : (node as EcrTagNode).parent
const client = ext.toolkitClientBuilder.createAppRunnerClient(ecrNode.regionCode)
const client = globals.toolkitClientBuilder.createAppRunnerClient(ecrNode.regionCode)
const wizard = new CreateAppRunnerServiceWizard(ecrNode.regionCode, {
SourceConfiguration: {
ImageRepository: {
Expand Down
5 changes: 3 additions & 2 deletions src/apprunner/explorer/apprunnerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as nls from 'vscode-nls'
import { AppRunnerClient } from '../../shared/clients/apprunnerClient'
import { getPaginatedAwsCallIter } from '../../shared/utilities/collectionUtils'
import { AppRunner } from 'aws-sdk'
import globals from '../../shared/extensionGlobals'

const localize = nls.loadMessageBundle()

Expand Down Expand Up @@ -92,14 +93,14 @@ export class AppRunnerNode extends AWSTreeNodeBase {

private clearPollTimer(): void {
if (this.pollingNodes.size === 0 && this.pollTimer) {
clearInterval(this.pollTimer)
globals.clock.clearInterval(this.pollTimer)
this.pollTimer = undefined
}
}

public startPolling(id: string): void {
this.pollingNodes.add(id)
this.pollTimer = this.pollTimer ?? setInterval(this.refresh.bind(this), POLLING_INTERVAL)
this.pollTimer = this.pollTimer ?? globals.clock.setInterval(this.refresh.bind(this), POLLING_INTERVAL)
}

public stopPolling(id: string): void {
Expand Down
7 changes: 4 additions & 3 deletions src/apprunner/explorer/apprunnerServiceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { AppRunnerClient } from '../../shared/clients/apprunnerClient'
import { AppRunner } from 'aws-sdk'
import { AppRunnerNode } from './apprunnerNode'
import { CloudWatchLogsClient } from '../../shared/clients/cloudWatchLogsClient'
import { ext } from '../../shared/extensionGlobals'

import { toArrayAsync, toMap } from '../../shared/utilities/collectionUtils'
import { CloudWatchLogsBase } from '../../cloudWatchLogs/explorer/cloudWatchLogsNode'
import { CloudWatchLogs } from 'aws-sdk'
import { AWSResourceNode } from '../../shared/treeview/nodes/awsResourceNode'

import * as nls from 'vscode-nls'
import { getLogger } from '../../shared/logger'
import globals from '../../shared/extensionGlobals'
const localize = nls.loadMessageBundle()

const CONTEXT_BASE = 'awsAppRunnerServiceNode'
Expand Down Expand Up @@ -49,8 +50,8 @@ export class AppRunnerServiceNode extends CloudWatchLogsBase implements AWSResou
localize('AWS.explorerNode.apprunner.nologs', '[No App Runner logs found]')
)
this.iconPath = {
dark: vscode.Uri.file(ext.iconPaths.dark.apprunner),
light: vscode.Uri.file(ext.iconPaths.light.apprunner),
dark: vscode.Uri.file(globals.iconPaths.dark.apprunner),
light: vscode.Uri.file(globals.iconPaths.light.apprunner),
}
this.id = `AppRunnerService-${_info.ServiceArn}`
this.name = _info.ServiceName
Expand Down
9 changes: 5 additions & 4 deletions src/apprunner/wizards/apprunnerCreateServiceWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { AppRunner } from 'aws-sdk'
import * as nls from 'vscode-nls'
import { createCommonButtons, QuickInputToggleButton } from '../../shared/ui/buttons'
import { ext } from '../../shared/extensionGlobals'

import * as input from '../../shared/ui/inputPrompter'
import * as picker from '../../shared/ui/pickerPrompter'
import { Prompter } from '../../shared/ui/prompter'
Expand All @@ -17,6 +17,7 @@ import { BasicExitPrompterProvider } from '../../shared/ui/common/exitPrompter'
import { GitExtension } from '../../shared/extensions/git'
import { makeDeploymentButton } from './deploymentButton'
import { apprunnerCreateServiceDocsUrl } from '../../shared/constants'
import globals from '../../shared/extensionGlobals'

const localize = nls.loadMessageBundle()

Expand Down Expand Up @@ -106,9 +107,9 @@ export class CreateAppRunnerServiceWizard extends Wizard<AppRunner.CreateService
exitPrompterProvider: new BasicExitPrompterProvider(),
})

const ecrClient = ext.toolkitClientBuilder.createEcrClient(region)
const iamClient = ext.toolkitClientBuilder.createIamClient(region)
const apprunnerClient = ext.toolkitClientBuilder.createAppRunnerClient(region)
const ecrClient = globals.toolkitClientBuilder.createEcrClient(region)
const iamClient = globals.toolkitClientBuilder.createIamClient(region)
const apprunnerClient = globals.toolkitClientBuilder.createAppRunnerClient(region)
const autoDeployButton = makeDeploymentButton()
const gitExtension = GitExtension.instance
const codeRepositoryWizard = new AppRunnerCodeRepositoryWizard(apprunnerClient, gitExtension, autoDeployButton)
Expand Down
11 changes: 6 additions & 5 deletions src/apprunner/wizards/deploymentButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@

import * as nls from 'vscode-nls'
import * as vscode from 'vscode'
import { ext } from '../../shared/extensionGlobals'

import { QuickInputButton, QuickInputToggleButton } from '../../shared/ui/buttons'
import { apprunnerPricingUrl, extensionSettingsPrefix } from '../../shared/constants'
import { DefaultSettingsConfiguration } from '../../shared/settingsConfiguration'
import globals from '../../shared/extensionGlobals'

const localize = nls.loadMessageBundle()

function makeDeployButtons() {
const autoDeploymentsEnable: QuickInputButton<void> = {
iconPath: {
light: ext.iconPaths.light.syncIgnore,
dark: ext.iconPaths.dark.syncIgnore,
light: globals.iconPaths.light.syncIgnore,
dark: globals.iconPaths.dark.syncIgnore,
},
tooltip: localize('AWS.apprunner.buttons.enableAutoDeploy', 'Turn on automatic deployment'),
}

const autoDeploymentsDisable: QuickInputButton<void> = {
iconPath: {
light: ext.iconPaths.light.sync,
dark: ext.iconPaths.dark.sync,
light: globals.iconPaths.light.sync,
dark: globals.iconPaths.dark.sync,
},
tooltip: localize('AWS.apprunner.buttons.disableAutoDeploy', 'Turn off automatic deployment'),
}
Expand Down
17 changes: 9 additions & 8 deletions src/awsexplorer/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { deleteCloudFormation } from '../lambda/commands/deleteCloudFormation'
import { CloudFormationStackNode } from '../lambda/explorer/cloudFormationNodes'
import { AwsContext } from '../shared/awsContext'
import { AwsContextTreeCollection } from '../shared/awsContextTreeCollection'
import { ext } from '../shared/extensionGlobals'

import { safeGet } from '../shared/extensionUtilities'
import { getLogger } from '../shared/logger'
import { RegionProvider } from '../shared/regions/regionProvider'
Expand Down Expand Up @@ -40,6 +40,7 @@ import { showViewLogsMessage } from '../shared/utilities/messages'
let didTryAutoConnect = false

import * as nls from 'vscode-nls'
import globals from '../shared/extensionGlobals'
const localize = nls.loadMessageBundle()

/**
Expand All @@ -52,17 +53,17 @@ export async function activate(args: {
toolkitOutputChannel: vscode.OutputChannel
remoteInvokeOutputChannel: vscode.OutputChannel
}): Promise<void> {
const awsExplorer = new AwsExplorer(ext.context, args.awsContext, args.regionProvider)
const awsExplorer = new AwsExplorer(globals.context, args.awsContext, args.regionProvider)

const view = vscode.window.createTreeView(awsExplorer.viewProviderId, {
treeDataProvider: awsExplorer,
showCollapseAll: true,
})
ext.context.subscriptions.push(view)
globals.context.subscriptions.push(view)

await registerAwsExplorerCommands(ext.context, awsExplorer, args.toolkitOutputChannel)
await registerAwsExplorerCommands(globals.context, awsExplorer, args.toolkitOutputChannel)

ext.context.subscriptions.push(
globals.context.subscriptions.push(
view.onDidChangeVisibility(async e => {
if (e.visible) {
await tryAutoConnect(args.awsContext)
Expand All @@ -72,7 +73,7 @@ export async function activate(args: {

args.awsContextTrees.addTree(awsExplorer)

updateAwsExplorerWhenAwsContextCredentialsChange(awsExplorer, args.awsContext, ext.context)
updateAwsExplorerWhenAwsContextCredentialsChange(awsExplorer, args.awsContext, globals.context)
}

async function tryAutoConnect(awsContext: AwsContext) {
Expand All @@ -98,7 +99,7 @@ async function registerAwsExplorerCommands(
context.subscriptions.push(
vscode.commands.registerCommand('aws.showRegion', async () => {
try {
await ext.awsContextCommands.onCommandShowRegion()
await globals.awsContextCommands.onCommandShowRegion()
} finally {
recordAwsShowRegion()
recordVscodeActiveRegions({ value: awsExplorer.getRegionNodesSize() })
Expand All @@ -109,7 +110,7 @@ async function registerAwsExplorerCommands(
context.subscriptions.push(
vscode.commands.registerCommand('aws.hideRegion', async (node?: RegionNode) => {
try {
await ext.awsContextCommands.onCommandHideRegion(safeGet(node, x => x.regionCode))
await globals.awsContextCommands.onCommandHideRegion(safeGet(node, x => x.regionCode))
} finally {
recordAwsHideRegion()
recordVscodeActiveRegions({ value: awsExplorer.getRegionNodesSize() })
Expand Down
15 changes: 9 additions & 6 deletions src/awsexplorer/regionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { EcrNode } from '../ecr/explorer/ecrNode'
import { IotNode } from '../iot/explorer/iotNodes'
import { EcsNode } from '../ecs/explorer/ecsNode'
import { isCloud9 } from '../shared/extensionUtilities'
import { ext } from '../shared/extensionGlobals'
import { Region } from '../shared/regions/endpoints'
import { RegionProvider } from '../shared/regions/regionProvider'
import { AWSTreeNodeBase } from '../shared/treeview/nodes/awsTreeNodeBase'
Expand All @@ -24,6 +23,7 @@ import { SsmDocumentNode } from '../ssmDocument/explorer/ssmDocumentNode'
import { ResourcesNode } from '../dynamicResources/explorer/nodes/resourcesNode'
import { AppRunnerNode } from '../apprunner/explorer/apprunnerNode'
import { LoadMoreNode } from '../shared/treeview/nodes/loadMoreNode'
import globals from '../shared/extensionGlobals'

/**
* An AWS Explorer node representing a region.
Expand Down Expand Up @@ -58,26 +58,29 @@ export class RegionNode extends AWSTreeNodeBase {
{
serviceId: 'apprunner',
createFn: () =>
new AppRunnerNode(this.regionCode, ext.toolkitClientBuilder.createAppRunnerClient(this.regionCode)),
new AppRunnerNode(
this.regionCode,
globals.toolkitClientBuilder.createAppRunnerClient(this.regionCode)
),
},
{ serviceId: 'cloudformation', createFn: () => new CloudFormationNode(this.regionCode) },
{ serviceId: 'logs', createFn: () => new CloudWatchLogsNode(this.regionCode) },
{
serviceId: 'ecr',
createFn: () => new EcrNode(ext.toolkitClientBuilder.createEcrClient(this.regionCode)),
createFn: () => new EcrNode(globals.toolkitClientBuilder.createEcrClient(this.regionCode)),
},
{
serviceId: 'ecs',
createFn: () => new EcsNode(ext.toolkitClientBuilder.createEcsClient(this.regionCode)),
createFn: () => new EcsNode(globals.toolkitClientBuilder.createEcsClient(this.regionCode)),
},
{
serviceId: 'iot',
createFn: () => new IotNode(ext.toolkitClientBuilder.createIotClient(this.regionCode)),
createFn: () => new IotNode(globals.toolkitClientBuilder.createIotClient(this.regionCode)),
},
{ serviceId: 'lambda', createFn: () => new LambdaNode(this.regionCode) },
{
serviceId: 's3',
createFn: () => new S3Node(ext.toolkitClientBuilder.createS3Client(this.regionCode)),
createFn: () => new S3Node(globals.toolkitClientBuilder.createS3Client(this.regionCode)),
},
...(isCloud9() ? [] : [{ serviceId: 'schemas', createFn: () => new SchemasNode(this.regionCode) }]),
{ serviceId: 'states', createFn: () => new StepFunctionsNode(this.regionCode) },
Expand Down
5 changes: 3 additions & 2 deletions src/cdk/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { AppNode } from './explorer/nodes/appNode'
import { ConstructNode } from './explorer/nodes/constructNode'
import { cdk } from './globals'
import { cdkDocumentationUrl } from '../shared/constants'
import { initalizeWebviewPaths } from '../stepFunctions/activation'
import { recordCdkAppExpanded, recordCdkHelp, recordCdkRefreshExplorer } from '../shared/telemetry/telemetry'
import { renderStateMachineGraphCommand } from '../stepFunctions/commands/visualizeStateMachine/renderStateMachineGraphCDK'
import globals from '../shared/extensionGlobals'
import { initalizeWebviewPaths } from '../stepFunctions/activation'

/**
* Activate AWS CDK related functionality for the extension.
Expand All @@ -22,7 +23,7 @@ export async function activate(activateArguments: { extensionContext: vscode.Ext
const explorer = new AwsCdkExplorer()

initializeIconPaths(activateArguments.extensionContext)
initalizeWebviewPaths(activateArguments.extensionContext)
globals.visualizationResourcePaths = initalizeWebviewPaths(activateArguments.extensionContext)

await registerCdkCommands(activateArguments.extensionContext, explorer)
const view = vscode.window.createTreeView(explorer.viewProviderId, {
Expand Down
Loading