Skip to content

Commit

Permalink
Change UnsetProxy() logic to use os.Unsetenv()
Browse files Browse the repository at this point in the history
  • Loading branch information
asteel-gsa committed May 14, 2024
1 parent 24facce commit e400a20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/s3_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var s3SyncCmd = &cobra.Command{
Long: `Uses aws s3 sync to sync two buckets contents.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("s3_sync called")
util.Unset_Proxy()
util.UnsetProxy()
source_s3 := parseS3Path(source_s3)
dest_s3 := parseS3Path(dest_s3)
source_creds := getBucketCredentials(source_s3)
Expand Down
17 changes: 4 additions & 13 deletions internal/util/unset_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@ package util

import (
"os"
"os/exec"
"slices"
"strings"

"gov.gsa.fac.cgov-util/internal/logging"
)

func Unset_Proxy() {
if slices.Contains([]string{"LOCAL", "DEV", "PREVIEW", "STAGING", "PRODUCTION"}, os.Getenv("ENV")) {
unset := []string{
"unset",
"https_proxy",
}
command := strings.Join(unset[:], " ")
func UnsetProxy() {
if slices.Contains([]string{"DEV", "PREVIEW", "STAGING", "PRODUCTION"}, os.Getenv("ENV")) {
logging.Logger.Println("Proxy:", os.Getenv("https_proxy"))
logging.Logger.Printf("Unsetting https_proxy variable...")
logging.Logger.Printf("Running command: " + command)
unset_proxy := exec.Command("bash", "-c", command)
unsetOutput, unsetError := unset_proxy.Output()
ErrorCheck(string(unsetOutput), unsetError)
os.Unsetenv("https_proxy")
logging.Logger.Println("DEBUG - Proxy after Unsetenv():", os.Getenv("https_proxy"))
}
}

0 comments on commit e400a20

Please sign in to comment.