Skip to content

Commit

Permalink
chore: show authorized git services based on existed OAuth token secrets
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha committed Nov 14, 2023
1 parent 5174f24 commit cd16763
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions packages/dashboard-frontend/src/store/GitOauthConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getOAuthProviders,
getOAuthToken,
} from '@/services/backend-client/oAuthApi';
import { fetchTokens } from '@/services/backend-client/personalAccessTokenApi';
import { IGitOauth } from '@/store/GitOauthConfig/types';
import { createObject } from '@/store/helpers';
import { selectDefaultNamespace } from '@/store/InfrastructureNamespaces/selectors';
Expand Down Expand Up @@ -141,12 +142,38 @@ export const actionCreators: ActionCreators = {
const providersWithToken: api.GitOauthProvider[] = [];
try {
const supportedGitOauth = await getOAuthProviders();

const defaultKubernetesNamespace = selectDefaultNamespace(getState());
const tokens = await fetchTokens(defaultKubernetesNamespace.name);

const promises: Promise<void>[] = [];
for (const { name } of supportedGitOauth) {
for (const gitOauth of supportedGitOauth) {
promises.push(
getOAuthToken(name).then(() => {
providersWithToken.push(name);
}),
getOAuthToken(gitOauth.name)
.then(() => {
providersWithToken.push(gitOauth.name);
})

.catch(() => {
const normalizedGitOauthEndpoint = gitOauth.endpointUrl.endsWith('/')
? gitOauth.endpointUrl.slice(0, -1)
: gitOauth.endpointUrl;

for (const token of tokens) {
const normalizedTokenGitProviderEndpoint = token.gitProviderEndpoint.endsWith('/')
? token.gitProviderEndpoint.slice(0, -1)
: token.gitProviderEndpoint;

// compare Git OAuth Endpoint url ONLY with OAuth tokens
if (
token.gitProvider.startsWith('oauth2') &&
normalizedGitOauthEndpoint === normalizedTokenGitProviderEndpoint
) {
providersWithToken.push(gitOauth.name);
break;
}
}
}),
);
}
promises.push(dispatch(actionCreators.requestSkipAuthorizationProviders()));
Expand Down

0 comments on commit cd16763

Please sign in to comment.