Skip to content

Commit

Permalink
Use async/await.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger committed Jan 8, 2025
1 parent a81330e commit acdc2f8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 55 deletions.
17 changes: 11 additions & 6 deletions web/packages/teleport/src/Users/useUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ export default function useUsers({

async function onCreate(u: User) {
const mfaResponse = await auth.getAdminActionMfaResponse(true);
return ctx.userService
.createUser(u, ExcludeUserField.Traits, mfaResponse)
.then(result => setUsers([result, ...users]))
.then(() =>
ctx.userService.createResetPasswordToken(u.name, 'invite', mfaResponse)
);
const result = await ctx.userService.createUser(
u,
ExcludeUserField.Traits,
mfaResponse
);
setUsers([result, ...users]);
return ctx.userService.createResetPasswordToken(
u.name,
'invite',
mfaResponse
);
}

function onInviteCollaboratorsClose() {
Expand Down
33 changes: 15 additions & 18 deletions web/packages/teleport/src/services/integrations/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { App } from '../apps';
import makeApp from '../apps/makeApps';
import auth from '../auth/auth';
import makeNode from '../nodes/makeNode';

import {
AwsDatabaseVpcsResponse,
AwsOidcDeployDatabaseServicesRequest,
Expand Down Expand Up @@ -272,15 +271,14 @@ export const integrationService = {
integrationName,
req: AwsOidcDeployServiceRequest
): Promise<string> {
const response = await auth.getAdminActionMfaResponse(true);
return api
.post(
cfg.getAwsDeployTeleportServiceUrl(integrationName),
req,
null,
response
)
.then(resp => resp.serviceDashboardUrl);
const mfaResp = await auth.getAdminActionMfaResponse(true);
const resp = await api.post(
cfg.getAwsDeployTeleportServiceUrl(integrationName),
req,
null,
mfaResp
);
return resp.serviceDashboardUrl;
},

async createAwsAppAccess(integrationName): Promise<App> {
Expand All @@ -294,14 +292,13 @@ export const integrationService = {
req: AwsOidcDeployDatabaseServicesRequest
): Promise<string> {
const mfaResponse = await auth.getAdminActionMfaResponse(true);
return api
.post(
cfg.getAwsRdsDbsDeployServicesUrl(integrationName),
req,
null,
mfaResponse
)
.then(resp => resp.clusterDashboardUrl);
const resp = await api.post(
cfg.getAwsRdsDbsDeployServicesUrl(integrationName),
req,
null,
mfaResponse
);
return resp.clusterDashboardUrl;
},

async enrollEksClusters(
Expand Down
59 changes: 28 additions & 31 deletions web/packages/teleport/src/services/joinToken/joinToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,45 @@ class JoinTokenService {
signal: AbortSignal = null
): Promise<JoinToken> {
const mfaResponse = await auth.getAdminActionMfaResponse();
return api
.post(
cfg.getJoinTokenUrl(),
{
roles: req.roles,
join_method: req.method || 'token',
allow: makeAllowField(req.rules || []),
suggested_agent_matcher_labels: makeLabelMapOfStrArrs(
req.suggestedAgentMatcherLabels
),
},
signal,
mfaResponse
)
.then(makeJoinToken);
const resp = await api.post(
cfg.getJoinTokenUrl(),
{
roles: req.roles,
join_method: req.method || 'token',
allow: makeAllowField(req.rules || []),
suggested_agent_matcher_labels: makeLabelMapOfStrArrs(
req.suggestedAgentMatcherLabels
),
},
signal,
mfaResponse
);
return makeJoinToken(resp);
}

async upsertJoinTokenYAML(
req: JoinTokenRequest,
tokenName: string
): Promise<JoinToken> {
const mfaResponse = await auth.getAdminActionMfaResponse();
return api
.putWithHeaders(
cfg.getJoinTokenYamlUrl(),
{
content: req.content,
},
{
[TeleportTokenNameHeader]: tokenName,
'Content-Type': 'application/json',
},
mfaResponse
)
.then(makeJoinToken);
const resp = await api.putWithHeaders(
cfg.getJoinTokenYamlUrl(),
{
content: req.content,
},
{
[TeleportTokenNameHeader]: tokenName,
'Content-Type': 'application/json',
},
mfaResponse
);
return makeJoinToken(resp);
}

async createJoinToken(req: JoinTokenRequest): Promise<JoinToken> {
const mfaResponse = await auth.getAdminActionMfaResponse();
return api
.post(cfg.getJoinTokensUrl(), req, mfaResponse)
.then(makeJoinToken);
const resp = api.post(cfg.getJoinTokensUrl(), req, mfaResponse);
return makeJoinToken(resp);
}

async fetchJoinTokens(
Expand Down

0 comments on commit acdc2f8

Please sign in to comment.