Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read admin url from environment variable to be able to target de… #401

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/admin_cluster_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func init() {
}

func deployClusters() {
utils.CheckAdminUrl()
utils.GetAdminUrl()

// if no filter is set, enforce to select only RUNNING clusters to avoid mistakes (e.g deploying a stopped cluster)
_, containsKey := filters["CurrentStatus"]
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin_cluster_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
}

func listClusters() {
utils.CheckAdminUrl()
utils.GetAdminUrl()

listService, err := pkg.NewAdminClusterListServiceImpl(filters)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin_demo_get_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
os.Exit(1)
}

url := fmt.Sprintf("%s/demoDebugLog", utils.AdminUrl)
url := fmt.Sprintf("%s/demoDebugLog", utils.GetAdminUrl())
req, _ := http.NewRequest(http.MethodGet, url, bytes.NewReader([]byte{}))
query := req.URL.Query()
query.Add("filename", args[0])
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin_demo_list_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
os.Exit(1)
}

url := fmt.Sprintf("%s/demoDebugLog", utils.AdminUrl)
url := fmt.Sprintf("%s/demoDebugLog", utils.GetAdminUrl())
req, _ := http.NewRequest(http.MethodGet, url, bytes.NewReader([]byte{}))
query := req.URL.Query()
orgaId, _ := cmd.Flags().GetString("organizationId")
Expand Down
4 changes: 1 addition & 3 deletions cmd/admin_jw_qovery_usage_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ func init() {
}

func createJwtForQoveryUsage() {
utils.CheckAdminUrl()

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
Expand Down Expand Up @@ -66,7 +64,7 @@ func createJwtForQoveryUsage() {
Description: description,
})

