-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor ServerConfig into 'config' package
- Loading branch information
Matt Morrison
committed
Jul 25, 2023
1 parent
405eb5b
commit 38a529f
Showing
10 changed files
with
85 additions
and
76 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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package pkg | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
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,55 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
|
||
giturls "github.com/whilp/git-urls" | ||
) | ||
|
||
type ServerConfig struct { | ||
ArgoCdNamespace string | ||
UrlPrefix string | ||
WebhookSecret string | ||
VcsToArgoMap VcsToArgoMap | ||
} | ||
|
||
func (cfg *ServerConfig) GetVcsRepos() []string { | ||
var repos []string | ||
for key := range cfg.VcsToArgoMap.vcsAppStubsByRepo { | ||
repos = append(repos, key.CloneURL()) | ||
} | ||
return repos | ||
} | ||
|
||
type repoURL struct { | ||
Host, Path string | ||
} | ||
|
||
func (r repoURL) CloneURL() string { | ||
return fmt.Sprintf("git@%s:%s", r.Host, r.Path) | ||
} | ||
|
||
func buildNormalizedRepoUrl(host, path string) repoURL { | ||
path = strings.TrimPrefix(path, "/") | ||
path = strings.TrimSuffix(path, ".git") | ||
return repoURL{host, path} | ||
} | ||
|
||
func normalizeRepoUrl(s string) (repoURL, error) { | ||
var parser func(string) (*url.URL, error) | ||
|
||
if strings.HasPrefix(s, "http") { | ||
parser = url.Parse | ||
} else { | ||
parser = giturls.Parse | ||
} | ||
|
||
r, err := parser(s) | ||
if err != nil { | ||
return repoURL{}, err | ||
} | ||
|
||
return buildNormalizedRepoUrl(r.Host, r.Path), 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
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
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