Skip to content

Commit 2dcd8df

Browse files
committed
add read access token from file
Fixes #42 Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 8d6efac commit 2dcd8df

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,49 @@ Application Options:
2020
--log.json Switch log output to json format [$LOG_JSON]
2121
--scrape.time= Default scrape time (time.duration) (default: 30m) [$SCRAPE_TIME]
2222
--scrape.time.projects= Scrape time for project metrics (time.duration) [$SCRAPE_TIME_PROJECTS]
23-
--scrape.time.repository= Scrape time for repository metrics (time.duration) [$SCRAPE_TIME_REPOSITORY]
23+
--scrape.time.repository= Scrape time for repository metrics (time.duration)
24+
[$SCRAPE_TIME_REPOSITORY]
2425
--scrape.time.build= Scrape time for build metrics (time.duration) [$SCRAPE_TIME_BUILD]
2526
--scrape.time.release= Scrape time for release metrics (time.duration) [$SCRAPE_TIME_RELEASE]
26-
--scrape.time.deployment= Scrape time for deployment metrics (time.duration) [$SCRAPE_TIME_DEPLOYMENT]
27-
--scrape.time.pullrequest= Scrape time for pullrequest metrics (time.duration) [$SCRAPE_TIME_PULLREQUEST]
27+
--scrape.time.deployment= Scrape time for deployment metrics (time.duration)
28+
[$SCRAPE_TIME_DEPLOYMENT]
29+
--scrape.time.pullrequest= Scrape time for pullrequest metrics (time.duration)
30+
[$SCRAPE_TIME_PULLREQUEST]
2831
--scrape.time.stats= Scrape time for stats metrics (time.duration) [$SCRAPE_TIME_STATS]
29-
--scrape.time.resourceusage= Scrape time for resourceusage metrics (time.duration) [$SCRAPE_TIME_RESOURCEUSAGE]
32+
--scrape.time.resourceusage= Scrape time for resourceusage metrics (time.duration)
33+
[$SCRAPE_TIME_RESOURCEUSAGE]
3034
--scrape.time.query= Scrape time for query results (time.duration) [$SCRAPE_TIME_QUERY]
31-
--scrape.time.live= Scrape time for live metrics (time.duration) (default: 30s) [$SCRAPE_TIME_LIVE]
35+
--scrape.time.live= Scrape time for live metrics (time.duration) (default: 30s)
36+
[$SCRAPE_TIME_LIVE]
3237
--stats.summary.maxage= Stats Summary metrics max age (time.duration) [$STATS_SUMMARY_MAX_AGE]
3338
--azuredevops.url= Azure DevOps url (empty if hosted by microsoft) [$AZURE_DEVOPS_URL]
3439
--azuredevops.access-token= Azure DevOps access token [$AZURE_DEVOPS_ACCESS_TOKEN]
40+
--azuredevops.access-token-file= Azure DevOps access token (from file) [$AZURE_DEVOPS_ACCESS_TOKEN_FILE]
3541
--azuredevops.organisation= Azure DevOps organization [$AZURE_DEVOPS_ORGANISATION]
3642
--azuredevops.apiversion= Azure DevOps API version (default: 5.1) [$AZURE_DEVOPS_APIVERSION]
43+
--azuredevops.agentpool= Enable scrape metrics for agent pool (IDs) [$AZURE_DEVOPS_AGENTPOOL]
3744
--whitelist.project= Filter projects (UUIDs) [$AZURE_DEVOPS_FILTER_PROJECT]
3845
--blacklist.project= Filter projects (UUIDs) [$AZURE_DEVOPS_BLACKLIST_PROJECT]
39-
--whitelist.agentpool= Filter of agent pool (IDs) [$AZURE_DEVOPS_FILTER_AGENTPOOL]
40-
--list.query= Pairs of query and project UUIDs in the form: '<queryId>@<projectId>' [$AZURE_DEVOPS_QUERIES]
41-
--request.concurrency= Number of concurrent requests against dev.azure.com (default: 10) [$REQUEST_CONCURRENCY]
42-
--request.retries= Number of retried requests against dev.azure.com (default: 3) [$REQUEST_RETRIES]
46+
--list.query= Pairs of query and project UUIDs in the form: '<queryId>@<projectId>'
47+
[$AZURE_DEVOPS_QUERIES]
48+
--request.concurrency= Number of concurrent requests against dev.azure.com (default: 10)
49+
[$REQUEST_CONCURRENCY]
50+
--request.retries= Number of retried requests against dev.azure.com (default: 3)
51+
[$REQUEST_RETRIES]
4352
--limit.project= Limit number of projects (default: 100) [$LIMIT_PROJECT]
4453
--limit.builds-per-project= Limit builds per project (default: 100) [$LIMIT_BUILDS_PER_PROJECT]
4554
--limit.builds-per-definition= Limit builds per definition (default: 10) [$LIMIT_BUILDS_PER_DEFINITION]
4655
--limit.releases-per-project= Limit releases per project (default: 100) [$LIMIT_RELEASES_PER_PROJECT]
47-
--limit.releases-per-definition= Limit releases per definition (default: 100) [$LIMIT_RELEASES_PER_DEFINITION]
48-
--limit.deployments-per-definition= Limit deployments per definition (default: 100) [$LIMIT_DEPLOYMENTS_PER_DEFINITION]
49-
--limit.releasedefinitions-per-project= Limit builds per definition (default: 100) [$LIMIT_RELEASEDEFINITION_PER_PROJECT]
50-
--limit.build-history-duration= Time (time.Duration) how long the exporter should look back for builds (default: 48h) [$LIMIT_BUILD_HISTORY_DURATION]
51-
--limit.release-history-duration= Time (time.Duration) how long the exporter should look back for releases (default: 48h) [$LIMIT_RELEASE_HISTORY_DURATION]
56+
--limit.releases-per-definition= Limit releases per definition (default: 100)
57+
[$LIMIT_RELEASES_PER_DEFINITION]
58+
--limit.deployments-per-definition= Limit deployments per definition (default: 100)
59+
[$LIMIT_DEPLOYMENTS_PER_DEFINITION]
60+
--limit.releasedefinitions-per-project= Limit builds per definition (default: 100)
61+
[$LIMIT_RELEASEDEFINITION_PER_PROJECT]
62+
--limit.build-history-duration= Time (time.Duration) how long the exporter should look back for builds
63+
(default: 48h) [$LIMIT_BUILD_HISTORY_DURATION]
64+
--limit.release-history-duration= Time (time.Duration) how long the exporter should look back for
65+
releases (default: 48h) [$LIMIT_RELEASE_HISTORY_DURATION]
5266
--bind= Server address (default: :8080) [$SERVER_BIND]
5367
5468
Help Options:

