-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
18 changed files
with
229 additions
and
1,450 deletions.
There are no files selected for viewing
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,54 @@ | ||
/** | ||
* 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 { PromiseClient } from "@connectrpc/connect"; | ||
import { PartialMessage } from "@bufbuild/protobuf"; | ||
import { SSHService } from "@gitpod/public-api/lib/gitpod/v1/ssh_connect"; | ||
import { | ||
CreateSSHPublicKeyRequest, | ||
CreateSSHPublicKeyResponse, | ||
DeleteSSHPublicKeyRequest, | ||
DeleteSSHPublicKeyResponse, | ||
ListSSHPublicKeysRequest, | ||
ListSSHPublicKeysResponse, | ||
} from "@gitpod/public-api/lib/gitpod/v1/ssh_pb"; | ||
import { converter } from "./public-api"; | ||
import { getGitpodService } from "./service"; | ||
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; | ||
|
||
export class JsonRpcSSHClient implements PromiseClient<typeof SSHService> { | ||
async listSSHPublicKeys(req: PartialMessage<ListSSHPublicKeysRequest>): Promise<ListSSHPublicKeysResponse> { | ||
const result = new ListSSHPublicKeysResponse(); | ||
const sshKeys = await getGitpodService().server.getSSHPublicKeys(); | ||
result.sshKeys = sshKeys.map((i) => converter.toSSHPublicKey(i)); | ||
|
||
return result; | ||
} | ||
|
||
async createSSHPublicKey(req: PartialMessage<CreateSSHPublicKeyRequest>): Promise<CreateSSHPublicKeyResponse> { | ||
if (!req.name || !req.key) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "name and key are required"); | ||
} | ||
|
||
const response = new CreateSSHPublicKeyResponse(); | ||
|
||
const sshKey = await getGitpodService().server.addSSHPublicKey({ name: req.name, key: req.key }); | ||
response.sshKey = converter.toSSHPublicKey(sshKey); | ||
|
||
return response; | ||
} | ||
|
||
async deleteSSHPublicKey(req: PartialMessage<DeleteSSHPublicKeyRequest>): Promise<DeleteSSHPublicKeyResponse> { | ||
if (!req.sshKeyId) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "sshKeyId is required"); | ||
} | ||
|
||
await getGitpodService().server.deleteSSHPublicKey(eq.sshKeyId); | ||
|
||
const response = new DeleteSSHPublicKeyResponse(); | ||
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 |
---|---|---|
|
@@ -22,7 +22,14 @@ import { | |
PrebuildSettings, | ||
WorkspaceSettings, | ||
} from "@gitpod/public-api/lib/gitpod/v1/configuration_pb"; | ||
import { AuthProviderEntry, AuthProviderInfo, ProjectEnvVar, UserEnvVarValue, WithEnvvarsContext } from "./protocol"; | ||
import { | ||
AuthProviderEntry, | ||
AuthProviderInfo, | ||
ProjectEnvVar, | ||
UserEnvVarValue, | ||
UserSSHPublicKey, | ||
WithEnvvarsContext, | ||
} from "./protocol"; | ||
import { | ||
AuthProvider, | ||
AuthProviderDescription, | ||
|
@@ -33,6 +40,7 @@ import { | |
EnvironmentVariableAdmission, | ||
UserEnvironmentVariable, | ||
} from "@gitpod/public-api/lib/gitpod/v1/envvar_pb"; | ||
import { SSHPublicKey } from "@gitpod/public-api/lib/gitpod/v1/ssh_pb"; | ||
|
||
describe("PublicAPIConverter", () => { | ||
const converter = new PublicAPIConverter(); | ||
|
@@ -951,4 +959,28 @@ describe("PublicAPIConverter", () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe("toSSHPublicKey", () => { | ||
const envVar: UserSSHPublicKey = { | ||
id: "1", | ||
userId: "1", | ||
name: "FOO", | ||
key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCnrN9UdK1bNGPmZfenTWXLuYYDjlYvZE8S+WOfP08WpR1GETzX5ZvgYOEZGwEE8KUPHC9cge4Hvo/ydIS9aqbZ5MiVGJ8cAIq1Ic89SjlDWU6fl8TwIqOPCi2imAASlEDP4q8vMLK1N6UOW1EVbxyL3uybGd10ysC1t1FxFPveIGNsYE/MOQeuEWS16AplpXYXIfVRSlgAskeBft2w8Ud3B4gNe8ECLA/FXu96UpvZkdtOarA3JZ9Z27GveNJg9Mtmmw0+US0KXiO9x9NyH7G8+mqVDwDY+nNvaFA5gtQxkkl/uY2oz9k/B4Rjlj3jOiUXe5uQs3XUm5m8g9a9fh62DabLpA2fEvtfg+a/VqNe52dNa5YjupwvBd6Inb5uMW/TYjNl6bNHPlXFKw/nwLOVzukpkjxMZUKS6+4BGkpoasj6y2rTU/wkpbdD8J7yjI1p6J9aKkC6KksIWgN7xGmHkv2PCGDqMHTNbnQyowtNKMgA/667vAYJ0qW7HAHBFXJRs6uRi/DI3+c1QV2s4wPCpEHDIYApovQ0fbON4WDPoGMyHd7kPh9xB/bX7Dj0uMXImu1pdTd62fQ/1XXX64+vjAAXS/P9RSCD0RCRt/K3LPKl2m7GPI3y1niaE52XhxZw+ms9ays6NasNVMw/ZC+f02Ti+L5FBEVf8230RVVRQ== [email protected]", | ||
fingerprint: "ykjP/b5aqoa3envmXzWpPMCGgEFMu3QvubfSTNrJCMA=", | ||
creationTime: "2023-10-16T20:18:24.923Z", | ||
lastUsedTime: "2023-10-16T20:18:24.923Z", | ||
}; | ||
const userEnvVar = new SSHPublicKey({ | ||
id: "1", | ||
name: "FOO", | ||
key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCnrN9UdK1bNGPmZfenTWXLuYYDjlYvZE8S+WOfP08WpR1GETzX5ZvgYOEZGwEE8KUPHC9cge4Hvo/ydIS9aqbZ5MiVGJ8cAIq1Ic89SjlDWU6fl8TwIqOPCi2imAASlEDP4q8vMLK1N6UOW1EVbxyL3uybGd10ysC1t1FxFPveIGNsYE/MOQeuEWS16AplpXYXIfVRSlgAskeBft2w8Ud3B4gNe8ECLA/FXu96UpvZkdtOarA3JZ9Z27GveNJg9Mtmmw0+US0KXiO9x9NyH7G8+mqVDwDY+nNvaFA5gtQxkkl/uY2oz9k/B4Rjlj3jOiUXe5uQs3XUm5m8g9a9fh62DabLpA2fEvtfg+a/VqNe52dNa5YjupwvBd6Inb5uMW/TYjNl6bNHPlXFKw/nwLOVzukpkjxMZUKS6+4BGkpoasj6y2rTU/wkpbdD8J7yjI1p6J9aKkC6KksIWgN7xGmHkv2PCGDqMHTNbnQyowtNKMgA/667vAYJ0qW7HAHBFXJRs6uRi/DI3+c1QV2s4wPCpEHDIYApovQ0fbON4WDPoGMyHd7kPh9xB/bX7Dj0uMXImu1pdTd62fQ/1XXX64+vjAAXS/P9RSCD0RCRt/K3LPKl2m7GPI3y1niaE52XhxZw+ms9ays6NasNVMw/ZC+f02Ti+L5FBEVf8230RVVRQ== [email protected]", | ||
fingerprint: "ykjP/b5aqoa3envmXzWpPMCGgEFMu3QvubfSTNrJCMA=", | ||
creationTime: Timestamp.fromDate(new Date("2023-10-16T20:18:24.923Z")), | ||
lastUsedTime: Timestamp.fromDate(new Date("2023-10-16T20:18:24.923Z")), | ||
}); | ||
it("should convert ssh public key variable types", () => { | ||
const result = converter.toSSHPublicKey(envVar); | ||
expect(result).to.deep.equal(userEnvVar); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.