-
Notifications
You must be signed in to change notification settings - Fork 14
feat(CG-1343): add ssm service support #135
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
Open
zhouse51
wants to merge
4
commits into
alpha
Choose a base branch
from
feature/CG-1343-support-ssm-service
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
caf1755
feat(CG-1343): add ssm service support
zhouse51 497dec6
remove the duplicated ssmDocument, rename ssm to systemManager
zhouse51 869e27e
add association to instance connection
zhouse51 c5200f6
Merge branch 'alpha' into feature/CG-1343-support-ssm-service
m-pizarro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import CloudGraph from '@cloudgraph/sdk' | ||
import SSM, { Activation, DescribeActivationsRequest, DescribeActivationsResult } from 'aws-sdk/clients/ssm' | ||
import { AWSError } from 'aws-sdk/lib/error' | ||
import { Config } from 'aws-sdk/lib/config' | ||
import isEmpty from 'lodash/isEmpty' | ||
import groupBy from 'lodash/groupBy' | ||
import awsLoggerText from '../../properties/logger' | ||
import { initTestEndpoint, setAwsRetryOptions } from '../../utils' | ||
import AwsErrorLog from '../../utils/errorLog' | ||
import { API_GATEWAY_CUSTOM_DELAY } from '../../config/constants' | ||
import { AwsTag, TagMap } from '../../types' | ||
import { convertAwsTagsToTagMap } from '../../utils/format' | ||
|
||
const lt = { ...awsLoggerText } | ||
const { logger } = CloudGraph | ||
const MAX_ACTIVATIONS = 50 | ||
const serviceName = 'ssmActivations' | ||
const errorLog = new AwsErrorLog(serviceName) | ||
const endpoint = initTestEndpoint(serviceName) | ||
const customRetrySettings = setAwsRetryOptions({ | ||
baseDelay: API_GATEWAY_CUSTOM_DELAY, | ||
}) | ||
|
||
/** | ||
* SSM Activation | ||
*/ | ||
|
||
export const getActivationsForRegion = async ( | ||
ssm: SSM | ||
): Promise<Activation[]> => | ||
new Promise(async resolve => { | ||
const activationList: Activation[] = [] | ||
|
||
const describeActivationsOpts: DescribeActivationsRequest = {} | ||
const listAllActivations = (token?: string): void => { | ||
describeActivationsOpts.MaxResults = MAX_ACTIVATIONS | ||
if (token) { | ||
describeActivationsOpts.NextToken = token | ||
} | ||
try { | ||
ssm.describeActivations( | ||
describeActivationsOpts, | ||
(err: AWSError, data: DescribeActivationsResult) => { | ||
if (err) { | ||
errorLog.generateAwsErrorLog({ | ||
functionName: 'ssm:describeActivations', | ||
err, | ||
}) | ||
} | ||
|
||
if (isEmpty(data)) { | ||
return resolve([]) | ||
} | ||
|
||
const { NextToken: nextToken, ActivationList: items = [] } = data || {} | ||
|
||
if (isEmpty(items)) { | ||
return resolve([]) | ||
} | ||
|
||
logger.debug(lt.fetchedSsmActivations(items.length)) | ||
|
||
activationList.push(...items) | ||
|
||
if (nextToken) { | ||
listAllActivations(nextToken) | ||
} else { | ||
resolve(activationList) | ||
} | ||
} | ||
) | ||
} catch (error) { | ||
resolve([]) | ||
} | ||
} | ||
listAllActivations() | ||
}) | ||
|
||
export interface RawAwsSsmActivation extends Omit<Activation, 'Tags'> { | ||
Tags: TagMap | ||
region: string | ||
account | ||
} | ||
|
||
export default async ({ | ||
regions, | ||
config, | ||
account, | ||
}: { | ||
account: string | ||
regions: string | ||
config: Config | ||
}): Promise<{ | ||
[region: string]: RawAwsSsmActivation[] | ||
}> => | ||
new Promise(async resolve => { | ||
const activationResult: RawAwsSsmActivation[] = [] | ||
|
||
const regionPromises = regions.split(',').map(region => { | ||
const ssm = new SSM({ | ||
...config, | ||
region, | ||
endpoint, | ||
...customRetrySettings, | ||
}) | ||
|
||
return new Promise<void>(async resolveSsmActivationData => { | ||
// Get SSM Activations | ||
const activations = await getActivationsForRegion(ssm) | ||
|
||
if (!isEmpty(activations)) { | ||
activationResult.push( | ||
...activations.map(({Tags, ...activation}) => ({ | ||
...activation, | ||
region, | ||
account, | ||
Tags: convertAwsTagsToTagMap(Tags as AwsTag[]), | ||
})) | ||
) | ||
} | ||
|
||
resolveSsmActivationData() | ||
}) | ||
}) | ||
|
||
await Promise.all(regionPromises) | ||
errorLog.reset() | ||
|
||
resolve(groupBy(activationResult, 'region')) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { RawAwsSsmActivation } from './data' | ||
import { AwsSsmActivation } from '../../types/generated' | ||
import { formatTagsFromMap } from '../../utils/format' | ||
import { ssmActivationArn } from '../../utils/generateArns' | ||
|
||
export default ({ | ||
service, | ||
account, | ||
region, | ||
}: { | ||
service: RawAwsSsmActivation | ||
account: string | ||
region: string | ||
}): AwsSsmActivation => { | ||
const { | ||
ActivationId: activationId, | ||
Description: description, | ||
DefaultInstanceName: defaultInstanceName, | ||
IamRole: iamRole, | ||
RegistrationLimit: registrationLimit, | ||
RegistrationsCount: registrationsCount, | ||
ExpirationDate: expirationDate, | ||
Expired: expired, | ||
CreatedDate: createdDate, | ||
Tags: tags, | ||
} = service | ||
|
||
const arn = ssmActivationArn({ region, account, id: activationId }) | ||
|
||
return { | ||
id: activationId, | ||
accountId: account, | ||
arn, | ||
region, | ||
description, | ||
defaultInstanceName, | ||
iamRole, | ||
registrationLimit, | ||
registrationsCount, | ||
expirationDate: expirationDate?.toISOString(), | ||
expired, | ||
createdDate: createdDate?.toISOString(), | ||
tags: formatTagsFromMap(tags), | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Service } from '@cloudgraph/sdk' | ||
import BaseService from '../base' | ||
import format from './format' | ||
import getData from './data' | ||
import mutation from './mutation' | ||
|
||
export default class Acm extends BaseService implements Service { | ||
format = format.bind(this) | ||
|
||
getData = getData.bind(this) | ||
|
||
mutation = mutation | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default `mutation($input: [AddawsSsmActivationInput!]!) { | ||
addawsSsmActivation(input: $input, upsert: true) { | ||
numUids | ||
} | ||
}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type awsSsmActivation implements awsBaseService @key(fields: "arn") { | ||
activationId: String @search(by: [hash, regexp]) | ||
description: String @search(by: [hash, regexp]) | ||
defaultInstanceName: String @search(by: [hash, regexp]) | ||
iamRole: String @search(by: [hash, regexp]) | ||
registrationLimit: Int @search | ||
registrationsCount: Int @search | ||
expirationDate: DateTime @search(by: [day]) | ||
expired: Boolean@search | ||
createdDate: DateTime @search(by: [day]) | ||
tags: [awsRawTag] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.