url := fmt.Sprintf("%s/jwts", utils.AdminUrl)
url := fmt.Sprintf("%s/jwts", utils.GetAdminUrl())
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(payload))
if err != nil {
log.Fatal(err)
Expand Down
4 changes: 1 addition & 3 deletions cmd/admin_jw_qovery_usage_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ func init() {
}

func deleteJwtForQoveryUsage() {
utils.CheckAdminUrl()

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(0)
}

url := fmt.Sprintf("%s/jwts/%s", utils.AdminUrl, jwtKid)
url := fmt.Sprintf("%s/jwts/%s", utils.GetAdminUrl(), jwtKid)
req, err := http.NewRequest(http.MethodDelete, url, nil)
if err != nil {
log.Fatal(err)
Expand Down
7 changes: 2 additions & 5 deletions cmd/admin_jw_qovery_usage_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ func init() {
}

func listJwtsForQoveryUsage() {
utils.CheckAdminUrl()

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(0)
}

url := fmt.Sprintf("%s/jwts", utils.AdminUrl)
url := fmt.Sprintf("%s/jwts", utils.GetAdminUrl())
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -72,13 +70,12 @@ func listJwtsForQoveryUsage() {
}

w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
format := "%s\t | %s\t | %s\t | %s\t | %s\n"
_, _ = fmt.Fprintf(w, format, "", "key_id", "descripton", "jwt payload", "created_at")
for idx, jwtForQoveryUsage := range resp.Results {
_, jwtPayload, err := DecodeJWT(jwtForQoveryUsage.Jwt)
if err != nil {
log.Fatal(err)
}
_, _ = fmt.Fprintln(w, "\t")
_, _ = fmt.Fprintln(w, "Field\t | Value")
_, _ = fmt.Fprintln(w, "------\t | ------")

Expand Down
4 changes: 1 addition & 3 deletions cmd/admin_jwt_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ func init() {
}

func createJwt() {
utils.CheckAdminUrl()

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(0)
}

url := fmt.Sprintf("%s/clusters/%s/jwts", utils.AdminUrl, clusterId)
url := fmt.Sprintf("%s/clusters/%s/jwts", utils.GetAdminUrl(), clusterId)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer([]byte("{ }")))
if err != nil {
log.Fatal(err)
Expand Down
4 changes: 1 addition & 3 deletions cmd/admin_jwt_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ func init() {
}

func deleteJwt() {
utils.CheckAdminUrl()

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(0)
}

url := fmt.Sprintf("%s/clusters/jwts/%s", utils.AdminUrl, jwtKid)
url := fmt.Sprintf("%s/clusters/jwts/%s", utils.GetAdminUrl(), jwtKid)
req, err := http.NewRequest(http.MethodDelete, url, nil)
if err != nil {
log.Fatal(err)
Expand Down
4 changes: 1 addition & 3 deletions cmd/admin_jwt_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ func init() {
}

func listJwts() {
utils.CheckAdminUrl()

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(0)
}

url := fmt.Sprintf("%s/clusters/%s/jwts", utils.AdminUrl, clusterId)
url := fmt.Sprintf("%s/clusters/%s/jwts", utils.GetAdminUrl(), clusterId)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin_k9s.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func getClusterCredentials(clusterId string) []utils.Var {
os.Exit(0)
}

url := fmt.Sprintf("%s/cluster/%s/credential", utils.AdminUrl, clusterId)
url := fmt.Sprintf("%s/cluster/%s/credential", utils.GetAdminUrl(), clusterId)
req, err := http.NewRequest(http.MethodGet, url, bytes.NewBuffer([]byte("{}")))
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin_notify_users_cluster_failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func init() {
}

func notifyUsersClusterFailure() {
utils.CheckAdminUrl()
utils.GetAdminUrl()

err := pkg.NotifyUsersClusterFailure(&clusterId)
if err != nil {
Expand Down
13 changes: 8 additions & 5 deletions pkg/admin_cluster_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (service AdminClusterListServiceImpl) fetchClustersEligibleToUpdate() ([]Cl
return nil, err
}

req, err := http.NewRequest(http.MethodGet, utils.AdminUrl+"/listClustersEligibleToUpdate", nil)
req, err := http.NewRequest(http.MethodGet, utils.GetAdminUrl()+"/listClustersEligibleToUpdate", nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -452,10 +452,11 @@ func (service AdminClusterBatchDeployServiceImpl) Deploy(clusters []ClusterDetai
}

func (service AdminClusterBatchDeployServiceImpl) deployCluster(clusterId string, dryRunDisabled bool) error {
response := execAdminRequest(utils.AdminUrl+"/cluster/deploy/"+clusterId, http.MethodPost, dryRunDisabled, map[string]string{})
adminUrl := utils.GetAdminUrl()
response := execAdminRequest(adminUrl+"/cluster/deploy/"+clusterId, http.MethodPost, dryRunDisabled, map[string]string{})
if response.StatusCode == 401 {
DoRequestUserToAuthenticate(false)
response = execAdminRequest(utils.AdminUrl+"/cluster/deploy/"+clusterId, http.MethodPost, dryRunDisabled, map[string]string{})
response = execAdminRequest(adminUrl+"/cluster/deploy/"+clusterId, http.MethodPost, dryRunDisabled, map[string]string{})
}
if response.StatusCode != 200 {
result, _ := io.ReadAll(response.Body)
Expand All @@ -471,8 +472,10 @@ func (service AdminClusterBatchDeployServiceImpl) upgradeCluster(clusterId strin
os.Exit(0)
}

adminUrl := utils.GetAdminUrl()

body := bytes.NewBuffer([]byte(fmt.Sprintf("{ \"metadata\": { \"dry_run_deploy\": \"%s\", \"target_version\": \"%s\" } }", strconv.FormatBool(!dryRunDisabled), targetVersion)))
request, err := http.NewRequest(http.MethodPost, utils.AdminUrl+"/cluster/update/"+clusterId, body)
request, err := http.NewRequest(http.MethodPost, adminUrl+"/cluster/update/"+clusterId, body)
if err != nil {
return err
}
Expand All @@ -487,7 +490,7 @@ func (service AdminClusterBatchDeployServiceImpl) upgradeCluster(clusterId strin

if response.StatusCode == 401 {
DoRequestUserToAuthenticate(false)
request, err = http.NewRequest(http.MethodPost, utils.AdminUrl+"/cluster/update/"+clusterId, body)
request, err = http.NewRequest(http.MethodPost, adminUrl+"/cluster/update/"+clusterId, body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/admin_environment_deployment_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func PublishEnvironmentDeploymentRules() error {
utils.CheckAdminUrl()
utils.GetAdminUrl()

utils.Println("Publishing environment deployment rules to scheduler...")
err := callPublishEnvironmentDeploymentRulesApi()
Expand All @@ -28,7 +28,7 @@ func callPublishEnvironmentDeploymentRulesApi() error {
os.Exit(0)
}

url := fmt.Sprintf("%s/environmentDeploymentRules/pushToScheduler", utils.AdminUrl)
url := fmt.Sprintf("%s/environmentDeploymentRules/pushToScheduler", utils.GetAdminUrl())
req, err := http.NewRequest(http.MethodPost, url, nil)
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/admin_notify_users_cluster_failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NotifyUsersClusterFailure(clusterId *string) error {
body = `{"all_failing_clusters": true}`
}

notifiedClustersResponse, err := postWithBody(utils.AdminUrl+"/cluster/notifyFailedClustersAdmins", body)
notifiedClustersResponse, err := postWithBody(utils.GetAdminUrl()+"/cluster/notifyFailedClustersAdmins", body)
if err != nil {
return err
}
Expand Down
9 changes: 3 additions & 6 deletions pkg/delete_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import (
)

func DeleteClusterById(clusterId string, dryRunDisabled bool) {
utils.CheckAdminUrl()

utils.DryRunPrint(dryRunDisabled)
if utils.Validate("delete") {
res := httpDelete(utils.AdminUrl+"/cluster/"+clusterId, http.MethodDelete, dryRunDisabled)
res := httpDelete(utils.GetAdminUrl()+"/cluster/"+clusterId, http.MethodDelete, dryRunDisabled)

if !dryRunDisabled {
fmt.Println("Cluster with id " + clusterId + " deletable.")
Expand All @@ -31,10 +30,9 @@ func DeleteClusterById(clusterId string, dryRunDisabled bool) {
}
}
func DeleteClusterUnDeployedInError() {
utils.CheckAdminUrl()

if utils.Validate("delete") {
res := httpDelete(utils.AdminUrl+"/cluster/deleteNotDeployedInErrorClusters", http.MethodPost, true)
res := httpDelete(utils.GetAdminUrl()+"/cluster/deleteNotDeployedInErrorClusters", http.MethodPost, true)

if !strings.Contains(res.Status, "200") {
result, _ := io.ReadAll(res.Body)
Expand All @@ -47,7 +45,6 @@ func DeleteClusterUnDeployedInError() {
}

func DeleteOldClustersWithInvalidCredentials(ageInDay int, dryRunDisabled bool) {
utils.CheckAdminUrl()

if utils.Validate("delete") {

Expand All @@ -62,7 +59,7 @@ func DeleteOldClustersWithInvalidCredentials(ageInDay int, dryRunDisabled bool)
return
}

res := deleteWithBody(utils.AdminUrl+"/cluster/deleteOldClustersWithInvalidCredentials", http.MethodPost, true, bytes.NewBuffer(requestBody))
res := deleteWithBody(utils.GetAdminUrl()+"/cluster/deleteOldClustersWithInvalidCredentials", http.MethodPost, true, bytes.NewBuffer(requestBody))

if !strings.Contains(res.Status, "200") {
result, _ := io.ReadAll(res.Body)
Expand Down
4 changes: 2 additions & 2 deletions pkg/delete_orga.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
)

func DeleteOrganizationByClusterId(clusterId string, dryRunDisabled bool) {
utils.CheckAdminUrl()
utils.GetAdminUrl()

utils.DryRunPrint(dryRunDisabled)
if utils.Validate("delete") {
res := httpDelete(utils.AdminUrl+"/organization?clusterId="+clusterId, http.MethodDelete, dryRunDisabled)
res := httpDelete(utils.GetAdminUrl()+"/organization?clusterId="+clusterId, http.MethodDelete, dryRunDisabled)

if !dryRunDisabled {
fmt.Println("Organization owning cluster" + clusterId + " deletable.")
Expand Down
4 changes: 1 addition & 3 deletions pkg/delete_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import (
)

func DeleteProjectById(projectId string, dryRunDisabled bool) {
utils.CheckAdminUrl()

utils.DryRunPrint(dryRunDisabled)
if utils.Validate("delete") {
res := httpDelete(utils.AdminUrl+"/project/"+projectId, http.MethodDelete, dryRunDisabled)
res := httpDelete(utils.GetAdminUrl()+"/project/"+projectId, http.MethodDelete, dryRunDisabled)

if !dryRunDisabled {
fmt.Println("Project with id " + projectId + " deletable.")
Expand Down
2 changes: 1 addition & 1 deletion pkg/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func ForceFailedDeploymentsToInternalErrorStatus(safeguardDuration time.Duration

durationIso8601 := fmt.Sprintf("PT%dM", nbMinutes)
queryParams := map[string]string{"safeguardDuration": durationIso8601}
res := execAdminRequest(utils.AdminUrl+"/deployment/forceFailedDeploymentsToInternalErrorStatus", http.MethodPost, true, queryParams)
res := execAdminRequest(utils.GetAdminUrl()+"/deployment/forceFailedDeploymentsToInternalErrorStatus", http.MethodPost, true, queryParams)
if !strings.Contains(res.Status, "200") {
result, _ := io.ReadAll(res.Body)
log.Errorf("Could not force the deployments status : %s. %s", res.Status, string(result))
Expand Down
4 changes: 1 addition & 3 deletions pkg/download_s3_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ type ArchiveResponse struct {
}

func DownloadS3Archive(executionId string, directory string) {
utils.CheckAdminUrl()

fileName := executionId + ".tgz"
res := download(utils.AdminUrl+"/getS3ArchiveObject", fileName)
res := download(utils.GetAdminUrl()+"/getS3ArchiveObject", fileName)

if !strings.Contains(res.Status, "200") {
result, _ := io.ReadAll(res.Body)
Expand Down
10 changes: 5 additions & 5 deletions pkg/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func LockedClusters() {
utils.CheckAdminUrl()
utils.GetAdminUrl()

res := listLockedClusters()

Expand Down Expand Up @@ -53,7 +53,7 @@ func LockedClusters() {
}

func LockById(clusterId string, reason string) {
utils.CheckAdminUrl()
utils.GetAdminUrl()

if reason == "" {
log.Errorf("Lock reason is required")
Expand All @@ -73,7 +73,7 @@ func LockById(clusterId string, reason string) {
}

func UnockById(clusterId string) {
utils.CheckAdminUrl()
utils.GetAdminUrl()

if utils.Validate("unlock") {
res := updateLockById(clusterId, "", http.MethodDelete)
Expand All @@ -94,7 +94,7 @@ func listLockedClusters() *http.Response {
os.Exit(0)
}

url := fmt.Sprintf("%s/cluster/lock", utils.AdminUrl)
url := fmt.Sprintf("%s/cluster/lock", utils.GetAdminUrl())
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -125,7 +125,7 @@ func updateLockById(clusterId string, reason string, method string) *http.Respon
log.Fatal(err)
}

url := fmt.Sprintf("%s/cluster/lock/%s", utils.AdminUrl, clusterId)
url := fmt.Sprintf("%s/cluster/lock/%s", utils.GetAdminUrl(), clusterId)
req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
if err != nil {
log.Fatal(err)
Expand Down
Loading
Loading