Skip to content

Commit 9c6ae1e

Browse files
committed
Adds OverwriteIfExists flag in workflow creation
1 parent 416407a commit 9c6ae1e

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

internal/api/workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func CreateWorkflowFromASL(e echo.Context) error {
3333

3434
// checking if the function already exists. If exists we return an error
3535
_, found := workflow.Get(creationRequest.Name)
36-
if found {
36+
if found && !creationRequest.OverwriteIfExists {
3737
log.Printf("Dropping request for already existing workflow '%s'", creationRequest.Name)
3838
return e.JSON(http.StatusConflict, "workflow already exists")
3939
}

internal/cli/cli.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func Init() {
166166
rootCmd.AddCommand(compCreateCmd)
167167
compCreateCmd.Flags().StringVarP(&compName, "workflow", "f", "", "name of the workflow")
168168
compCreateCmd.Flags().StringVarP(&jsonSrc, "src", "s", "", "source Amazon States Language file that defines the workflow")
169+
compCreateCmd.Flags().BoolVarP(&update, "update", "u", false, "Update workflow (if exists)")
169170

170171
rootCmd.AddCommand(compDeleteCmd)
171172
compDeleteCmd.Flags().StringVarP(&compName, "workflow", "f", "", "name of the workflow")
@@ -573,8 +574,10 @@ func createWorkflow(cmd *cobra.Command, args []string) {
573574
}
574575
encoded := base64.StdEncoding.EncodeToString(src)
575576
request := client.WorkflowCreationRequest{
576-
Name: compName,
577-
ASLSrc: encoded}
577+
Name: compName,
578+
ASLSrc: encoded,
579+
OverwriteIfExists: update,
580+
}
578581

579582
requestBody, err := json.Marshal(request)
580583
if err != nil {

internal/client/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type WorkflowInvocationRequest struct {
2929
}
3030

3131
type WorkflowCreationRequest struct {
32-
Name string // Name of the new workflow
33-
ASLSrc string // Specification source in Amazon State Language (encoded in Base64)
32+
Name string // Name of the new workflow
33+
ASLSrc string // Specification source in Amazon State Language (encoded in Base64)
34+
OverwriteIfExists bool
3435
}

0 commit comments

Comments
 (0)