feat: pass gcom sso_api_token to repo created from install command (#98973)
* feat: pass gcom sso_api_token to repo created from install command * fix * fix: extract gcom section to a func * Update pkg/cmd/grafana-cli/utils/command_line.go Co-authored-by: Giuseppe Guerra <giuseppe.guerra@grafana.com> * fix: only set gcom token when the request is to GCOM --------- Co-authored-by: Giuseppe Guerra <giuseppe.guerra@grafana.com>
This commit is contained in:
co-authored by
Giuseppe Guerra
parent
79fc26ea87
commit
dfe0712955
@@ -70,7 +70,7 @@ func Test_Download(t *testing.T) {
|
||||
require.Equal(t, 2, count, "should retry on error")
|
||||
})
|
||||
|
||||
t.Run("it should use gcom token when it's available", func(t *testing.T) {
|
||||
t.Run("it should use gcom token when the token is available and request is to GCOM", func(t *testing.T) {
|
||||
expectedToken := "token-test"
|
||||
var gcomCalled bool
|
||||
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -82,9 +82,29 @@ func Test_Download(t *testing.T) {
|
||||
}))
|
||||
defer fakeServer.Close()
|
||||
cli := fakeServer.Client()
|
||||
repo := Client{httpClient: *cli, httpClientNoTimeout: *cli, log: log.NewPrettyLogger("test"), grafanaComAPIToken: expectedToken}
|
||||
_, err := repo.Download(context.Background(), fakeServer.URL, "", CompatOpts{})
|
||||
pluginURL := fakeServer.URL + "/api/plugins/test-datasource"
|
||||
gcomAPIURL := fakeServer.URL + "/api/plugins"
|
||||
repo := Client{httpClient: *cli, httpClientNoTimeout: *cli, log: log.NewPrettyLogger("test"), grafanaComAPIToken: expectedToken, grafanaComAPIURL: gcomAPIURL}
|
||||
_, err := repo.Download(context.Background(), pluginURL, "", CompatOpts{})
|
||||
require.NoError(t, err)
|
||||
require.True(t, gcomCalled)
|
||||
})
|
||||
|
||||
t.Run("it should not set gcom token when the token is available but request is NOT to GCOM", func(t *testing.T) {
|
||||
expectedToken := "token-test"
|
||||
var serverCalled bool
|
||||
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
token := r.Header.Get("Authorization")
|
||||
require.Empty(t, token, "token should not be set")
|
||||
err := writeFakeZip(w)
|
||||
require.NoError(t, err)
|
||||
serverCalled = true
|
||||
}))
|
||||
defer fakeServer.Close()
|
||||
cli := fakeServer.Client()
|
||||
repo := Client{httpClient: *cli, httpClientNoTimeout: *cli, log: log.NewPrettyLogger("test"), grafanaComAPIToken: expectedToken, grafanaComAPIURL: "https://grafana.com/api/plugins"}
|
||||
_, err := repo.Download(context.Background(), fakeServer.URL, "", CompatOpts{})
|
||||
require.NoError(t, err)
|
||||
require.True(t, serverCalled)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user