Skip to content

Commit b3d588c

Browse files
authored
Cleaning up logs and functions (#198)
1 parent 91672a6 commit b3d588c

File tree

8 files changed

+36
-33
lines changed

8 files changed

+36
-33
lines changed

src/app/standalone.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ async function onInitialize(params: ExtendedInitializeParams) {
2222
getLogger().info(
2323
{
2424
ClientInfo,
25-
AwsMetadata,
2625
NodeEnv,
2726
AwsEnv,
27+
aws: {
28+
clientInfo: AwsMetadata?.clientInfo,
29+
telemetryEnabled: AwsMetadata?.telemetryEnabled,
30+
logLevel: AwsMetadata?.logLevel,
31+
cloudformation: AwsMetadata?.cloudformation,
32+
},
2833
},
2934
`${ExtensionName} initializing...`,
3035
);

src/auth/AwsCredentials.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class AwsCredentials {
3131
encryptionKey?: string,
3232
) {
3333
this.encryptionKey = encryptionKey ? Buffer.from(encryptionKey, 'base64') : undefined;
34+
this.logger.info(`AWS credentials ${encryptionKey ? 'encrypted' : 'unencrypted'}`);
3435
}
3536

3637
getIAM(): DeepReadonly<IamCredentials> {

src/featureFlag/FeatureFlagProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { readFileSync, writeFileSync } from 'fs';
22
import { join } from 'path';
3-
import { downloadJson } from '../schema/RemoteSchemaHelper';
43
import { LoggerFactory } from '../telemetry/LoggerFactory';
54
import { Measure } from '../telemetry/TelemetryDecorator';
65
import { Closeable } from '../utils/Closeable';
76
import { AwsEnv } from '../utils/Environment';
7+
import { downloadJson } from '../utils/RemoteDownload';
88
import { FeatureFlag, TargetedFeatureFlag } from './FeatureFlagI';
99
import { FeatureFlagSupplier, FeatureFlagConfigKey, TargetedFeatureFlagConfigKey } from './FeatureFlagSupplier';
1010

src/schema/CombinedSchemas.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { LoggerFactory } from '../telemetry/LoggerFactory';
12
import { PrivateSchemas, PrivateSchemasType } from './PrivateSchemas';
23
import { RegionalSchemas, RegionalSchemasType } from './RegionalSchemas';
34
import { ResourceSchema } from './ResourceSchema';
45
import { SamSchemas, SamSchemasType } from './SamSchemas';
56

67
export class CombinedSchemas {
8+
private static readonly log = LoggerFactory.getLogger('CombinedSchemas');
79
readonly numSchemas: number;
810
readonly schemas: Map<string, ResourceSchema>;
911

@@ -16,13 +18,6 @@ export class CombinedSchemas {
1618
this.numSchemas = this.schemas.size;
1719
}
1820

19-
toLog() {
20-
return {
21-
schema: this.schemas.size,
22-
names: [...this.schemas.keys()],
23-
};
24-
}
25-
2621
static from(
2722
regionalSchemas?: RegionalSchemasType,
2823
privateSchemas?: PrivateSchemasType,
@@ -32,6 +27,9 @@ export class CombinedSchemas {
3227
const privateSchema = privateSchemas === undefined ? undefined : PrivateSchemas.from(privateSchemas);
3328
const samSchema = samSchemas === undefined ? undefined : SamSchemas.from(samSchemas);
3429

30+
CombinedSchemas.log.info(
31+
`Schemas from ${regionalSchemas?.schemas.length} public schemas, ${privateSchema?.schemas.size} private schemas and ${samSchema?.schemas.size} sam schemas`,
32+
);
3533
return new CombinedSchemas(regionalSchema, privateSchema, samSchema);
3634
}
3735
}

src/schema/GetSamSchemaTask.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { DataStore } from '../datastore/DataStore';
22
import { LoggerFactory } from '../telemetry/LoggerFactory';
33
import { Measure } from '../telemetry/TelemetryDecorator';
4+
import { downloadJson } from '../utils/RemoteDownload';
45
import { GetSchemaTask } from './GetSchemaTask';
5-
import { downloadJson } from './RemoteSchemaHelper';
66
import { SamSchemas, SamSchemasType, SamStoreKey } from './SamSchemas';
77
import { SamSchemaTransformer, SamSchema } from './SamSchemaTransformer';
88

@@ -15,8 +15,6 @@ export class GetSamSchemaTask extends GetSchemaTask {
1515
@Measure({ name: 'getSchemas' })
1616
override async runImpl(dataStore: DataStore): Promise<void> {
1717
try {
18-
logger.info('Downloading SAM schema');
19-
2018
const samSchema = await downloadJson<Record<string, unknown>>(GetSamSchemaTask.SAM_SCHEMA_URL);
2119

2220
const resourceSchemas = SamSchemaTransformer.transformSamSchema(samSchema as unknown as SamSchema);

src/schema/GetSchemaTask.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { DataStore } from '../datastore/DataStore';
44
import { CfnService } from '../services/CfnService';
55
import { Measure } from '../telemetry/TelemetryDecorator';
66
import { AwsRegion } from '../utils/Region';
7+
import { downloadFile } from '../utils/RemoteDownload';
78
import { PrivateSchemas, PrivateSchemasType } from './PrivateSchemas';
89
import { RegionalSchemas, RegionalSchemasType, SchemaFileType } from './RegionalSchemas';
9-
import { cfnResourceSchemaLink, downloadFile, unZipFile } from './RemoteSchemaHelper';
10+
import { cfnResourceSchemaLink, unZipFile } from './RemoteSchemaHelper';
1011

1112
export abstract class GetSchemaTask {
1213
protected abstract runImpl(dataStore: DataStore, logger?: Logger): Promise<void>;

src/schema/RemoteSchemaHelper.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import axios from 'axios';
21
import { ZipFile, fromBuffer, Entry } from 'yauzl';
32
import { AwsRegion } from '../utils/Region';
43
import { SchemaFileType } from './RegionalSchemas';
@@ -11,16 +10,6 @@ export function cfnResourceSchemaLink(region: AwsRegion) {
1110
return `https://schema.cloudformation.${region}.amazonaws.com/CloudformationSchema.zip`;
1211
}
1312

14-
export async function downloadFile(url: string): Promise<Buffer> {
15-
const response = await axios({
16-
method: 'get',
17-
url: url,
18-
responseType: 'arraybuffer',
19-
});
20-
21-
return Buffer.from(response.data);
22-
}
23-
2413
export async function unZipFile(buffer: Promise<Buffer>): Promise<SchemaFileType[]> {
2514
return await buffer.then((zipBuffer) => {
2615
return new Promise((resolve, reject) => {
@@ -82,12 +71,3 @@ export async function unZipFile(buffer: Promise<Buffer>): Promise<SchemaFileType
8271
});
8372
});
8473
}
85-
86-
export async function downloadJson<T = unknown>(url: string): Promise<T> {
87-
const response = await axios<T>({
88-
method: 'get',
89-
url: url,
90-
});
91-
92-
return response.data;
93-
}

src/utils/RemoteDownload.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import axios from 'axios';
2+
3+
export async function downloadFile(url: string): Promise<Buffer> {
4+
const response = await axios({
5+
method: 'get',
6+
url: url,
7+
responseType: 'arraybuffer',
8+
});
9+
10+
return Buffer.from(response.data);
11+
}
12+
13+
export async function downloadJson<T = unknown>(url: string): Promise<T> {
14+
const response = await axios<T>({
15+
method: 'get',
16+
url: url,
17+
});
18+
19+
return response.data;
20+
}

0 commit comments

Comments
 (0)