abhilash1in / aws-secrets-manager-action

Use secrets from AWS Secrets Manager as environment variables in your GitHub Actions workflow
MIT License
68 stars 43 forks source link

Feature/custom envvar names #44

Open operatorequals opened 2 years ago

operatorequals commented 2 years ago

This PR solves https://github.com/abhilash1in/aws-secrets-manager-action/issues/42, enabling putting secrets under specific Environment Variable names. It does not work with Wildcard paths and throws an appropriate error about it.

abhilash1in commented 2 years ago

Thank you for the PR, @operatorequals! Will review it shortly.

operatorequals commented 2 years ago

Just added support for parse-json as I also needed it in my usecase.

With json secrets as:

{
  "key1":"value1",
  "key2":"value2"
}
      - name: Read secrets from AWS Secrets Manager into environment variables
        uses: operatorequals/aws-secrets-manager-action@feature/custom_envvar_names
        with:
          parse-json: true
          secrets: |
            json   | CUSTOM_ENV_VAR_JSON

populates CUSTOM_ENV_VAR_JSON_KEY1 and CUSTOM_ENV_VAR_JSON_KEY2

operatorequals commented 1 year ago

Thank you for the PR, @operatorequals! Will review it shortly.

Hello @abhilash1in ! Added an extra feature here, can you please re-trigger the tests? I am currently using this code in my builds and it works properly!

cwinters commented 1 year ago

Is it possible for this to also support having no prefix as well? So in your example, if you had:

{
  "key1":"value1",
  "key2":"value2"
}

you'd get an environment with the values:

KEY1=value1
KEY2=value2

Apologies if this is already supported, I couldn't find any mention of it.

Thanks!

cwinters commented 1 year ago

...actually, scratch my request -- I found a one-liner to do this for me; this is in Ruby but I expect it'd be similarly short in other languages:

- name: Sync ENV to AWS secrets for branch
  run: |
     aws secretsmanager get-secret-value --secret-id ${{ inputs.aws_secret_name }} --query SecretString --output text | ruby script/secret_to_env.rb >> $GITHUB_ENV

where script/secret_to_env.rb is just the following (my keys are already uppercased and underscored):

require 'json'

JSON.parse($stdin.read).each { |k, v| puts "#{k}=#{v}" }
operatorequals commented 1 year ago

Is it possible for this to also support having no prefix as well? So in your example, if you had:

{
  "key1":"value1",
  "key2":"value2"
}

you'd get an environment with the values:

KEY1=value1
KEY2=value2

Apologies if this is already supported, I couldn't find any mention of it.

Thanks!

Best you could do right now is:

            json   | _

and get keys like _KEY1 and _KEY2.

Also a syntax like:

            json   | 

must do exactly what you want!

adamwespiser commented 1 year ago

@operatorequals just so I understand,

The syntax:

            json   | 

Would be able to import json secrets without a prefix? I believe that's what would happen form checking the code, but I'm not sure.

I'd like to use this plug in, but need to be able to import json secrets with no prefix.

operatorequals commented 1 year ago

@operatorequals just so I understand,

The syntax:

            json   | 

Would be able to import json secrets without a prefix? I believe that's what would happen form checking the code, but I'm not sure.

I'd like to use this plug in, but need to be able to import json secrets with no prefix.

Try it! It should work as I explained!

FannWuCircle commented 8 months ago

@abhilash1in Is it good enough to merge back to master and bump a new version?