Skip to content

Commit 46e8409

Browse files
authored
feat: Support for bearer tokens in profilecli. (#4475)
* feat: Support for bearer tokens in profilecli. This allows to easily connect via Grafana data source proxies: ``` PROFILECLI_URL=https://ops.grafana-ops.net/api/datasources/proxy/uid/grafanacloud-profiles PROFILECLI_TOKEN=glsa_xyz profilecli query series --label-names "service_repository" ``` * Improve language
1 parent f7aba2a commit 46e8409

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cmd/profilecli/client.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ const (
2020
var userAgentHeader = fmt.Sprintf("pyroscope/%s", version.Version)
2121

2222
type phlareClient struct {
23-
TenantID string
24-
URL string
25-
BasicAuth struct {
23+
TenantID string
24+
URL string
25+
BearerToken string
26+
BasicAuth struct {
2627
Username string
2728
Password string
2829
}
@@ -43,6 +44,8 @@ func (a *authRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
4344
}
4445
if c.BasicAuth.Username != "" || c.BasicAuth.Password != "" {
4546
req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password)
47+
} else if c.BearerToken != "" {
48+
req.Header.Set("Authorization", "Bearer "+c.BearerToken)
4649
}
4750
}
4851

@@ -84,8 +87,9 @@ type commander interface {
8487
func addPhlareClient(cmd commander) *phlareClient {
8588
client := &phlareClient{}
8689

87-
cmd.Flag("url", "URL of the profile store.").Default("http://localhost:4040").Envar(envPrefix + "URL").StringVar(&client.URL)
90+
cmd.Flag("url", "URL of the Pyroscope Endpoint. (Examples: https://profiles-prod-001.grafana.net for a Grafana Cloud endpoint, https://grafana.example.net/api/datasources/proxy/uid/<uid> when using the Grafana data source proxy)").Default("http://localhost:4040").Envar(envPrefix + "URL").StringVar(&client.URL)
8891
cmd.Flag("tenant-id", "The tenant ID to be used for the X-Scope-OrgID header.").Default("").Envar(envPrefix + "TENANT_ID").StringVar(&client.TenantID)
92+
cmd.Flag("token", "The bearer token to be used for communication with the server. Particularly useful when connecting to Grafana data source URLs (bearer token should be a Grafana Service Account token of the form 'glsa_[...]')").Default("").Envar(envPrefix + "TOKEN").StringVar(&client.BearerToken)
8993
cmd.Flag("username", "The username to be used for basic auth.").Default("").Envar(envPrefix + "USERNAME").StringVar(&client.BasicAuth.Username)
9094
cmd.Flag("password", "The password to be used for basic auth.").Default("").Envar(envPrefix + "PASSWORD").StringVar(&client.BasicAuth.Password)
9195
cmd.Flag("protocol", "The protocol to be used for communicating with the server.").Default(protocolTypeConnect).EnumVar(&client.protocol,

0 commit comments

Comments
 (0)