This repository was archived by the owner on Feb 3, 2021. It is now read-only.
File tree 9 files changed +43
-31
lines changed
9 files changed +43
-31
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Iot } from 'aws-sdk'
2
2
import { CloudFormationCustomResourceEvent } from 'aws-lambda'
3
3
import { paginate } from '../util/paginate'
4
4
import { cfnResponse , ResponseStatus } from '@bifravst/cloudformation-helpers'
5
+ import { isNullOrUndefined } from 'util'
5
6
6
7
const iot = new Iot ( )
7
8
@@ -32,7 +33,7 @@ export const handler = async (
32
33
thingGroupProperties : ThingGroupProperties ,
33
34
} )
34
35
. promise ( )
35
- if ( thingGroupArn === undefined ) {
36
+ if ( isNullOrUndefined ( thingGroupArn ) ) {
36
37
throw new Error ( `Failed to create thing group ${ ThingGroupName } !` )
37
38
}
38
39
await iot
Original file line number Diff line number Diff line change 1
1
import { Iot } from 'aws-sdk'
2
+ import { isNullOrUndefined } from 'util'
2
3
3
4
export const getIotEndpoint = async ( iot : Iot ) : Promise < string > =>
4
5
iot
5
6
. describeEndpoint ( { endpointType : 'iot:Data-ATS' } )
6
7
. promise ( )
7
8
. then ( ( { endpointAddress } ) => {
8
- if ( endpointAddress === undefined ) {
9
+ if ( isNullOrUndefined ( endpointAddress ) ) {
9
10
throw new Error ( `Failed to resolved AWS IoT endpoint` )
10
11
}
11
12
return endpointAddress
Original file line number Diff line number Diff line change 1
1
import { CloudFormation } from 'aws-sdk'
2
2
import { stackId } from '../stacks/stackId'
3
+ import { isNullOrUndefined } from 'util'
3
4
4
5
const cf = new CloudFormation ( {
5
6
region : process . env . AWS_DEFAULT_REGION ,
@@ -13,7 +14,7 @@ export const getLambdaSourceCodeBucketName = async (): Promise<string> => {
13
14
} )
14
15
. promise ( )
15
16
. then ( ( { Stacks } ) => {
16
- if ( Stacks === undefined || ! Stacks . length ) {
17
+ if ( isNullOrUndefined ( Stacks ) || ! Stacks . length ) {
17
18
throw new Error ( `${ StackName } stack is not available.` )
18
19
} else {
19
20
const stack = Stacks [ 0 ]
Original file line number Diff line number Diff line change @@ -18,29 +18,28 @@ export const purgeIotUserPolicyPrincipals = ({
18
18
const policyName = userIotPolicyArn ?. split ( '/' ) . pop ( ) as string
19
19
const iot = new Iot ( { region } )
20
20
await paginate ( {
21
- paginator : async ( marker ?: any ) =>
22
- iot
21
+ paginator : async ( marker ?: any ) => {
22
+ const { principals , nextMarker } = await iot
23
23
. listPolicyPrincipals ( {
24
24
policyName,
25
25
marker,
26
26
} )
27
27
. promise ( )
28
- . then ( async ( { principals, nextMarker } ) => {
29
- await Promise . all (
30
- principals ?. map ( async ( principal ) => {
31
- console . log (
32
- `Detaching principal ${ principal } from policy ${ policyName } ...` ,
33
- )
34
- return iot
35
- . detachPrincipalPolicy ( {
36
- policyName,
37
- principal,
38
- } )
39
- . promise ( )
40
- } ) ?? [ ] ,
28
+ await Promise . all (
29
+ principals ?. map ( async ( principal ) => {
30
+ console . log (
31
+ `Detaching principal ${ principal } from policy ${ policyName } ...` ,
41
32
)
42
- return nextMarker
43
- } ) ,
33
+ return iot
34
+ . detachPrincipalPolicy ( {
35
+ policyName,
36
+ principal,
37
+ } )
38
+ . promise ( )
39
+ } ) ?? [ ] ,
40
+ )
41
+ return nextMarker
42
+ } ,
44
43
} )
45
44
} ,
46
45
help : 'Purges all principals from the user IoT policy' ,
Original file line number Diff line number Diff line change @@ -11,10 +11,7 @@ import * as path from 'path'
11
11
import { device , thingShadow } from 'aws-iot-device-sdk'
12
12
import { deviceFileLocations } from '../../cli/jitp/deviceFileLocations'
13
13
import { expect } from 'chai'
14
-
15
- const isNullOrUndefined = ( arg ?: unknown | null ) : boolean =>
16
- arg === undefined || arg === null
17
- const isNotNullOrUndefined = ( arg ?: unknown | null ) => ! isNullOrUndefined ( arg )
14
+ import { isNotNullOrUndefined } from '../../util/isNullOrUndefined'
18
15
19
16
const connect = ( mqttEndpoint : string ) => ( clientId : string ) => {
20
17
const deviceFiles = deviceFileLocations ( {
Original file line number Diff line number Diff line change 1
1
import { S3 } from 'aws-sdk'
2
+ import {
3
+ isNotNullOrUndefined ,
4
+ isNullOrUndefined ,
5
+ } from '../util/isNullOrUndefined'
2
6
3
7
export type CollectFilesArgs = {
4
8
Prefix : string
@@ -42,14 +46,14 @@ export const collectFiles = ({
42
46
if ( d >= notAfterDate ) {
43
47
return files
44
48
}
45
- if ( files [ d ] === undefined ) {
49
+ if ( isNullOrUndefined ( files [ d ] ) ) {
46
50
files [ d ] = [ file ]
47
51
} else {
48
52
files [ d ] . push ( file )
49
53
}
50
54
return files
51
55
} , files ?? { } )
52
- if ( NextMarker !== undefined ) {
56
+ if ( isNotNullOrUndefined ( NextMarker ) ) {
53
57
return collectFiles ( { Bucket, s3 } ) ( {
54
58
files : f ,
55
59
Marker : NextMarker ,
Original file line number Diff line number Diff line change
1
+ export const isNullOrUndefined = ( arg ?: unknown | null ) : boolean =>
2
+ arg === undefined || arg === null
3
+
4
+ export const isNotNullOrUndefined = ( arg ?: unknown | null ) : boolean =>
5
+ ! isNullOrUndefined ( arg )
Original file line number Diff line number Diff line change
1
+ import { isNotNullOrUndefined } from './isNullOrUndefined'
2
+
1
3
/**
2
4
* Iteratively follows paginated results.
3
5
* NOTE: This method has no upper runtime limit and may time out.
@@ -10,7 +12,7 @@ export const paginate = async ({
10
12
startKey ?: any
11
13
} ) : Promise < void > => {
12
14
const nextStartKey = await paginator ( startKey )
13
- if ( nextStartKey !== undefined ) {
15
+ if ( isNotNullOrUndefined ( nextStartKey ) ) {
14
16
await paginate ( {
15
17
paginator,
16
18
startKey : nextStartKey ,
You can’t perform that action at this time.
0 commit comments