-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1881370
commit 408f074
Showing
11 changed files
with
373 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
5 changes: 5 additions & 0 deletions
5
lambda-deployment-deck/src/updateCodeLambda/LambdaUpdateCodeStage.less
This file contains 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 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
.LambdaCodeUpdateStageConfig { | ||
} |
26 changes: 26 additions & 0 deletions
26
lambda-deployment-deck/src/updateCodeLambda/LambdaUpdateCodeStage.tsx
This file contains 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,26 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
|
||
import { | ||
ExecutionDetailsTasks, | ||
HelpContentsRegistry, | ||
IStageTypeConfig, | ||
} from '@spinnaker/core'; | ||
|
||
import { LambdaUpdateCodeExecutionDetails } from './LambdaUpdateCodeStageExecutionDetails'; | ||
import { LambdaUpdateCodeConfig, validate } from './LambdaUpdateCodeStageConfig'; | ||
|
||
export const initialize = () => { | ||
HelpContentsRegistry.register('aws.lambdaDeploymentStage.lambda', 'Lambda Name'); | ||
}; | ||
|
||
export const lambdaUpdateCodeStage: IStageTypeConfig = { | ||
key: 'Aws.LambdaUpdateCodeStage', | ||
label: `AWS Lambda Update Code`, | ||
description: 'Update code for a single AWS Lambda Function', | ||
component: LambdaUpdateCodeConfig, // stage config | ||
executionDetailsSections: [LambdaUpdateCodeExecutionDetails, ExecutionDetailsTasks], | ||
validateFn: validate, | ||
}; |
58 changes: 58 additions & 0 deletions
58
lambda-deployment-deck/src/updateCodeLambda/LambdaUpdateCodeStageConfig.tsx
This file contains 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,58 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
|
||
import { | ||
FormikStageConfig, | ||
FormValidator, | ||
IFormikStageConfigInjectedProps, | ||
IStage, | ||
IStageConfigProps, | ||
} from '@spinnaker/core'; | ||
|
||
import './LambdaUpdateCodeStage.less'; | ||
import { | ||
s3BucketNameValidator, | ||
} from '../utils/aws.validators'; | ||
import { UpdateCodeLambdaFunctionStageForm } from './components/UpdateCodeStageForm'; | ||
|
||
export function LambdaUpdateCodeConfig(props: IStageConfigProps) { | ||
return ( | ||
<div className="LambdaUpdateCodeConfig"> | ||
<FormikStageConfig | ||
{...props} | ||
validate={validate} | ||
onChange={props.updateStage} | ||
render={(props: IFormikStageConfigInjectedProps) => <UpdateCodeLambdaFunctionStageForm {...props} />} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export function validate(stageConfig: IStage) { | ||
const validator = new FormValidator(stageConfig); | ||
|
||
validator | ||
.field('account', 'Account Name') | ||
.required() | ||
|
||
validator | ||
.field('region', 'Region') | ||
.required() | ||
|
||
validator | ||
.field('functionName', 'Lambda Function Name') | ||
.required() | ||
|
||
validator | ||
.field('s3key', 'S3 Object Key') | ||
.required() | ||
|
||
validator | ||
.field('s3bucket', 'S3 Bucket Name') | ||
.required() | ||
.withValidators(s3BucketNameValidator); | ||
|
||
return validator.validateForm(); | ||
} |
27 changes: 27 additions & 0 deletions
27
lambda-deployment-deck/src/updateCodeLambda/LambdaUpdateCodeStageExecutionDetails.tsx
This file contains 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,27 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
|
||
import { | ||
ExecutionDetailsSection, | ||
IExecutionDetailsSectionProps, | ||
StageFailureMessage, | ||
} from '@spinnaker/core'; | ||
|
||
export function LambdaUpdateCodeExecutionDetails(props: IExecutionDetailsSectionProps) { | ||
const { stage, current, name } = props; | ||
return ( | ||
<ExecutionDetailsSection name={name} current={current}> | ||
<StageFailureMessage stage={stage} message={stage.outputs.failureMessage} /> | ||
<div> | ||
<p> <b> Function Name: </b> {stage.outputs.functionName ? stage.outputs.functionName : "N/A"} </p> | ||
<p> <b> Function ARN: </b> {stage.outputs.functionARN ? stage.outputs.functionARN : "N/A"} </p> | ||
</div> | ||
</ExecutionDetailsSection> | ||
); | ||
} | ||
|
||
export namespace LambdaUpdateCodeExecutionDetails { | ||
export const title = 'Lambda Update Code Stage'; | ||
} |
119 changes: 119 additions & 0 deletions
119
lambda-deployment-deck/src/updateCodeLambda/components/UpdateCodeStageForm.tsx
This file contains 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,119 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
|
||
import { | ||
AccountService, CheckboxInput, | ||
FormikFormField, | ||
HelpField, IAccount, IAccountDetails, | ||
IFormikStageConfigInjectedProps, IFormInputProps, IFunction, IRegion, ReactSelectInput, TextInput, useData | ||
} from '@spinnaker/core'; | ||
|
||
export function UpdateCodeLambdaFunctionStageForm(props: IFormikStageConfigInjectedProps) { | ||
const { values, errors } = props.formik; | ||
const { functions } = props.application; | ||
|
||
const { result: fetchAccountsResult, status: fetchAccountsStatus } = useData( | ||
() => AccountService.listAccounts('aws'), | ||
[], | ||
[], | ||
); | ||
|
||
const onAccountChange = (fieldValue: any): void => { | ||
props.formik.setFieldValue("region", null); | ||
props.formik.setFieldValue("functionName", null); | ||
|
||
props.formik.setFieldValue("account", fieldValue); | ||
}; | ||
|
||
const onRegionChange = (fieldValue: any): void => { | ||
props.formik.setFieldValue("functionName", null); | ||
props.formik.setFieldValue("region", fieldValue); | ||
}; | ||
|
||
const availableFunctions = values.account && values.region ? | ||
functions.data | ||
.filter((f: IFunction) => f.account === values.account) | ||
.filter((f: IFunction) => f.region === values.region) | ||
.map((f: IFunction) => f.functionName) : | ||
[]; | ||
|
||
return ( | ||
<div className="form-horizontal"> | ||
<h4> Basic Settings </h4> | ||
<FormikFormField | ||
label="Account" | ||
name="account" | ||
onChange={onAccountChange} | ||
required={true} | ||
input={(inputProps: IFormInputProps) => ( | ||
<ReactSelectInput | ||
{...inputProps} | ||
clearable={false} | ||
isLoading={fetchAccountsStatus === 'PENDING'} | ||
stringOptions={fetchAccountsResult.map((acc: IAccount) => acc.name)} | ||
/> | ||
)} | ||
/> | ||
<FormikFormField | ||
label="Region" | ||
name="region" | ||
onChange={onRegionChange} | ||
input={(inputProps: IFormInputProps) => ( | ||
<ReactSelectInput | ||
clearable={false} | ||
disabled={ !(values.account) } | ||
placeholder={ | ||
values.account ? | ||
"Select..." : | ||
"Select an Account..." | ||
} | ||
{...inputProps} | ||
isLoading={fetchAccountsStatus === 'PENDING'} | ||
stringOptions={fetchAccountsResult | ||
.filter((acc: IAccountDetails) => acc.name === values.account) | ||
.flatMap((acc: IAccountDetails) => acc.regions) | ||
.map((reg: IRegion) => reg.name) | ||
} | ||
/> | ||
)} | ||
/> | ||
<FormikFormField | ||
label="Function Name" | ||
name="functionName" | ||
input={(inputProps: IFormInputProps) => ( | ||
<ReactSelectInput | ||
clearable={false} | ||
disabled={ !(values.account && values.region) } | ||
placeholder={ | ||
values.account && values.region ? | ||
"Select..." : | ||
"Select an Account and Region..." | ||
} | ||
{...inputProps} | ||
stringOptions={ availableFunctions } | ||
/> | ||
)} | ||
/> | ||
<FormikFormField | ||
name="s3bucket" | ||
label="S3 Bucket" | ||
help={<HelpField id="aws.function.s3bucket" />} | ||
input={props => <TextInput {...props} placeholder="S3 bucket name" />} | ||
/> | ||
<FormikFormField | ||
name="s3key" | ||
label="S3 Key" | ||
help={<HelpField id="aws.function.s3key" />} | ||
input={props => <TextInput {...props} placeholder="object.zip" />} | ||
/> | ||
<FormikFormField | ||
name="publish" | ||
label="Publish" | ||
help={<HelpField id="aws.function.publish" />} | ||
input={props => <CheckboxInput {...props} />} | ||
/> | ||
</div> | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
lambda-deployment-deck/src/updateCodeLambda/components/index.ts
This file contains 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,4 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './UpdateCodeStageForm'; |
This file contains 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,4 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './LambdaUpdateCodeStage'; |
This file contains 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
48 changes: 48 additions & 0 deletions
48
...rc/main/java/com/amazon/aws/spinnaker/plugin/lambda/updatecode/LambdaUpdateCodeStage.java
This file contains 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,48 @@ | ||
/* | ||
* Copyright 2018 Amazon.com, Inc. or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.amazon.aws.spinnaker.plugin.lambda.updatecode; | ||
|
||
import com.amazon.aws.spinnaker.plugin.lambda.upsert.LambdaUpdateCodeTask; | ||
import com.amazon.aws.spinnaker.plugin.lambda.verify.LambdaCacheRefreshTask; | ||
import com.amazon.aws.spinnaker.plugin.lambda.verify.LambdaVerificationTask; | ||
import com.netflix.spinnaker.orca.api.pipeline.graph.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.api.pipeline.graph.TaskNode; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@Component | ||
@StageDefinitionBuilder.Aliases({"Aws.LambdaUpdateCodeStage"}) | ||
public class LambdaUpdateCodeStage implements StageDefinitionBuilder { | ||
private static Logger logger = LoggerFactory.getLogger(LambdaUpdateCodeStage.class); | ||
|
||
public LambdaUpdateCodeStage() { | ||
logger.debug("Constructing Aws.LambdaCodeUpdateStage"); | ||
} | ||
|
||
@Override | ||
public void taskGraph(@Nonnull StageExecution stage, @Nonnull TaskNode.Builder builder) { | ||
logger.debug("taskGraph for Aws.LambdaUpdateCodeStage"); | ||
builder.withTask("lambdaUpdateCodeTask", LambdaUpdateCodeTask.class); | ||
builder.withTask("lambdaVerificationTask", LambdaVerificationTask.class); | ||
builder.withTask("lambdaCacheRefreshTask", LambdaCacheRefreshTask.class); | ||
builder.withTask("lambdaWaitForCacheTask", LambdaWaitForCacheCodeUpdateTask.class); | ||
} | ||
} |
Oops, something went wrong.