Skip to content

Commit

Permalink
CLOUDP-272605 Remove IDPs on cleanup script (#3320)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmenezes authored Oct 11, 2024
1 parent c510096 commit 71ad153
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build/ci/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1707,13 +1707,15 @@ buildvariants:
- name: ".e2e .backup .atlas"
- name: e2e_cleanup
display_name: "E2E Cleanup Resources"
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
tags:
- cleanup
run_on:
- rhel80-small
expansions:
<<: *go_linux_version
tasks:
- name: ".e2e .cleanup"
cron: "0 2 * * *" # 2am daily
- name: e2e_atlas_deployments
display_name: "E2E Atlas Deployments Tests"
run_on:
Expand Down Expand Up @@ -1867,6 +1869,9 @@ patch_aliases:
- alias: "packer"
variant_tags: ["packer"]
task: ".*"
- alias: "cleanup"
variant_tags: ["cleanup"]
task: ".*"
github_pr_aliases:
- variant: "code_health"
task_tags: ["code_health"]
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/atlas/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func TestCleanup(t *testing.T) {
t.Parallel()
deleteOrgTeams(t, cliPath)
})
t.Run("trying to delete all org idps", func(t *testing.T) {
if IsGov() {
t.Skip("idps are not available on gov")
}
t.Parallel()
deleteAllIDPs(t, cliPath)
})
args := []string{projectEntity,
"list",
"--limit=500",
Expand Down
49 changes: 49 additions & 0 deletions test/e2e/atlas/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,3 +1265,52 @@ func installExamplePlugin(t *testing.T, cliPath string, version string) {
resp, err := e2e.RunAndGetStdOut(cmd)
require.NoError(t, err, string(resp))
}

func getFedSettingsID(t *testing.T, cliPath string) string {
t.Helper()
args := []string{federatedAuthenticationEntity,
federationSettingsEntity,
"describe",
"-o=json",
}
if orgID, set := os.LookupEnv("MCLI_ORG_ID"); set {
args = append(args, "--orgId", orgID)
}
cmd := exec.Command(cliPath, args...)
cmd.Env = os.Environ()
resp, err := e2e.RunAndGetStdOut(cmd)
require.NoError(t, err, string(resp))
var settings *atlasv2.OrgFederationSettings
require.NoError(t, json.Unmarshal(resp, &settings))
require.NotNil(t, settings.Id)

return *settings.Id
}

func listIDPs(t *testing.T, cliPath string, fedSettingsID string) *atlasv2.PaginatedFederationIdentityProvider {
t.Helper()
cmd := exec.Command(cliPath, "federatedAuthentication", "federationSettings", "identityProvider", "list", "--federationSettingsId", fedSettingsID, "-o", "json")
cmd.Env = os.Environ()
resp, err := e2e.RunAndGetStdOut(cmd)
require.NoError(t, err, string(resp))
var idps *atlasv2.PaginatedFederationIdentityProvider
require.NoError(t, json.Unmarshal(resp, &idps))
return idps
}

func deleteIDP(t *testing.T, cliPath string, id string, fedSettingsID string) {
t.Helper()
cmd := exec.Command(cliPath, federatedAuthenticationEntity, federationSettingsEntity, "identityProvider", "delete", id, "--federationSettingsId", fedSettingsID, "--force")
cmd.Env = os.Environ()
resp, err := e2e.RunAndGetStdOut(cmd)
require.NoError(t, err, string(resp))
}

func deleteAllIDPs(t *testing.T, cliPath string) {
t.Helper()
fedSettingsID := getFedSettingsID(t, cliPath)
idps := listIDPs(t, cliPath, fedSettingsID)
for _, idp := range *idps.Results {
deleteIDP(t, cliPath, idp.Id, fedSettingsID)
}
}

0 comments on commit 71ad153

Please sign in to comment.