Skip to content

Commit

Permalink
Merge pull request #6 from zozs/master
Browse files Browse the repository at this point in the history
feat: add optional IPv6 support for Docker Hub
  • Loading branch information
kha7iq authored Mar 28, 2023
2 parents 1cd7ed1 + 387fa74 commit 72b80ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ make docker
| DOCKERHUB_REPO_IMAGE | ratelimitpreview/test | custom repository/image |
| ENABLE_FILE_AUTH | false | Load auth credentials from docker config file<br>at /$FILE_AUTH_DIR/config.json<br>Must leave auth through ENV empty. |
| FILE_AUTH_DIR | /config | Directory where config.json resides |
| ENABLE_IPV6 | false | Use IPv6 instead of IPv4 when fetching rate limits |
<br>

Example docker configuration config.json file below. <br>
Expand Down
12 changes: 10 additions & 2 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ var DockerLabels = make(map[string]string, 1)
// GetMetrics will save metrics in a float64 map
func GetMetrics() {
l := log.New(os.Stdout, "drl-exporter ", log.LstdFlags)
tokenUrl := "https://auth.docker.io/token?service=" +

tokenBaseUrl := "https://auth.docker.io"
repoBaseUrl := "https://registry-1.docker.io"
if *vars.EnableIPv6 {
tokenBaseUrl = "https://auth.ipv6.docker.com"
repoBaseUrl = "https://registry.ipv6.docker.com"
}

tokenUrl := tokenBaseUrl + "/token?service=" +
"registry.docker.io&scope=repository:" + *vars.DockerRepoImage + ":pull"
repoUrl := "https://registry-1.docker.io/v2/" +
repoUrl := repoBaseUrl + "/v2/" +
"registry.docker.io&scope=repository:" + *vars.DockerRepoImage + "/manifests/latest"

tr, err := tokenRequest(tokenUrl)
Expand Down
1 change: 1 addition & 0 deletions internal/vars/envars.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ var (
EnableUserAuth = env.Bool("ENABLE_USER_AUTH", false, false, "Enable metrics for users")
EnableFileAuth = env.Bool("ENABLE_FILE_AUTH", false, false, "Enable authentication through docker configuration file 'config.json'")
FileAuthDir = env.String("FILE_AUTH_DIR", false, "/config", "Directory to load 'config.json' docker configuration from")
EnableIPv6 = env.Bool("ENABLE_IPV6", false, false, "Use IPv6 instead of IPv4")
)

0 comments on commit 72b80ad

Please sign in to comment.