Skip to content

Commit

Permalink
Updating dependency, adding retry logic, and updating init
Browse files Browse the repository at this point in the history
  • Loading branch information
safaci2000 committed Oct 25, 2023
1 parent b3e7ffd commit 95241d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions internal/service/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -32,7 +32,7 @@ var (
)

type DashNGoImpl struct {
officialClient *client.GrafanaHTTPAPI
officialClient *goapi.GrafanaHTTPAPI
extended *api.ExtendedApi

grafanaConf *config.GrafanaConfig
Expand Down
24 changes: 17 additions & 7 deletions internal/service/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down

0 comments on commit 95241d7

Please sign in to comment.