Skip to content

chore: inject the Authlify Token in netlify dev #4167

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

Merged
merged 6 commits into from
Feb 4, 2022

Conversation

anmonteiro
Copy link
Contributor

🎉 Thanks for submitting a pull request! 🎉

Summary


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)

squirrel yelling at husky hooks

Sorry, something went wrong.

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

github-actions bot commented Feb 2, 2022

📊 Benchmark results

Comparing with fc1c991

Package size: 362 MB

⬆️ 0.14% increase vs. fc1c991

^  360 MB  360 MB  360 MB  360 MB  360 MB  360 MB  360 MB  360 MB  360 MB  360 MB  360 MB  360 MB  362 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

@anmonteiro anmonteiro requested a review from sgrove February 2, 2022 02:01
authlifyJWT == null
? {}
: {
ONEGRAPH_AUTHLIFY_TOKEN: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

follows the format expected by injectEnvVariables. Not sure if there's a helper to create this?

@@ -105,6 +106,11 @@ const createHandler = function ({ functionsRegistry }) {
rawQuery,
}

if (config.authlify && config.authlify.authlifyTokenId != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

follows https://github.com/netlify/proxy/pull/719 by injecting the token whenever there's an authlify token ID, and not only when --graph is passed.

Verified

This commit was signed with the committer’s verified signature.
caendesilva Caen De Silva

Verified

This commit was signed with the committer’s verified signature.
caendesilva Caen De Silva
sgrove
sgrove previously approved these changes Feb 2, 2022
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.

The only concern I have is that we're exposing authlifyToken to end users when it should probably be netlifyGraphToken. Let's say that's fine for the beta period, and then migrate users off of it (well) before GA.

@anmonteiro
Copy link
Contributor Author

anmonteiro commented Feb 3, 2022

Tests seem flakey and unrelated to my changes -- they fail in different OSes in different runs, for different tests 😢.

I'm planning on merging this later today if there are no objections. I'll follow up with a fix if indeed there are broken things.

EDIT: trying to get them to pass after #4164

Verified

This commit was signed with the committer’s verified signature.
caendesilva Caen De Silva
@anmonteiro anmonteiro added the automerge Add to Kodiak auto merge queue label Feb 3, 2022
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Hi @sgrove and @anmonteiro.

I added 2 comments

@@ -253,7 +254,29 @@ const dev = async (options, command) => {
)
}

await injectEnvVariables({ env: command.netlify.cachedConfig.env, site })
const startNetlifyGraphWatcher = Boolean(options.graph)
const netlifyToken = await command.authenticate()
Copy link
Contributor

@erezrokah erezrokah Feb 3, 2022

Choose a reason for hiding this comment

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

This will open up a browser and authenticate if users are not logged in.
This is not the expected behavior for the CLI as ntl dev should not require it.

We can put this under the graph condition for now, but we should probably have better error reporting.
Users can also pass --offline to the dev command which should prevent any requests from being sent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we'll need the netlify bearer token for the user. What's an alternative way of getting it?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the way to get it. We should only do it when running with graph I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There’s also the API Authentication use case. I can do it only in the presence of an authlify token ID, then. Appreciate the review!

authlifyJWT == null
? {}
: {
ONEGRAPH_AUTHLIFY_TOKEN: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do we want ONEGRAPH_AUTHLIFY_TOKEN injected to?

The PR description says builds and functions.
This injects it into functions and dev command, but not builds

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's injected in builds via Bitballoon.

Are there local builds where I should inject the variable too?

Copy link
Contributor

Choose a reason for hiding this comment

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

The CLI has a build command

command.setAnalyticsPayload({ dry: options.dry })

The CLI gets all the configuration, including environment variables from netlify/config, so I wonder if it will be easier to implement this PR in that package.
See the code to retrieve site information in https://github.com/netlify/build/blob/dc76f4b27a9fe92395c7d20346ce1655f8340d8c/packages/config/src/api/site_info.js

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 feel like this is more specific to the CLI than the generic config package.

@erezrokah are you on board if we merge this with the current functionality to unblock Mathias's upcoming talk and make the build improvements later?

@anmonteiro anmonteiro removed the automerge Add to Kodiak auto merge queue label Feb 3, 2022

Verified

This commit was signed with the committer’s verified signature.
caendesilva Caen De Silva
…s on
@erezrokah erezrokah enabled auto-merge (squash) February 4, 2022 10:32
@erezrokah erezrokah disabled auto-merge February 4, 2022 10:36
@erezrokah erezrokah enabled auto-merge (squash) February 4, 2022 10:36
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Hi @anmonteiro, I'm good with unblocking.

I think it will great to follow up with a test case for this, do you mind opening an issue for it?

Do you mind opening another issue for supporting this in ntl build? If we inject the auth token in our build system, will should inject it to ntl build too.

@erezrokah erezrokah merged commit 4ffba32 into main Feb 4, 2022
@erezrokah erezrokah deleted the anmonteiro/authlify-token-in-dev branch February 4, 2022 10:51
@erezrokah
Copy link
Contributor

This is released in https://github.com/netlify/cli/releases/tag/v8.15.5

@anmonteiro
Copy link
Contributor Author

Thanks, @erezrokah! I opened #4182 and #4181 per your suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

None yet

3 participants