Skip to content

Commit

Permalink
Merge pull request #137 from sudo-bmitch/pr-valid-oauth-username
Browse files Browse the repository at this point in the history
Require a valid oauth2 username
  • Loading branch information
rafibarash authored Jun 16, 2023
2 parents 62afb27 + 69e55d2 commit 96952ab
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config
import (
"context"
"fmt"
"regexp"
"runtime/debug"
"strings"

Expand Down Expand Up @@ -124,4 +125,13 @@ var GCRScopes = []string{"https://www.googleapis.com/auth/devstorage.read_write"
var OAuthHTTPContext = context.Background()

// GcrOAuth2Username is the Basic auth username accompanying Docker requests to GCR.
var GcrOAuth2Username = fmt.Sprintf("_dcgcr_%s_token", strings.ReplaceAll(Version, ".", "_"))
var GcrOAuth2Username string

func init() {
re := regexp.MustCompile(`^(?:[0-9]+\._)*$`)
if re.MatchString(Version) {
GcrOAuth2Username = fmt.Sprintf("_dcgcr_%s_token", strings.ReplaceAll(Version, ".", "_"))
} else {
GcrOAuth2Username = "_dcgcr_0_0_0_token"
}
}

0 comments on commit 96952ab

Please sign in to comment.