Skip to content

Commit cccc04d

Browse files
committed
feat: collect provider errors
1 parent 3b46cda commit cccc04d

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ CloudGraph will generate this configuration file when you run `cg init aws`. You
6060
], // Optional, defaults to the default profile
6161
"regions": "us-east-1,us-east-2,us-west-2",
6262
"resources": "alb,apiGatewayResource,apiGatewayRestApi,apiGatewayStage,appSync,asg,billing,cognitoIdentityPool,cognitoUserPool,cloudFormationStack,cloudFormationStackSet,cloudfront,cloudwatch,ebs,ec2Instance,eip,elb,igw,kinesisFirehose,kinesisStream,kms,lambda,nat,networkInterface,route53HostedZone,route53Record,routeTable,sg,vpc,sqs,s3"
63-
}
6463
}
6564
```
6665

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@aws-sdk/client-ssm": "^3.341.0",
3939
"@aws-sdk/credential-providers": "^3.256.0",
4040
"@aws-sdk/shared-ini-file-loader": "^3.254.0",
41-
"@cloudgraph/sdk": "^0.22.1",
41+
"@cloudgraph/sdk": "^0.23.0",
4242
"@fast-csv/parse": "^4.3.6",
4343
"@graphql-tools/load-files": "^6.5.3",
4444
"@graphql-tools/merge": "^8.2.1",
@@ -88,4 +88,4 @@
8888
"**/glob-parent": "^5.1.2",
8989
"**/uri-js": "^3.0.1"
9090
}
91-
}
91+
}

src/services/index.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { obfuscateSensitiveString } from '../utils/format'
2626
import { checkAndMergeConnections } from '../utils'
2727
import { Account, rawDataInterface } from './base'
2828
import enhancers, { EnhancerConfig } from './base/enhancers'
29+
import AwsErrorLog from '../utils/errorLog'
2930

3031
const DEFAULT_REGION = 'us-east-1'
3132
const DEFAULT_RESOURCES = Object.values(services).join(',')
@@ -314,15 +315,16 @@ export default class Provider extends CloudGraph.Client {
314315
// MFA token support
315316
mfaCodeProvider: async () => {
316317
this.logger.debug('MFA token needed, requesting...')
317-
const { mfaToken = '' }: { mfaToken: string } = await this.interface.prompt([
318-
{
319-
type: 'input',
320-
message: `Please enter the MFA token for ${profile}`,
321-
name: 'mfaToken'
322-
},
323-
])
318+
const { mfaToken = '' }: { mfaToken: string } =
319+
await this.interface.prompt([
320+
{
321+
type: 'input',
322+
message: `Please enter the MFA token for ${profile}`,
323+
name: 'mfaToken',
324+
},
325+
])
324326
return mfaToken
325-
}
327+
},
326328
})
327329
if (creds) {
328330
sts = new AWS.STS({ credentials: await credsFunction() })
@@ -454,7 +456,7 @@ export default class Provider extends CloudGraph.Client {
454456
* getSchema is used to get the schema for provider
455457
* @returns A string of graphql sub schemas
456458
*/
457-
getSchema(): DocumentNode {
459+
getSchema(): DocumentNode {
458460
const typesArray = loadFilesSync(path.join(__dirname), {
459461
recursive: true,
460462
extensions: ['graphql'],
@@ -495,7 +497,7 @@ export default class Provider extends CloudGraph.Client {
495497
}
496498

497499
private async getProfilesFromSharedConfig(): Promise<string[]> {
498-
let profiles = []
500+
const profiles = []
499501
try {
500502
const filesObject = await loadSharedConfigFiles()
501503
const files = Object.keys(filesObject)
@@ -861,11 +863,12 @@ export default class Provider extends CloudGraph.Client {
861863
}
862864
}
863865

864-
return this.enhanceData({
866+
const enhancedData = this.enhanceData({
865867
accounts: accounts.data[globalRegion],
866868
configuredRegions,
867869
rawData: mergedRawData,
868870
data: result,
869871
})
872+
return { ...enhancedData, errors: AwsErrorLog.errorsHistory }
870873
}
871874
}

src/utils/errorLog.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import CloudGraph from '@cloudgraph/sdk'
2+
import { ProviderError } from '@cloudgraph/sdk/dist/src/types'
23
import { AWSError } from 'aws-sdk'
34

45
const notAuthorized = 'not authorized' // part of the error string aws passes back for permissions errors
@@ -7,6 +8,9 @@ const throttling = 'Throttling'
78
const { logger } = CloudGraph
89

910
export default class AwsErrorLog {
11+
// store errors for futher analysis
12+
static errorsHistory: ProviderError[] = []
13+
1014
constructor(serviceName: string) {
1115
this.serviceName = serviceName
1216
}
@@ -35,6 +39,13 @@ export default class AwsErrorLog {
3539
logger.warn(
3640
`There was a problem getting data for service ${this.serviceName}, CG encountered an error calling ${functionName}`
3741
)
42+
43+
AwsErrorLog.errorsHistory.push({
44+
service: this.serviceName,
45+
function: functionName,
46+
message: err?.message,
47+
})
48+
3849
if (
3950
err?.message?.includes(notAuthorized) ||
4051
err?.code === accessDenied

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,10 +3474,10 @@
34743474
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
34753475
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
34763476

3477-
"@cloudgraph/sdk@^0.22.1":
3478-
version "0.22.1"
3479-
resolved "https://registry.yarnpkg.com/@cloudgraph/sdk/-/sdk-0.22.1.tgz#bf5c2f263df17b085147a3ca234ac5b0a8806545"
3480-
integrity sha512-aMrnoTRRIODAVvgtmqGZPB7Z8x1kMgKjFtLjpiHa121o0GCEZCjbxDmU8T3DwmRwI1u4QD5iKbXf9dB0573mJA==
3477+
"@cloudgraph/sdk@^0.23.0":
3478+
version "0.23.0"
3479+
resolved "https://registry.yarnpkg.com/@cloudgraph/sdk/-/sdk-0.23.0.tgz#3f6012c0e3573f527da27ebcccb8841bbeffd21b"
3480+
integrity sha512-c+Ozu8yLK3RlAcKy4d0fdTQc9JkdUJ2ESmrcW7oC5XdIARrDWQ5+Kr8AGPABOK1/UYtFyVR2JmUHnoSJdGAv6Q==
34813481
dependencies:
34823482
"@graphql-tools/load-files" "^6.5.3"
34833483
"@graphql-tools/merge" "^8.2.1"

0 commit comments

Comments
 (0)