@ossy/deployment-tools 0.0.31 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/aws-credentials-client.ts +11 -7
- package/src/deployment-queue-client.ts +9 -6
- package/src/log/index.ts +2 -7
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ import { Credentials } from '@aws-sdk/types'
|
|
|
6
6
|
|
|
7
7
|
export class AwsCredentialsClient {
|
|
8
8
|
|
|
9
|
-
static resolveAwsCredentials({ awsAccountId, awsRegion, awsRoleToAssume }: DeploymentPlatform)
|
|
9
|
+
static resolveAwsCredentials({ awsAccountId, awsRegion, awsRoleToAssume }: DeploymentPlatform) {
|
|
10
10
|
// If awsRoleToAssume is present, then we assume we run in a github workflow
|
|
11
11
|
// If awsRoleToAssume is not present, then we assume they are resolved localy by aws-sdk
|
|
12
12
|
if (!awsRoleToAssume) {
|
|
@@ -20,6 +20,7 @@ export class AwsCredentialsClient {
|
|
|
20
20
|
return core.getIDToken('sts.amazonaws.com')
|
|
21
21
|
.then(webIdentityToken => {
|
|
22
22
|
logInfo({ message: `[AwsCredentialsClient] Attempting to resolve aws credentials by assuming the role: ${awsRoleToAssume}` })
|
|
23
|
+
logDebug({ message: '[AwsCredentialsClient] webIdentityToken', data: webIdentityToken })
|
|
23
24
|
return stsClient.send(new AssumeRoleWithWebIdentityCommand({
|
|
24
25
|
RoleArn: `arn:aws:iam::${awsAccountId}:role/${awsRoleToAssume}`,
|
|
25
26
|
RoleSessionName: 'GitHubActions',
|
|
@@ -27,12 +28,15 @@ export class AwsCredentialsClient {
|
|
|
27
28
|
WebIdentityToken: webIdentityToken
|
|
28
29
|
}))
|
|
29
30
|
})
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
.then(responseData => ({
|
|
32
|
+
AccessKeyId: responseData.Credentials.AccessKeyId,
|
|
33
|
+
SessionToken: responseData.Credentials.SessionToken,
|
|
34
|
+
SecretAccessKey: responseData.Credentials.SecretAccessKey,
|
|
35
|
+
accessKeyId: responseData.Credentials.AccessKeyId,
|
|
36
|
+
sessionToken: responseData.Credentials.SessionToken,
|
|
37
|
+
secretAccessKey: responseData.Credentials.SecretAccessKey,
|
|
38
|
+
}))
|
|
39
|
+
// .then(responseData => responseData.Credentials)
|
|
36
40
|
.then(data => {
|
|
37
41
|
logDebug({ message: '[AwsCredentialsClient] AssumeRoleWithWebIdentityCommand responseData.Credentials', data })
|
|
38
42
|
return data
|
|
@@ -6,29 +6,32 @@ import {
|
|
|
6
6
|
} from '@aws-sdk/client-sqs'
|
|
7
7
|
import { DeploymentPlatform, ContainerDeploymentRequest } from 'types'
|
|
8
8
|
import { AwsCredentialsClient } from 'aws-credentials-client'
|
|
9
|
-
import { logInfo, logError } from 'log'
|
|
9
|
+
import { logInfo, logError, logDebug } from 'log'
|
|
10
10
|
|
|
11
11
|
export class DeploymentQueueClient {
|
|
12
12
|
|
|
13
13
|
static sendDeploymentRequest(deploymentPlatform: DeploymentPlatform, deploymentRequest: ContainerDeploymentRequest) {
|
|
14
|
-
logInfo({
|
|
14
|
+
logInfo({ message: '[DeploymentQueueClient] Starting deployment sequence' })
|
|
15
15
|
return DeploymentQueueClient.createAwsSqsClient(deploymentPlatform)
|
|
16
16
|
.then(sqsClient => {
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const sendMessageParams = {
|
|
19
19
|
QueueUrl: deploymentPlatform.awsDeploymentSqsArn,
|
|
20
20
|
MessageBody: JSON.stringify(deploymentRequest)
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
logDebug({ message: '[DeploymentQueueClient] SendMessageCommand params', data: sendMessageParams })
|
|
24
|
+
const command = new SendMessageCommand(sendMessageParams)
|
|
22
25
|
|
|
23
26
|
return sqsClient.send(command)
|
|
24
|
-
.then(() => logInfo({
|
|
27
|
+
.then(() => logInfo({ message: '[DeploymentQueueClient] Deployment request sent' }))
|
|
25
28
|
.catch(error => logError({ message: '[DeploymentQueueClient] Could not send deployment request', error }))
|
|
26
29
|
})
|
|
27
30
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
static pollForDeploymentRequests(deploymentPlatform: DeploymentPlatform, handleDeploymentRequest: (deploymentRequest: ContainerDeploymentRequest) => Promise<void>) {
|
|
31
|
-
logInfo({
|
|
34
|
+
logInfo({ message: '[DeploymentQueueClient] Starting polling for deployment requests' })
|
|
32
35
|
DeploymentQueueClient.createAwsSqsClient(deploymentPlatform).then(sqsClient => {
|
|
33
36
|
const FIVE_MINUTES = 3000
|
|
34
37
|
|
package/src/log/index.ts
CHANGED
|
@@ -11,13 +11,8 @@ enum TypeOfMessage {
|
|
|
11
11
|
Debug = 'DEBUG'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const log = (...params) => {
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function prefixTo(prefix: string, message: string) {
|
|
19
|
-
`[${prefix}]${message.startsWith('[') ? '' : ': '}`
|
|
20
|
-
}
|
|
14
|
+
const log = (...params) => { console.log(...params) }
|
|
15
|
+
const prefixTo = (prefix: string, message: string) => `[${prefix}]${message.startsWith('[') ? '' : ': '}`
|
|
21
16
|
|
|
22
17
|
export const logInfo = logInput => {
|
|
23
18
|
const messagePrefix = prefixTo(TypeOfMessage.Info, logInput.message)
|