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

chore: support envelope in graph:init #4947

Merged
merged 6 commits into from
Aug 15, 2022

Conversation

jasonbarry
Copy link
Contributor

@jasonbarry jasonbarry commented Aug 15, 2022

Summary

Fixes https://github.com/netlify/pillar-workflow/issues/802 (continuation of #4711)

netlify graph:init creates two new environment variables on the site. It currently saves those env vars attached to the site record in Mongo. However, env vars are moving to a separate service (called Envelope) that has its own API and that is detached from the site record. This PR adds logic to detect that if a site has opted into Envelope, to save the newly created env vars to the Envelope service.

Envelope also supports scoped environment variables, which means you can set env vars to only be present in e.g. builds or only available in functions. I think the ones that Graph sets only need to be in the functions runtime, is that correct?


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

Screenshot 2022-08-15 at 09 32 14

@github-actions github-actions bot added the type: chore work needed to keep the product and development running smoothly label Aug 15, 2022
@github-actions
Copy link

github-actions bot commented Aug 15, 2022

📊 Benchmark results

Comparing with f6c3d78

Package size: 222 MB

(no change)

^  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

let siteData = null
try {
// @ts-ignore: we need better types for our api object
siteData = await api.getSite({ siteId })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted this block of code because everything we need should already be available in command.netlify.siteInfo -- is this an incorrect assumption on my part?

netlifyGraphConfig,
})

if (process.env.NODE_ENV !== 'test') {
Copy link
Contributor Author

@jasonbarry jasonbarry Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this conditional to skip over in integration testing

{
path: 'accounts/test-account/env',
method: 'GET',
response: [envelopeResponse[1]],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test, we set NETLIFY_GRAPH_PERSIST_QUERY_TOKEN to already exist, in order to skip over some of the logic that reaches out using the OneGraph client. I didn't know how to mock that out, so skipped over it to at least test some of the function.

@jasonbarry jasonbarry marked this pull request as ready for review August 15, 2022 17:05
Copy link
Contributor

@sgrove sgrove left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wouldn't mind updating the persist query token scope, I can follow up with a quick approval.

Thanks for taking the time to port this over!

},
!env.NETLIFY_GRAPH_PERSIST_QUERY_TOKEN && {
key: 'NETLIFY_GRAPH_PERSIST_QUERY_TOKEN',
scopes: ['functions'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are scopes typed? As in, will autocomplete ensure that I'm not putting in spurious scope values?

Also, this token needs to be available in build, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scopes are defined here in the openapi spec for this method -- should anything else be needed to populate autocomplete suggestions in the cli codebase?

@jasonbarry jasonbarry self-assigned this Aug 15, 2022
@jasonbarry jasonbarry added the automerge Add to Kodiak auto merge queue label Aug 15, 2022
@kodiakhq kodiakhq bot merged commit 85e652e into main Aug 15, 2022
@kodiakhq kodiakhq bot deleted the chore/support-envelope-in-graph-init branch August 15, 2022 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Add to Kodiak auto merge queue type: chore work needed to keep the product and development running smoothly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants