This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matteo Baiguini SBT
committed
Jan 3, 2020
1 parent
df0178e
commit da86401
Showing
4 changed files
with
126 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package envvar | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func Check(key string) bool { | ||
return os.Getenv(key) != "" | ||
} | ||
|
||
func Set(key string, value string) error { | ||
return os.Setenv(key, value) | ||
} | ||
|
||
func Unset(key string) error { | ||
return os.Unsetenv(key) | ||
} | ||
|
||
func GetString(key, defaultValue string) string { | ||
if !Check(key) { | ||
return defaultValue | ||
} | ||
return os.Getenv(key) | ||
} | ||
|
||
func GetBool(key string, defaultValue bool) bool { | ||
value, err := strconv.ParseBool(os.Getenv(key)) | ||
if err != nil { | ||
return defaultValue | ||
} | ||
return value | ||
} | ||
|
||
func GetInt(key string, defaultValue int) int { | ||
return int(GetInt64(key, int64(defaultValue))) | ||
} | ||
|
||
func GetInt64(key string, defaultValue int64) int64 { | ||
value, err := strconv.ParseInt(os.Getenv(key), 10, 64) | ||
if err != nil { | ||
return defaultValue | ||
} | ||
return value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package utils | ||
|
||
import ( | ||
"bygui86/kubeconfigurator/envvar" | ||
"os" | ||
) | ||
|
||
const ( | ||
kubeConfigEnvVar = "KUBECONFIG" | ||
|
||
kubeConfigOutputFolderPerm = 0755 | ||
) | ||
|
||
func GetKubeConfigEnvVar() string { | ||
return envvar.GetString(kubeConfigEnvVar, "") | ||
} | ||
|
||
func SetKubeConfigEnvVar(kubeConfigsPath string) error { | ||
return envvar.Set(kubeConfigEnvVar, kubeConfigsPath) | ||
} | ||
|
||
func CheckKubeConfigsFolder(path string) error { | ||
_, statErr := os.Stat(path) | ||
if statErr != nil { | ||
if os.IsNotExist(statErr) { | ||
return os.Mkdir(path, kubeConfigOutputFolderPerm) | ||
} | ||
return statErr | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package utils | ||
|
||
import ( | ||
"os/user" | ||
|
||
"bygui86/kubeconfigurator/envvar" | ||
) | ||
|
||
const ( | ||
homeEnvVar = "HOME" | ||
) | ||
|
||
func GetHomeDir() (string,error) { | ||
home, err := GetCurrentUserHomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
return envvar.GetString(homeEnvVar, home), nil | ||
} | ||
|
||
func GetCurrentUserHomeDir() (string,error) { | ||
usr, err := user.Current() | ||
if err != nil{ | ||
return "", err | ||
} | ||
return usr.HomeDir, nil | ||
} |