-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[public-api] Add AuthProviderService service #19008
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
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7c2f6a0
add Unauthenticated decorator for public-api
AlexTugarev b41d9c6
[server] add AuthProviderServiceAPI
AlexTugarev ae50fbd
[dashboard] add client facade (JsonRpcAuthProviderClient)
AlexTugarev d493db5
use uuidValidate
AlexTugarev 2e482e1
update UpdateAuthProviderResponse to return provider
AlexTugarev 711bd6e
return updated provider in UpdateAuthProviderResponse
AlexTugarev 9dbe696
handle pagination for ListAuthProvider(Description)s
AlexTugarev 9316a9a
add simple conversion tests for auth providers
AlexTugarev 3055c58
relax param validation on updateAuthProvider
AlexTugarev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
components/dashboard/src/service/json-rpc-authprovider-client.ts
This file contains hidden or 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,136 @@ | ||
/** | ||
* 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 { PartialMessage } from "@bufbuild/protobuf"; | ||
import { Code, ConnectError, PromiseClient } from "@connectrpc/connect"; | ||
import { AuthProviderService } from "@gitpod/public-api/lib/gitpod/v1/authprovider_connect"; | ||
import { | ||
CreateAuthProviderRequest, | ||
CreateAuthProviderResponse, | ||
DeleteAuthProviderRequest, | ||
DeleteAuthProviderResponse, | ||
GetAuthProviderRequest, | ||
GetAuthProviderResponse, | ||
ListAuthProviderDescriptionsRequest, | ||
ListAuthProviderDescriptionsResponse, | ||
ListAuthProvidersRequest, | ||
ListAuthProvidersResponse, | ||
UpdateAuthProviderRequest, | ||
UpdateAuthProviderResponse, | ||
} from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb"; | ||
import { converter } from "./public-api"; | ||
import { getGitpodService } from "./service"; | ||
|
||
export class JsonRpcAuthProviderClient implements PromiseClient<typeof AuthProviderService> { | ||
async createAuthProvider(request: PartialMessage<CreateAuthProviderRequest>): Promise<CreateAuthProviderResponse> { | ||
const ownerId = request.owner?.case === "ownerId" ? request.owner.value : undefined; | ||
const organizationId = request.owner?.case === "organizationId" ? request.owner.value : undefined; | ||
|
||
if (!organizationId && !ownerId) { | ||
throw new ConnectError("organizationId or ownerId is required", Code.InvalidArgument); | ||
} | ||
if (!request.type) { | ||
throw new ConnectError("type is required", Code.InvalidArgument); | ||
} | ||
if (!request.host) { | ||
throw new ConnectError("host is required", Code.InvalidArgument); | ||
} | ||
|
||
if (organizationId) { | ||
const result = await getGitpodService().server.createOrgAuthProvider({ | ||
entry: { | ||
organizationId, | ||
host: request.host, | ||
type: converter.fromAuthProviderType(request.type), | ||
clientId: request.oauth2Config?.clientId, | ||
clientSecret: request.oauth2Config?.clientSecret, | ||
}, | ||
}); | ||
return new CreateAuthProviderResponse({ authProvider: converter.toAuthProvider(result) }); | ||
} | ||
if (ownerId) { | ||
const result = await getGitpodService().server.updateOwnAuthProvider({ | ||
entry: { | ||
host: request.host, | ||
ownerId, | ||
type: converter.fromAuthProviderType(request.type), | ||
clientId: request.oauth2Config?.clientId, | ||
clientSecret: request.oauth2Config?.clientSecret, | ||
}, | ||
}); | ||
return new CreateAuthProviderResponse({ authProvider: converter.toAuthProvider(result) }); | ||
} | ||
|
||
throw new ConnectError("organizationId or ownerId is required", Code.InvalidArgument); | ||
} | ||
|
||
async getAuthProvider(request: PartialMessage<GetAuthProviderRequest>): Promise<GetAuthProviderResponse> { | ||
if (!request.authProviderId) { | ||
throw new ConnectError("authProviderId is required", Code.InvalidArgument); | ||
} | ||
|
||
const provider = await getGitpodService().server.getAuthProvider(request.authProviderId); | ||
return new GetAuthProviderResponse({ | ||
authProvider: converter.toAuthProvider(provider), | ||
}); | ||
} | ||
|
||
async listAuthProviders(request: PartialMessage<ListAuthProvidersRequest>): Promise<ListAuthProvidersResponse> { | ||
if (!request.id?.case) { | ||
throw new ConnectError("id is required", Code.InvalidArgument); | ||
} | ||
const organizationId = request.id.case === "organizationId" ? request.id.value : undefined; | ||
const userId = request.id.case === "userId" ? request.id.value : undefined; | ||
|
||
if (!organizationId && !userId) { | ||
throw new ConnectError("organizationId or userId is required", Code.InvalidArgument); | ||
} | ||
|
||
const authProviders = !!organizationId | ||
? await getGitpodService().server.getOrgAuthProviders({ | ||
organizationId, | ||
}) | ||
: await getGitpodService().server.getOwnAuthProviders(); | ||
const response = new ListAuthProvidersResponse({ | ||
authProviders: authProviders.map(converter.toAuthProvider), | ||
}); | ||
return response; | ||
} | ||
|
||
async listAuthProviderDescriptions( | ||
request: PartialMessage<ListAuthProviderDescriptionsRequest>, | ||
): Promise<ListAuthProviderDescriptionsResponse> { | ||
const aps = await getGitpodService().server.getAuthProviders(); | ||
return new ListAuthProviderDescriptionsResponse({ | ||
descriptions: aps.map((ap) => converter.toAuthProviderDescription(ap)), | ||
}); | ||
} | ||
|
||
async updateAuthProvider(request: PartialMessage<UpdateAuthProviderRequest>): Promise<UpdateAuthProviderResponse> { | ||
if (!request.authProviderId) { | ||
throw new ConnectError("authProviderId is required", Code.InvalidArgument); | ||
} | ||
const clientId = request?.clientId; | ||
const clientSecret = request?.clientSecret; | ||
if (!clientId || !clientSecret) { | ||
throw new ConnectError("clientId or clientSecret are required", Code.InvalidArgument); | ||
} | ||
|
||
await getGitpodService().server.updateAuthProvider(request.authProviderId, { | ||
clientId, | ||
clientSecret, | ||
}); | ||
return new UpdateAuthProviderResponse(); | ||
} | ||
|
||
async deleteAuthProvider(request: PartialMessage<DeleteAuthProviderRequest>): Promise<DeleteAuthProviderResponse> { | ||
if (!request.authProviderId) { | ||
throw new ConnectError("authProviderId is required", Code.InvalidArgument); | ||
} | ||
await getGitpodService().server.deleteAuthProvider(request.authProviderId); | ||
return new DeleteAuthProviderResponse(); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.