Skip to content

Commit a587531

Browse files
committed
docs: fix golint warnings
1 parent f4a23a6 commit a587531

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

cmd/git-remote-https+iap/main.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@ import (
1616
)
1717

1818
const (
19-
BinaryName = "git-remote-https+iap"
20-
2119
// DebugEnvVariable is the name of the environment variable that needs to be set in order to enable debug logging
2220
DebugEnvVariable = "GIT_IAP_VERBOSE"
2321
)
2422

2523
var (
26-
version string
24+
binaryName = os.Args[0]
25+
version string
2726

2827
// only used in configureCmd
2928
repoURL, helperID, helperSecret, clientID string
3029

3130
rootCmd = &cobra.Command{
32-
Use: fmt.Sprintf("%s remote url", BinaryName),
31+
Use: fmt.Sprintf("%s remote url", binaryName),
3332
Short: "git-remote-helper that handles authentication for GCP Identity Aware Proxy",
3433
Args: cobra.ExactArgs(2),
3534
Run: execute,
@@ -84,18 +83,18 @@ func main() {
8483

8584
func execute(cmd *cobra.Command, args []string) {
8685
remote, url := args[0], args[1]
87-
log.Debug().Msgf("%s %s %s", BinaryName, remote, url)
86+
log.Debug().Msgf("%s %s %s", binaryName, remote, url)
8887

8988
handleIAPAuthCookieFor(url)
9089
git.PassThruRemoteHTTPSHelper(remote, url)
9190
}
9291

9392
func printVersion(cmd *cobra.Command, args []string) {
94-
fmt.Printf("%s %s\n", BinaryName, version)
93+
fmt.Printf("%s %s\n", binaryName, version)
9594
}
9695

9796
func installGitProtocol(cmd *cobra.Command, args []string) {
98-
p := strings.TrimLeft(BinaryName, "git-remote-")
97+
p := strings.TrimLeft(binaryName, "git-remote-")
9998
git.InstallProtocol(p)
10099
log.Info().Msgf("%s protocol configured in git!", p)
101100
}

internal/git/git.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func ConfigGetURLMatch(key, url string) string {
3333
return strings.TrimSpace(string(stdout.Bytes()))
3434
}
3535

36+
// SetGlobalConfig allows to set system-wide Git configuration.
37+
// The application exits in case of error.
3638
func SetGlobalConfig(url, section, key, value string) {
3739
x := fmt.Sprintf("%s.%s.%s", section, url, key)
3840
args := []string{"config", "--global", x, value}
@@ -43,6 +45,8 @@ func SetGlobalConfig(url, section, key, value string) {
4345
}
4446
}
4547

48+
// PassThruRemoteHTTPSHelper exec the git-remote-https helper,
49+
// which allows the caller to transparently pass-thru it.
4650
func PassThruRemoteHTTPSHelper(remote, url string) {
4751
u, err := _url.Parse(url)
4852
if err != nil {
@@ -63,6 +67,8 @@ func PassThruRemoteHTTPSHelper(remote, url string) {
6367
}
6468
}
6569

70+
// StoreCredentials persists credentials on disk, using the built-in
71+
// git-credential-store helper.
6672
func StoreCredentials(protocol, host, username, password string) error {
6773
var stdin bytes.Buffer
6874

@@ -80,6 +86,7 @@ func StoreCredentials(protocol, host, username, password string) error {
8086
return res
8187
}
8288

89+
// GetCredentials retrieves credentials from the built-in git-credential-store helper.
8390
func GetCredentials(protocol, host, username string) (string, error) {
8491
var stdin, stdout bytes.Buffer
8592

@@ -102,6 +109,7 @@ func GetCredentials(protocol, host, username string) (string, error) {
102109
return "", fmt.Errorf("GetCredentials - not found for protocol=%s,host=%s,username=%s", protocol, host, username)
103110
}
104111

112+
// InstallProtocol configure Git to allow a given protocol on the system.
105113
func InstallProtocol(protocol string) {
106114
protocol = fmt.Sprintf("protocol.%s.allow", protocol)
107115
args := []string{"config", "--global", protocol, "always"}

internal/iap/cookie.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
IAPCookieName = "GCP_IAAP_AUTH_TOKEN"
2222
)
2323

24+
// A Cookie holds pieces of information required to manage the IAP cookie
2425
type Cookie struct {
2526
JarPath string
2627
Domain string

internal/iap/token.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ import (
1717
)
1818

1919
const (
20+
// CacheProtocol is the protocol used when saving the refresh-token in git-credential-store
21+
// It can be an arbitrary value.
2022
CacheProtocol = "iap"
23+
24+
// CacheUsername is the username used when saving the refresh-token in git-credential-store.
25+
// It can be an arbitrary value.
2126
CacheUsername = "refresh-token"
2227
)
2328

24-
type Token struct {
29+
type token struct {
2530
AccessToken string `json:"access_token"`
2631
ExpiresIn int `json:"expires_in"`
2732
Scope string `json:"scope"`
@@ -95,9 +100,12 @@ func getRefreshTokenFromCache(key string) (string, error) {
95100
return git.GetCredentials(CacheProtocol, key, CacheUsername)
96101
}
97102

98-
// GetIAPAuthToken returns a raw IAP auth token for the given args
103+
// GetIAPAuthToken take care of the IAP Authentication process when relevant.
104+
// It optmize this workflow by detecting cases where an existing IAP auth token is already available,
105+
// and caching a refresh-token.
106+
// It returns a raw IAP auth token and any error encountered.
99107
func GetIAPAuthToken(domain, helperID, helperSecret, IAPclientID string) (string, error) {
100-
var result Token
108+
var result token
101109

102110
refreshToken, err := getRefreshTokenFromCache(domain)
103111
if err != nil {

0 commit comments

Comments
 (0)