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

Add eas env:push and env:pull commands #2437

Conversation

khamilowicz
Copy link
Contributor

@khamilowicz khamilowicz commented Jun 17, 2024

Why

User should be able to synchronise local environment variables with upstream.

How

  • added eas env:pull and eas env:push commands
  • eas env:pull handles sudo access to request values of sensitive variables

Test Plan

Tested manually

Copy link

linear bot commented Jun 17, 2024

Copy link

github-actions bot commented Jun 17, 2024

Size Change: +3.7 kB (+0.01%)

Total Size: 52.5 MB

Filename Size Change
./packages/eas-cli/dist/eas-linux-x64.tar.gz 52.5 MB +3.7 kB (+0.01%)

compressed-size-action

@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch from 499c5d9 to 8bd1071 Compare June 17, 2024 12:23
@khamilowicz khamilowicz changed the title Piotrekszeremeta/eng 11920 add eas envpush command add eas envpush command Jun 17, 2024
@khamilowicz khamilowicz changed the title add eas envpush command Add eas env:push and env:pull commands Jun 17, 2024
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch from 8bd1071 to db531a4 Compare June 17, 2024 13:16
Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 23.88060% with 153 lines in your changes missing coverage. Please review.

Project coverage is 52.68%. Comparing base (27d0d42) to head (1f07455).

Files Patch % Lines
packages/eas-cli/src/commands/env/push.ts 16.86% 67 Missing and 7 partials ⚠️
packages/eas-cli/src/commands/env/pull.ts 36.12% 20 Missing and 3 partials ⚠️
packages/eas-cli/src/user/SessionManager.ts 17.86% 21 Missing and 2 partials ⚠️
packages/eas-cli/src/authUtils.ts 10.00% 8 Missing and 1 partial ⚠️
packages/eas-cli/src/commands/env/get.ts 10.00% 8 Missing and 1 partial ⚠️
...c/graphql/mutations/EnvironmentVariableMutation.ts 0.00% 3 Missing ⚠️
packages/eas-cli/src/commands/env/delete.ts 0.00% 2 Missing ⚠️
packages/eas-cli/src/commands/env/list.ts 0.00% 2 Missing ⚠️
...i/src/graphql/queries/EnvironmentVariablesQuery.ts 0.00% 2 Missing ⚠️
...ages/eas-cli/src/user/fetchSessionSecretAndUser.ts 33.34% 2 Missing ⚠️
... and 4 more
Additional details and impacted files
@@                                   Coverage Diff                                    @@
##           piotrekszeremeta/eng-11913-add-eas-envcreate-command    #2437      +/-   ##
========================================================================================
- Coverage                                                 52.94%   52.68%   -0.25%     
========================================================================================
  Files                                                       542      545       +3     
  Lines                                                     20063    20247     +184     
  Branches                                                   4101     4136      +35     
========================================================================================
+ Hits                                                      10620    10665      +45     
- Misses                                                     8630     8755     +125     
- Partials                                                    813      827      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11913-add-eas-envcreate-command branch from 2b270de to 37c7b6a Compare June 17, 2024 16:38
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch 3 times, most recently from 05552ae to 5aa373c Compare June 19, 2024 11:00
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11913-add-eas-envcreate-command branch from 3eb0466 to f8dc407 Compare July 24, 2024 12:12
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch 2 times, most recently from f821dbb to 7c6f532 Compare August 1, 2024 14:51
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11913-add-eas-envcreate-command branch from f8dc407 to 114acb6 Compare August 1, 2024 15:11
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch 2 times, most recently from e807c8d to 70be519 Compare August 1, 2024 15:35
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11913-add-eas-envcreate-command branch 2 times, most recently from 710782b to 63928f0 Compare August 1, 2024 15:53
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch 3 times, most recently from 0365364 to 8d097bf Compare August 5, 2024 13:40
@khamilowicz khamilowicz marked this pull request as ready for review August 5, 2024 13:44
packages/eas-cli/src/authUtils.ts Show resolved Hide resolved
packages/eas-cli/src/commands/env/pull.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/pull.ts Show resolved Hide resolved
packages/eas-cli/src/commands/env/pull.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/pull.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
Copy link
Member

@szdziedzic szdziedzic left a comment

Choose a reason for hiding this comment

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

I'm not an expert on our auth/sudo system. Let's ask for the @wschurman review as well.

packages/eas-cli/src/user/SessionManager.ts Outdated Show resolved Hide resolved
Comment on lines +283 to +288
private async ssoSudoUpgradeAsync(): Promise<void> {
throw Error('Sudo upgrade with SSO is not yet supported');
}
Copy link
Member

Choose a reason for hiding this comment

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

We need to figure out how to handle this case. We definitely want to allow SSO clients to pull env vars.

Copy link
Member

Choose a reason for hiding this comment

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

Yep. This will need to do something similar to how SSO login is done in the CLI (using the website I believe). Can trace the SSO code in the CLI ssoLoginAsync to see how SSO auth works. Happy to dig deeper if necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Would be good to stack a PR on top of this that adds SSO and then land them together.

