Skip to content

Commit 71ad153

Browse files
authored
CLOUDP-272605 Remove IDPs on cleanup script (#3320)
1 parent c510096 commit 71ad153

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

build/ci/evergreen.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,13 +1707,15 @@ buildvariants:
17071707
- name: ".e2e .backup .atlas"
17081708
- name: e2e_cleanup
17091709
display_name: "E2E Cleanup Resources"
1710+
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
1711+
tags:
1712+
- cleanup
17101713
run_on:
17111714
- rhel80-small
17121715
expansions:
17131716
<<: *go_linux_version
17141717
tasks:
17151718
- name: ".e2e .cleanup"
1716-
cron: "0 2 * * *" # 2am daily
17171719
- name: e2e_atlas_deployments
17181720
display_name: "E2E Atlas Deployments Tests"
17191721
run_on:
@@ -1867,6 +1869,9 @@ patch_aliases:
18671869
- alias: "packer"
18681870
variant_tags: ["packer"]
18691871
task: ".*"
1872+
- alias: "cleanup"
1873+
variant_tags: ["cleanup"]
1874+
task: ".*"
18701875
github_pr_aliases:
18711876
- variant: "code_health"
18721877
task_tags: ["code_health"]

test/e2e/atlas/cleanup_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ func TestCleanup(t *testing.T) {
4040
t.Parallel()
4141
deleteOrgTeams(t, cliPath)
4242
})
43+
t.Run("trying to delete all org idps", func(t *testing.T) {
44+
if IsGov() {
45+
t.Skip("idps are not available on gov")
46+
}
47+
t.Parallel()
48+
deleteAllIDPs(t, cliPath)
49+
})
4350
args := []string{projectEntity,
4451
"list",
4552
"--limit=500",

test/e2e/atlas/helper_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,3 +1265,52 @@ func installExamplePlugin(t *testing.T, cliPath string, version string) {
12651265
resp, err := e2e.RunAndGetStdOut(cmd)
12661266
require.NoError(t, err, string(resp))
12671267
}
1268+
1269+
func getFedSettingsID(t *testing.T, cliPath string) string {
1270+
t.Helper()
1271+
args := []string{federatedAuthenticationEntity,
1272+
federationSettingsEntity,
1273+
"describe",
1274+
"-o=json",
1275+
}
1276+
if orgID, set := os.LookupEnv("MCLI_ORG_ID"); set {
1277+
args = append(args, "--orgId", orgID)
1278+
}
1279+
cmd := exec.Command(cliPath, args...)
1280+
cmd.Env = os.Environ()
1281+
resp, err := e2e.RunAndGetStdOut(cmd)
1282+
require.NoError(t, err, string(resp))
1283+
var settings *atlasv2.OrgFederationSettings
1284+
require.NoError(t, json.Unmarshal(resp, &settings))
1285+
require.NotNil(t, settings.Id)
1286+
1287+
return *settings.Id
1288+
}
1289+
1290+
func listIDPs(t *testing.T, cliPath string, fedSettingsID string) *atlasv2.PaginatedFederationIdentityProvider {
1291+
t.Helper()
1292+
cmd := exec.Command(cliPath, "federatedAuthentication", "federationSettings", "identityProvider", "list", "--federationSettingsId", fedSettingsID, "-o", "json")
1293+
cmd.Env = os.Environ()
1294+
resp, err := e2e.RunAndGetStdOut(cmd)
1295+
require.NoError(t, err, string(resp))
1296+
var idps *atlasv2.PaginatedFederationIdentityProvider
1297+
require.NoError(t, json.Unmarshal(resp, &idps))
1298+
return idps
1299+
}
1300+
1301+
func deleteIDP(t *testing.T, cliPath string, id string, fedSettingsID string) {
1302+
t.Helper()
1303+
cmd := exec.Command(cliPath, federatedAuthenticationEntity, federationSettingsEntity, "identityProvider", "delete", id, "--federationSettingsId", fedSettingsID, "--force")
1304+
cmd.Env = os.Environ()
1305+
resp, err := e2e.RunAndGetStdOut(cmd)
1306+
require.NoError(t, err, string(resp))
1307+
}
1308+
1309+
func deleteAllIDPs(t *testing.T, cliPath string) {
1310+
t.Helper()
1311+
fedSettingsID := getFedSettingsID(t, cliPath)
1312+
idps := listIDPs(t, cliPath, fedSettingsID)
1313+
for _, idp := range *idps.Results {
1314+
deleteIDP(t, cliPath, idp.Id, fedSettingsID)
1315+
}
1316+
}

0 commit comments

Comments
 (0)