diff --git a/go.mod b/go.mod index f9413513..003b637b 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/carlmjohnson/requests v0.23.4 github.com/go-openapi/runtime v0.26.0 github.com/go-openapi/strfmt v0.21.7 - github.com/grafana/grafana-openapi-client-go v0.0.0-20231017131745-480147ff8f3d + github.com/grafana/grafana-openapi-client-go v0.0.0-20231025135510-3891e4362f08 github.com/jedib0t/go-pretty/v6 v6.4.8 github.com/ory/dockertest/v3 v3.10.0 github.com/samber/lo v1.38.1 diff --git a/go.sum b/go.sum index 4331f448..25bb4101 100644 --- a/go.sum +++ b/go.sum @@ -346,6 +346,8 @@ github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6 github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc= github.com/grafana/grafana-openapi-client-go v0.0.0-20231017131745-480147ff8f3d h1:P2lchYp6VnA9h6k/JrAF5ofNblUR6LcZSyKpjfaPLdM= github.com/grafana/grafana-openapi-client-go v0.0.0-20231017131745-480147ff8f3d/go.mod h1:2vJ8YEgriYoHaNg5eijRU/q7eJTxT078VrGRSTTLeRk= +github.com/grafana/grafana-openapi-client-go v0.0.0-20231025135510-3891e4362f08 h1:MHwtJl5FGXlRQ0Maay+WHwXpGnwFJIS1iN2ntgNrWuU= +github.com/grafana/grafana-openapi-client-go v0.0.0-20231025135510-3891e4362f08/go.mod h1:2vJ8YEgriYoHaNg5eijRU/q7eJTxT078VrGRSTTLeRk= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= diff --git a/internal/service/contract.go b/internal/service/contract.go index b2ea785c..e9ace398 100644 --- a/internal/service/contract.go +++ b/internal/service/contract.go @@ -4,7 +4,7 @@ import ( "context" "github.com/esnet/gdg/internal/api" "github.com/esnet/gdg/internal/config" - "github.com/grafana/grafana-openapi-client-go/client" + goapi "github.com/grafana/grafana-openapi-client-go/client" log "github.com/sirupsen/logrus" "github.com/spf13/viper" @@ -32,7 +32,7 @@ var ( ) type DashNGoImpl struct { - officialClient *client.GrafanaHTTPAPI + officialClient *goapi.GrafanaHTTPAPI extended *api.ExtendedApi grafanaConf *config.GrafanaConfig diff --git a/internal/service/login.go b/internal/service/login.go index 0a965c70..ecb16e16 100644 --- a/internal/service/login.go +++ b/internal/service/login.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/esnet/gdg/internal/api" "github.com/esnet/gdg/internal/config" - runtimeClient "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" "net/url" @@ -32,16 +31,27 @@ func (s *DashNGoImpl) Login() { } var clientTransport *http.Transport httpClient := &http.Client{} - officialCfg := client.TransportConfig{ - BasePath: "/api", - Schemes: []string{u.Scheme}, + httpTransportCfg := client.TransportConfig{ + Host: u.Host, + BasePath: "/api", + Schemes: []string{u.Scheme}, + NumRetries: 3, } + if config.Config().IgnoreSSL() { httpClient, clientTransport = ignoreSSLErrors() - officialCfg.TLSConfig = clientTransport.TLSClientConfig + httpTransportCfg.TLSConfig = clientTransport.TLSClientConfig + } + if s.grafanaConf.UserName != "" && s.grafanaConf.Password != "" { + httpTransportCfg.BasicAuth = url.UserPassword(s.grafanaConf.UserName, s.grafanaConf.Password) + } + if s.grafanaConf.APIToken != "" { + httpTransportCfg.APIKey = s.grafanaConf.APIToken + } + if s.grafanaConf.OrganizationId != 0 { + httpTransportCfg.OrgID = s.grafanaConf.OrganizationId } - swaggerObj := runtimeClient.NewWithClient(u.Host, "/api", []string{u.Scheme}, httpClient) - s.officialClient = client.New(swaggerObj, &officialCfg, nil) + s.officialClient = client.NewHTTPClientWithConfig(strfmt.Default, &httpTransportCfg) userInfo, err := s.GetUserInfo() //Sets state based on user permissions