config/opts.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ type (
3737

3838
// azure settings
3939
AzureDevops struct {
40-
Url *string `long:"azuredevops.url" env:"AZURE_DEVOPS_URL" description:"Azure DevOps url (empty if hosted by microsoft)"`
41-
AccessToken string `long:"azuredevops.access-token" env:"AZURE_DEVOPS_ACCESS_TOKEN" description:"Azure DevOps access token" required:"true" json:"-"`
42-
Organisation string `long:"azuredevops.organisation" env:"AZURE_DEVOPS_ORGANISATION" description:"Azure DevOps organization" required:"true"`
43-
ApiVersion string `long:"azuredevops.apiversion" env:"AZURE_DEVOPS_APIVERSION" description:"Azure DevOps API version" default:"5.1"`
40+
Url *string `long:"azuredevops.url" env:"AZURE_DEVOPS_URL" description:"Azure DevOps url (empty if hosted by microsoft)"`
41+
AccessToken string `long:"azuredevops.access-token" env:"AZURE_DEVOPS_ACCESS_TOKEN" description:"Azure DevOps access token" json:"-"`
42+
AccessTokenFile *string `long:"azuredevops.access-token-file" env:"AZURE_DEVOPS_ACCESS_TOKEN_FILE" description:"Azure DevOps access token (from file)"`
43+
Organisation string `long:"azuredevops.organisation" env:"AZURE_DEVOPS_ORGANISATION" description:"Azure DevOps organization" required:"true"`
44+
ApiVersion string `long:"azuredevops.apiversion" env:"AZURE_DEVOPS_APIVERSION" description:"Azure DevOps API version" default:"5.1"`
4445

4546
// agentpool
4647
AgentPoolIdList []int64 `long:"azuredevops.agentpool" env:"AZURE_DEVOPS_AGENTPOOL" env-delim:" " description:"Enable scrape metrics for agent pool (IDs)"`

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ func initArgparser() {
9898
})
9999
}
100100

101+
// load accesstoken from file
102+
if opts.AzureDevops.AccessTokenFile != nil && len(*opts.AzureDevops.AccessTokenFile) > 0 {
103+
log.Infof("reading access token from file \"%s\"", *opts.AzureDevops.AccessTokenFile)
104+
// load access token from file
105+
if val, err := os.ReadFile(*opts.AzureDevops.AccessTokenFile); err == nil {
106+
opts.AzureDevops.AccessToken = strings.TrimSpace(string(val))
107+
} else {
108+
log.Panicf("unable to read access token file \"%s\": %v", *opts.AzureDevops.AccessTokenFile, err)
109+
}
110+
}
111+
112+
if len(opts.AzureDevops.AccessToken) == 0 {
113+
log.Panicf("no Azure DevOps access token specified")
114+
}
115+
101116
// ensure query paths and projects are splitted by '@'
102117
if opts.AzureDevops.QueriesWithProjects != nil {
103118
queryError := false

0 commit comments

Comments
 (0)