Skip to content

[public-api] Migrate envvarService #19067

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 7 commits into from
Nov 20, 2023
Merged

[public-api] Migrate envvarService #19067

merged 7 commits into from
Nov 20, 2023

Conversation

jeanp413
Copy link
Member

@jeanp413 jeanp413 commented Nov 14, 2023

Description

Summary generated by Copilot

🤖 Generated by Copilot at 2d8b9cb

This pull request adds a new public API service for managing user environment variables for workspaces. It defines the service and its messages using Protobuf, generates client and server code for gRPC and Connect in Go and TypeScript, and implements the service handler and client in the server and dashboard components. It also refactors the dashboard component for environment variables to use the new public API service.

Related Issue(s)

Fixes #

How to test

  • It should be able to CRUD env in org, configuration and user level
  • Start workspace in org, envs in org + user should be in workspace
  • Start workspace in org + configuration, envs in org + configuration + user should be in workspace
  • Create a new org, there should only have user envs in workspace

Documentation

Preview status

Gitpod was successfully deployed to your preview environment.

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

@jeanp413
Copy link
Member Author

@akosyakov could you review again 🙏

message ResolveWorkspaceEnvironmentVariablesRequest { string workspace_id = 1; }

message ResolveWorkspaceEnvironmentVariablesResponse {
message EnvironmentVariable {
Copy link
Member

Choose a reason for hiding this comment

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

generally looks good, not sure about it, maybe it is find to have it on global level?

@akosyakov
Copy link
Member

@jeanp413 it looks ok, you can consider moving proto file and generated classes in another PR, to make this PR small, I will approve it to unblock.

@jeanp413 jeanp413 mentioned this pull request Nov 16, 2023
15 tasks
@jeanp413
Copy link
Member Author

@akosyakov moved the proto files to another PR #19085

@jeanp413
Copy link
Member Author

jeanp413 commented Nov 17, 2023

/gh run recreate-vm

Comment triggered a workflow run

Started workflow run: 6900579887

  • recreate_vm: true

@jeanp413
Copy link
Member Author

Tested and it's working

@akosyakov
Copy link
Member

@jeanp413 open for a review?

@jeanp413 jeanp413 marked this pull request as ready for review November 17, 2023 08:51
@jeanp413 jeanp413 requested a review from a team as a code owner November 17, 2023 08:51
repositoryPattern: "",
};

await this.envVarService.deleteUserEnvVar(context.user.id, context.user.id, variable);
Copy link
Member

Choose a reason for hiding this comment

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

why is not enough to pass id?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's needed for old api resource guard validation

Copy link
Member

Choose a reason for hiding this comment

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

yeah, ignore my noise on gRPC implementation here, when we get rid of JSON-RPC we can simplify, don't want to block with it

Copy link
Member Author

Choose a reason for hiding this comment

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

Already updated a couple 😅

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

I left comment on gRPC implementation. I think at least we should fix error propagation, logic looks unnecessary complicated, but it seems because of underlying application service design. I wonder whether we can improve it, if it is too much work let's go with what we have for now.

@mustard-mh mustard-mh self-requested a review November 17, 2023 09:46
@mustard-mh
Copy link
Contributor

mustard-mh commented Nov 20, 2023

Add some nit changes cd19ba3

❌ Failed to update user env, checked that list API has respond with id. Going to update code

image

@mustard-mh
Copy link
Contributor

I tried to create workspace with another ORG, it seems new workspace still includes previous ORG envs (the same repo)

@jeanp413
Copy link
Member Author

jeanp413 commented Nov 20, 2023

org env? you mean user env or project env?

@mustard-mh
Copy link
Contributor

mustard-mh commented Nov 20, 2023

org env? you mean user env or project env?

I mean org project env.

Seems something wrong in our code.

Project 0c893085-6a88-4718-b5e9-4fddc52b5ae3 below to org d319b06f-3a73-4595-a341-ab63ff0fd65c. But I can access with a workspace with org e6cfe015-326a-40d7-95a2-319f1994e051 (which has it's context with the same projectId like previous one)

mysql> select * from d_b_workspace where id='mustardmh-templatesvelt-5vcqsl66if7' \G;
*************************** 1. row ***************************
                   id: mustardmh-templatesvelt-5vcqsl66if7
         creationTime: 2023-11-20T13:58:03.696Z
              ownerId: f22cb39c-b108-4651-9212-c3bca4d391b6
           contextURL: var=value,var2=value2/https://github.com/mustard-mh/template-sveltejs
          description: mustard-mh/template-sveltejs - master
              context: *****
               config: *****
          imageSource: {"baseImageResolved":"docker.io/gitpod/workspace-full:latest"}
    imageNameResolved: eu.gcr.io/gitpod-core-dev/build/workspace-images:d1ce6d3571f4a5aca988999226fcac22f3b72326ab2becf9b0e80f561ed8395a
             archived: 0
            shareable: 0
        _lastModified: 2023-11-20 13:58:16.835081
              deleted: 0
                 type: regular
baseImageNameResolved: docker.io/gitpod/workspace-full@sha256:850314e6963b47c4e5d3ca18abe6345b435fa3423a735e7d94f93badf4502700
          softDeleted: NULL
               pinned: 0
      softDeletedTime: 
   contentDeletedTime: 
    basedOnPrebuildId: 
    basedOnSnapshotId: 
            projectId: 0c893085-6a88-4718-b5e9-4fddc52b5ae3
             cloneURL: https://github.com/mustard-mh/template-sveltejs.git
       organizationId: e6cfe015-326a-40d7-95a2-319f1994e051
1 row in set (0.28 sec)

ERROR: 
No query specified

mysql> select * from d_b_project_env_var \G;
*************************** 1. row ***************************
           id: 4c70516b-a522-4afe-91c9-7524c53bb5e6
    projectId: 0c893085-6a88-4718-b5e9-4fddc52b5ae3
         name: ORG_VAR_1
        value: *****
     censored: 1
 creationTime: 2023-11-20T13:26:27.858Z
      deleted: 0
_lastModified: 2023-11-20 13:26:27.860595
*************************** 2. row ***************************
           id: 9a6c52fa-d4d6-4259-9048-047894861b04
    projectId: 0c893085-6a88-4718-b5e9-4fddc52b5ae3
         name: ORG_VAR_2_VISIABLE
        value: *****
     censored: 0
 creationTime: 2023-11-20T13:27:08.348Z
      deleted: 0
_lastModified: 2023-11-20 13:27:08.352197
2 rows in set (0.48 sec)

ERROR: 
No query specified

mysql> select * from d_b_project \G;
*************************** 1. row ***************************
               id: 0c893085-6a88-4718-b5e9-4fddc52b5ae3
             name: template-sveltejs
         cloneUrl: https://github.com/mustard-mh/template-sveltejs.git
           teamId: d319b06f-3a73-4595-a341-ab63ff0fd65c
appInstallationId: 
     creationTime: 2023-11-20T13:26:04.970Z
    _lastModified: 2023-11-20 13:26:04.973654
    markedDeleted: 0
           userId: NULL
             slug: NULL
         settings: *****
1 row in set (0.42 sec)

ERROR: 
No query specified

mysql> 

@mustard-mh
Copy link
Contributor

mustard-mh commented Nov 20, 2023

But ☝️ not relates to this PR's changes, tested all good.

@mustard-mh
Copy link
Contributor

Let's wait preview env to validate updateUserEnv fixing. Once it's ok, we are good to go

@jeanp413
Copy link
Member Author

But ☝️ not relates to this PR's changes

😆

@@ -1830,11 +1830,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
const user = await this.checkAndBlockUser("setEnvVar");
const userEnvVars = await this.envVarService.listUserEnvVars(user.id, user.id);
if (userEnvVars.find((v) => v.name == variable.name && v.repositoryPattern == variable.repositoryPattern)) {
return this.envVarService.updateUserEnvVar(user.id, user.id, variable, (envvar: UserEnvVar) => {
await this.envVarService.updateUserEnvVar(user.id, user.id, variable, (envvar: UserEnvVar) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we update userEnv with value and scope changed, server will call addUserEnvVar even we have envId passed.

Not blocker as it's just like before 😌

Copy link
Member Author

@jeanp413 jeanp413 Nov 20, 2023

Choose a reason for hiding this comment

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

yes, intended

Copy link
Contributor

@mustard-mh mustard-mh left a comment

Choose a reason for hiding this comment

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

Tested all good.

Bugs [1][2] that not relates to this PR will create follow-up issues ✅

@roboquat roboquat merged commit 4ac04ee into main Nov 20, 2023
@roboquat roboquat deleted the jp/practical-guppy branch November 20, 2023 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants