Skip to content

Commit

Permalink
Clarify poller callback and update IamPolicyStatus enum vals
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa committed Aug 1, 2023
1 parent 1ca2a00 commit 099006f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export function useCreateDatabase() {
setAttempt({ status: 'success' });
}, [dbPollingResult]);

// fetchDatabaseServer is the callback that is run every interval by the poller.
// The poller will stop polling once a result returns (a dbServer).
function fetchDatabaseServer(signal: AbortSignal) {
const request = {
search: createdDb.name,
Expand All @@ -137,18 +139,24 @@ export function useCreateDatabase() {
.fetchDatabases(clusterId, request, signal)
.then(res => {
if (res.agents.length) {
// If the db response we got is type AWS,
// keep polling until an AWS specific flag
// "iamPolicyStatus" returns a non zero enum value.
const dbServer = res.agents[0];
if (!isAws || !dbServer.aws || !dbServer.aws.iamPolicyStatus) {
if (
!isAws ||
!dbServer.aws?.iamPolicyStatus ||
dbServer.aws?.iamPolicyStatus === IamPolicyStatus.Unspecified
) {
return dbServer;
}

if (dbServer.aws.iamPolicyStatus !== IamPolicyStatus.Pending) {
return dbServer;
}
}
// Returning nothing here will continue the polling.
// Either no result came back back yet or
// a result did come back but we are waiting for a specific
// marker to appear in the result. Specifically for AWS dbs,
// we wait for a non-pending flag to appear.
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const mockResponse = {
region: 'us-west-1',
subnets: ['sn1', 'sn2'],
},
iam_policy_status: 'success',
iam_policy_status: 'IAM_POLICY_STATUS_SUCCESS',
},
},
// non-aws self-hosted
Expand Down
8 changes: 4 additions & 4 deletions web/packages/teleport/src/services/databases/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { AwsRdsDatabase, RdsEngine } from '../integrations';
export enum IamPolicyStatus {
// Unspecified flag is most likely a result
// from an older service that do not set this state
Unspecified = '',
Pending = 'pending',
Failed = 'failed',
Success = 'success',
Unspecified = 'IAM_POLICY_STATUS_UNSPECIFIED',
Pending = 'IAM_POLICY_STATUS_PENDING',
Failed = 'IAM_POLICY_STATUS_FAILED',
Success = 'IAM_POLICY_STATUS_SUCCESS',
}

export type Aws = {
Expand Down

0 comments on commit 099006f

Please sign in to comment.