Skip to content
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

Directory JSON actions secrets matches YAML #954

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

TimeTravelerFromNow
Copy link

@TimeTravelerFromNow TimeTravelerFromNow commented Sep 9, 2024

🔧 Changes

Problem statement

On export, when using secrets placeholders in the actions JSON, this error occurs TypeError: secrets.map is not a function. Description in issue #955

Solution

The line of code which handles parsing of secrets during export on YAML src/context/yaml/handlers/actions.ts by switching on the type typeof action.secrets === 'string', was copied to the src/context/directory/handlers/actions.ts. This code preserves the secret placeholder when it detects a type of string, such as "@@MY_SECRETS@@". If it is an array, it will call mapSecrets(). mapSecrets() I believe gets called when the keywords are set to their values defined in the config file during an import to Auth0.

📚 References

🔬 Testing

  1. Begin with a tenant that contains an Auth0 action.
  2. Export from a tenant using the --format directory.
  3. View the directory output, and manually edit the json file for this action to have the "secrets": [] array use a placeholder value instead. "secrets": "@@MY_SECRETS@@"
  4. Define the placeholder preservation in your config file used for your export, simple example below
    exports/webapp/myconfig.json
{
  "AUTH0_ALLOW_DELETE": true,
  "AUTH0_PRESERVE_KEYWORDS": true,
  "AUTH0_KEYWORD_REPLACE_MAPPINGS": {
    "MY_SECRETS": [
      {
        "name": "M_TO_M_APP_DOMAIN",
        "value": "##AUTH0_DOMAIN##"
      }
    ]
  }
}
  1. Next, perform the export again with this config file
a0deploy export \
  --strip \
  --format directory \
  --output_folder ./exports/webapp \
  --config_file ./exports/webapp/myconfig.json \
  --debug true
  1. This error should no longer occur, the export should complete successfully, the secrets placeholder remains
2024-09-06T21:15:03.444Z - debug: TypeError: secrets.map is not a function
    at mapSecrets (/Users/sebastiandetering/.nvm/versions/node/v20.12.2/lib/node_modules/auth0-deploy-cli/lib/context/directory/handlers/actions.js:49:24)
    at mapToAction (/Users/sebastiandetering/.nvm/versions/node/v20.12.2/lib/node_modules/auth0-deploy-cli/lib/context/directory/handlers/actions.js:73:18)

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (N/A - doesnt add/ change functionality, just a fix )

@TimeTravelerFromNow TimeTravelerFromNow marked this pull request as ready for review September 11, 2024 20:27
@TimeTravelerFromNow TimeTravelerFromNow requested a review from a team as a code owner September 11, 2024 20:27
@TimeTravelerFromNow TimeTravelerFromNow marked this pull request as draft September 11, 2024 20:27
@TimeTravelerFromNow
Copy link
Author

The failing E2E test seems to be failing on master as well. Marking as ready for review, any help is appreciated!

@kushalshit27
Copy link
Contributor

@TimeTravelerFromNow
Thank you for submitting this PR! I really appreciate the time and effort you put into it, as well as your approach to tackling this issue. The code looks good overall.

I do have a suggestion for improvement:

Once you make these changes, I’ll be happy to merge your PR!

@kushalshit27
Copy link
Contributor

kushalshit27 commented Sep 19, 2024

Can you please update the same for yaml, also:

typeof action.secrets === 'string' ? action.secrets : mapSecrets(action.secrets || []), //Enables keyword preservation to operate on action secrets

I will check the failing E2E test and merge it soon. Thanks again.

@TimeTravelerFromNow
Copy link
Author

TimeTravelerFromNow commented Sep 19, 2024

Can you please update the same for yaml, also:

typeof action.secrets === 'string' ? action.secrets : mapSecrets(action.secrets || []), //Enables keyword preservation to operate on action secrets

I will check the failing E2E test and merge it soon. Thanks again.

Thanks @kushalshit27 ,
Yes I was wondering about doing the same for YAML, I'll also make that change soon.

@kushalshit27
Copy link
Contributor

Tests aren't passing because this is a fork but I've confirmed myself that they pass.

Looks good, thanks for the contribution!

@kushalshit27
Copy link
Contributor

kushalshit27 commented Sep 27, 2024

Hi, @TimeTravelerFromNow

According to the new commit rule, the commits should be signed to enhance security, authorship, trust and compliance.

Updated the Contribution doc also.

Please update the PR with signed commits, and we will be able to merge your PR!

@TimeTravelerFromNow TimeTravelerFromNow force-pushed the json-action-secrets-map branch 2 times, most recently from 27a769e to d76d33b Compare September 28, 2024 20:05
@TimeTravelerFromNow TimeTravelerFromNow marked this pull request as draft September 28, 2024 20:08
Signed-off-by: Sebastian Detering <[email protected]>
Signed-off-by: Sebastian Detering <[email protected]>
Rebased to master
kushalshit27
kushalshit27 previously approved these changes Sep 30, 2024
kushalshit27
kushalshit27 previously approved these changes Sep 30, 2024
@kushalshit27 kushalshit27 requested review from developerkunal and removed request for developerkunal September 30, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants