Skip to content

Commit

Permalink
some optimizations for cert.go (#9404)
Browse files Browse the repository at this point in the history
Signed-off-by: ls0f <lovedboy.tk@qq.com>
  • Loading branch information
ls0f committed May 17, 2022
1 parent 3896ae0 commit 4b4fd88
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions util/cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ func IsValidHostname(hostname string, fqdn bool) bool {
// filesystem. If ARGOCD_TLS_DATA_PATH environment is set, path is taken from
// there, otherwise the default will be returned.
func GetTLSCertificateDataPath() string {
envPath := os.Getenv(common.EnvVarTLSDataPath)
if envPath != "" {
if envPath := os.Getenv(common.EnvVarTLSDataPath); envPath != "" {
return envPath
} else {
return common.DefaultPathTLSConfig
Expand All @@ -100,11 +99,10 @@ func GetTLSCertificateDataPath() string {
// filesystem. If ARGOCD_SSH_DATA_PATH environment is set, path is taken from
// there, otherwise the default will be returned.
func GetSSHKnownHostsDataPath() string {
envPath := os.Getenv(common.EnvVarSSHDataPath)
if envPath != "" {
return envPath + "/" + common.DefaultSSHKnownHostsName
if envPath := os.Getenv(common.EnvVarSSHDataPath); envPath != "" {
return filepath.Join(envPath, common.DefaultSSHKnownHostsName)
} else {
return common.DefaultPathSSHConfig + "/" + common.DefaultSSHKnownHostsName
return filepath.Join(common.DefaultPathSSHConfig, common.DefaultSSHKnownHostsName)
}
}

Expand Down Expand Up @@ -302,9 +300,6 @@ func ServerNameWithoutPort(serverName string) string {
// consider it an error and just return empty data.
func GetCertificateForConnect(serverName string) ([]string, error) {
dataPath := GetTLSCertificateDataPath()
if !strings.HasSuffix(dataPath, "/") {
dataPath += "/"
}
certPath, err := filepath.Abs(filepath.Join(dataPath, ServerNameWithoutPort(serverName)))
if err != nil {
return nil, err
Expand Down Expand Up @@ -332,7 +327,7 @@ func GetCertificateForConnect(serverName string) ([]string, error) {
// mount. This function makes sure that the path returned actually contain
// at least one valid certificate, and no invalid data.
func GetCertBundlePathForRepository(serverName string) (string, error) {
certPath := fmt.Sprintf("%s/%s", GetTLSCertificateDataPath(), ServerNameWithoutPort(serverName))
certPath := filepath.Join(GetTLSCertificateDataPath(), ServerNameWithoutPort(serverName))
certs, err := GetCertificateForConnect(serverName)
if err != nil {
return "", nil
Expand Down

0 comments on commit 4b4fd88

Please sign in to comment.