-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,676 additions
and
11 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
components/dashboard/src/service/json-rpc-envvar-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { Code, ConnectError, PromiseClient } from "@connectrpc/connect"; | ||
import { PartialMessage } from "@bufbuild/protobuf"; | ||
import { EnvironmentVariableService } from "@gitpod/public-api/lib/gitpod/v1/envvar_connect"; | ||
import { | ||
ListEnvironmentVariablesRequest, | ||
ListEnvironmentVariablesResponse, | ||
UpdateEnvironmentVariableRequest, | ||
UpdateEnvironmentVariableResponse, | ||
DeleteEnvironmentVariableRequest, | ||
DeleteEnvironmentVariableResponse, | ||
} from "@gitpod/public-api/lib/gitpod/v1/envvar_pb"; | ||
import { converter } from "./public-api"; | ||
import { getGitpodService } from "./service"; | ||
import { UserEnvVar, UserEnvVarValue } from "@gitpod/gitpod-protocol"; | ||
|
||
export class JsonRpcEnvvarClient implements PromiseClient<typeof EnvironmentVariableService> { | ||
async listEnvironmentVariables( | ||
req: PartialMessage<ListEnvironmentVariablesRequest>, | ||
): Promise<ListEnvironmentVariablesResponse> { | ||
const userEnvVars = await getGitpodService().server.getAllEnvVars(); | ||
const result = new ListEnvironmentVariablesResponse(); | ||
result.environmentVariables = userEnvVars.map((i) => converter.toUserEnvironmentVariable(i)); | ||
return result; | ||
} | ||
|
||
async updateEnvironmentVariable( | ||
req: PartialMessage<UpdateEnvironmentVariableRequest>, | ||
): Promise<UpdateEnvironmentVariableResponse> { | ||
await getGitpodService().server.setEnvVar({ | ||
name: req.envvarName || "", | ||
value: req.envvarValue || "", | ||
repositoryPattern: req.envvarRepositoryPattern || "", | ||
}); | ||
|
||
req.envvarRepositoryPattern = UserEnvVar.normalizeRepoPattern(req.envvarRepositoryPattern || ""); | ||
const updatedUserEnvVars = await getGitpodService().server.getAllEnvVars(); | ||
const updatedUserEnvVar = updatedUserEnvVars.find( | ||
(v) => v.name === req.envvarName && v.repositoryPattern === req.envvarRepositoryPattern, | ||
); | ||
if (!updatedUserEnvVar) { | ||
throw new ConnectError("env variable not found", Code.Internal); | ||
} | ||
|
||
const response = new UpdateEnvironmentVariableResponse(); | ||
response.environmentVariable = converter.toUserEnvironmentVariable(updatedUserEnvVar); | ||
return response; | ||
} | ||
|
||
async deleteEnvironmentVariable( | ||
req: PartialMessage<DeleteEnvironmentVariableRequest>, | ||
): Promise<DeleteEnvironmentVariableResponse> { | ||
const variable: UserEnvVarValue = { | ||
name: req.envvarName || "", | ||
value: "", | ||
repositoryPattern: req.envvarRepositoryPattern || "", | ||
}; | ||
await getGitpodService().server.deleteEnvVar(variable); | ||
|
||
const response = new DeleteEnvironmentVariableResponse(); | ||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
syntax = "proto3"; | ||
|
||
package gitpod.v1; | ||
|
||
option go_package = "github.com/gitpod-io/gitpod/components/public-api/go/v1"; | ||
|
||
service EnvironmentVariableService { | ||
// ListEnvironmentVariables returns all environment variables for the | ||
// authenticated user. | ||
// | ||
// +return NOT_FOUND User does not have access to a workspace with the given | ||
// ID +return NOT_FOUND Workspace does not exist | ||
rpc ListEnvironmentVariables(ListEnvironmentVariablesRequest) | ||
returns (ListEnvironmentVariablesResponse) {} | ||
|
||
// UpdateEnvironmentVariable updates an environment variable for the | ||
// authenticated user. | ||
// | ||
// workspace_id +return NOT_FOUND Workspace does not exist | ||
rpc UpdateEnvironmentVariable(UpdateEnvironmentVariableRequest) | ||
returns (UpdateEnvironmentVariableResponse) {} | ||
|
||
// DeleteEnvironmentVariable deletes an environment variable for the | ||
// authenticated user. | ||
// | ||
// workspace_id +return NOT_FOUND Workspace does not exist | ||
rpc DeleteEnvironmentVariable(DeleteEnvironmentVariableRequest) | ||
returns (DeleteEnvironmentVariableResponse) {} | ||
} | ||
|
||
message UserEnvironmentVariable { | ||
string id = 1; | ||
string name = 2; | ||
string value = 3; | ||
string repository_pattern = 4; | ||
} | ||
|
||
message ListEnvironmentVariablesRequest { optional string workspace_id = 1; } | ||
|
||
message ListEnvironmentVariablesResponse { | ||
repeated UserEnvironmentVariable environment_variables = 1; | ||
} | ||
|
||
message UpdateEnvironmentVariableRequest { | ||
optional string envvar_name = 1; | ||
optional string envvar_value = 2; | ||
optional string envvar_repository_pattern = 3; | ||
} | ||
|
||
message UpdateEnvironmentVariableResponse { | ||
UserEnvironmentVariable environment_variable = 1; | ||
} | ||
|
||
message DeleteEnvironmentVariableRequest { | ||
string envvar_name = 1; | ||
string envvar_repository_pattern = 2; | ||
} | ||
|
||
message DeleteEnvironmentVariableResponse {} |
Oops, something went wrong.