packages/eas-cli/src/user/SessionManager.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/authUtils.ts Show resolved Hide resolved
packages/eas-cli/src/authUtils.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/authUtils.ts Outdated Show resolved Hide resolved
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch 2 times, most recently from f246d72 to 3ebe97d Compare August 7, 2024 16:03
Copy link
Member

@wschurman wschurman left a comment

Choose a reason for hiding this comment

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

Since eas-cli doesn't have feature gating and does continuous deployment it'd probably be best to have the SSO functionality ironed out in a stacked PR before landing this. Otherwise we'd risk deploying a broken experience. Though I guess since the command is new and hidden it's okay for now, we can just fast-follow with the SSO fix.

Comment on lines +283 to +288
private async ssoSudoUpgradeAsync(): Promise<void> {
throw Error('Sudo upgrade with SSO is not yet supported');
}
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to stack a PR on top of this that adds SSO and then land them together.

packages/eas-cli/src/commands/env/pull.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/pull.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch from 3ebe97d to 50a54a8 Compare August 9, 2024 11:42
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11913-add-eas-envcreate-command branch from 9971a16 to 54af248 Compare August 9, 2024 11:49
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch from 50a54a8 to c66be42 Compare August 9, 2024 11:49
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11913-add-eas-envcreate-command branch from 54af248 to 6f6faf5 Compare August 9, 2024 11:55
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch from c66be42 to 621c5ad Compare August 9, 2024 11:55
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11913-add-eas-envcreate-command branch from 6f6faf5 to 27d0d42 Compare August 9, 2024 11:59
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch from 621c5ad to 676c707 Compare August 9, 2024 11:59
@khamilowicz khamilowicz force-pushed the piotrekszeremeta/eng-11920-add-eas-envpush-command branch from 676c707 to 3f8749c Compare August 9, 2024 13:07
@khamilowicz
Copy link
Contributor Author

@wschurman @szdziedzic Ok, I'll work on SSO. I think the flow will be similar to that of login via SSO and I'll reuse some of its logic

packages/eas-cli/src/commands/env/pull.ts Outdated Show resolved Hide resolved
const { appVariables } = await EnvironmentVariablesQuery.byAppIdAsync(
graphqlClient,
projectId,
const { appVariables } = await EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
Copy link
Member

Choose a reason for hiding this comment

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

Should we allow getting sensitive env vars values here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we allow it here

.appVariables
: await EnvironmentVariablesQuery.sharedAsync(graphqlClient, projectId);
? (
await EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
Copy link
Member

Choose a reason for hiding this comment

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

should we allow pulling sensitive env vars here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe with '--include-sensitive' flag? We'll save on decrypting values when user just want to know whether a variable is defined.

packages/eas-cli/src/commands/env/pull.ts Show resolved Hide resolved
packages/eas-cli/src/commands/env/pull.ts Outdated Show resolved Hide resolved
import SessionManager from './user/SessionManager';

// Handle the case where a user needs to be in sudo mode to perform an action.
export async function withSudoModeAsync<T>(
Copy link
Member

Choose a reason for hiding this comment

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

I believe it doesn't respect --non-interactive mode, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it wouldn't make sense to automatically reauthorize in non-interactive mode.

packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
packages/eas-cli/src/commands/env/push.ts Outdated Show resolved Hide resolved
Copy link

❌ It looks like a changelog entry is missing for this PR. You have two options: you can add it manually, or you can use the changelog bot to do it for you.
🤖 To use the bot, simply comment on this PR with the command /changelog-entry [breaking-change|new-feature|bug-fix|chore] [message].
⏩ If this PR doesn't require a changelog entry, such as if it's an internal change that doesn't affect the user experience, you can add the "no changelog" label to the PR.

Comment on lines +3 to +21
// Handle the case where a user needs to be in sudo mode to perform an action.
export async function withSudoModeAsync<T>(
sessionManager: SessionManager,
graphqlQuery: () => Promise<T>
): Promise<T> {
try {
return await graphqlQuery();
} catch (error: any) {
const isSudoError = error.graphQLErrors?.some(
(err: { extensions: { errorCode: string } }) =>
err?.extensions?.errorCode === 'SUDO_MODE_REQUIRED'
);
if (!isSudoError) {
throw error;
}
await sessionManager.showSudoPromptAsync({ sso: false });
return await graphqlQuery();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Offline discussion feedback:

It seems like requiring sudo mode is problematic for now, it doesn't work for SSO auth and doesn't seem to work with --non-interactive mode, which is a big use case. For now, we decided to allow people to read sensitive env vars without sudo mode. This will require backend changes + dropping sudo logic from this PR.

@khamilowicz khamilowicz merged commit 1f07455 into piotrekszeremeta/eng-11913-add-eas-envcreate-command Aug 13, 2024
8 of 9 checks passed
@khamilowicz khamilowicz deleted the piotrekszeremeta/eng-11920-add-eas-envpush-command branch August 13, 2024 13:29
@khamilowicz khamilowicz restored the piotrekszeremeta/eng-11920-add-eas-envpush-command branch August 13, 2024 13:53
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.

3 participants