-
Notifications
You must be signed in to change notification settings - Fork 5
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
Allow a State to set a value in Credentials for subsequent states #145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,38 @@ You can provide that at runtime via the `--credentials` parameter: | |
bundle exec ruby exe/floe --workflow my-workflow.asl --credentials='{"roleArn": "arn:aws:iam::111122223333:role/LambdaRole"}' | ||
``` | ||
|
||
If you need to set a credential at runtime you can do that by using the `"ResultPath": "$.Credentials"` directive, for example to user a username/password to login and get a Bearer token: | ||
|
||
``` | ||
bundle exec ruby exe/floe --workflow my-workflow.asl --credentials='{"username": "user", "password": "pass"}' | ||
``` | ||
|
||
```json | ||
{ | ||
"StartAt": "Login", | ||
"States": { | ||
"Login": { | ||
"Type": "Task", | ||
"Resource": "docker://login:latest", | ||
"Credentials": { | ||
"username.$": "$.username", | ||
"password.$": "$.password" | ||
}, | ||
"ResultPath": "$.Credentials", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to state where in the credentials hash this will go? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary since the If I did (and if I didn't have the |
||
"Next": "DoSomething" | ||
}, | ||
"DoSomething": { | ||
"Type": "Task", | ||
"Resource": "docker://do-something:latest", | ||
"Credentials": { | ||
"token.$": "$.bearer_token" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Ruby Library | ||
|
||
```ruby | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"Comment": "An example showing how to set a credential.", | ||
"StartAt": "Login", | ||
"States": { | ||
"Login": { | ||
"Type": "Task", | ||
"Resource": "docker://docker.io/agrare/echo:latest", | ||
"Parameters": { | ||
"ECHO": "TOKEN" | ||
}, | ||
"ResultPath": "$.Credentials", | ||
"ResultSelector": { | ||
"bearer_token.$": "$.echo" | ||
}, | ||
"Next": "DoSomething" | ||
}, | ||
"DoSomething": { | ||
"Type": "Task", | ||
"Resource": "docker://docker.io/agrare/hello-world:latest", | ||
"Credentials": { | ||
"bearer_token.$": "$.bearer_token" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Floe | ||
class Workflow | ||
module States | ||
module InputOutputMixin | ||
def process_input(input) | ||
input = input_path.value(context, input) | ||
input = parameters.value(context, input) if parameters | ||
input | ||
end | ||
|
||
def process_output(input, results) | ||
return input if results.nil? | ||
return if output_path.nil? | ||
|
||
results = result_selector.value(context, results) if @result_selector | ||
if result_path.payload.start_with?("$.Credentials") | ||
credentials = result_path.set(workflow.credentials, results)["Credentials"] | ||
workflow.credentials.merge!(credentials) | ||
output = input | ||
else | ||
output = result_path.set(input, results) | ||
end | ||
|
||
output_path.value(context, output) | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use asl here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it, but I actually think the json markup actually renders nicer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asl
doesn't differentiate between keys and values, and doesn't even markup the booleanThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fryguy do you still want to do the
asl
tag even though I think it is objectively worse?