Skip to content

Commit

Permalink
Switching to official grafana OpenAPI
Browse files Browse the repository at this point in the history
Fixes #217
  • Loading branch information
safaci2000 committed Nov 13, 2023
1 parent 91cc966 commit d145b2e
Show file tree
Hide file tree
Showing 41 changed files with 124 additions and 145 deletions.
2 changes: 1 addition & 1 deletion cmd/backup/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/esnet/gdg/cmd/support"
"github.com/esnet/gdg/internal/config"
api "github.com/esnet/gdg/internal/service"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
"log/slog"
Expand Down
2 changes: 1 addition & 1 deletion cmd/test/conections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/esnet/gdg/cmd/support"
"github.com/esnet/gdg/internal/service"
"github.com/esnet/gdg/internal/service/mocks"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io"
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ require (
github.com/aws/aws-sdk-go v1.47.3
github.com/bep/simplecobra v0.3.2
github.com/carlmjohnson/requests v0.23.5
github.com/esnet/grafana-swagger-api-golang v0.0.0-20230904013855-9a47b55d30d3
github.com/go-openapi/runtime v0.26.0
github.com/go-openapi/strfmt v0.21.7
github.com/google/uuid v1.4.0
github.com/gosimple/slug v1.13.1
github.com/grafana/grafana-openapi-client-go v0.0.0-20231112232708-b03b585a9658
github.com/jedib0t/go-pretty/v6 v6.4.9
github.com/lmittmann/tint v1.0.3
github.com/mattn/go-isatty v0.0.20
Expand All @@ -22,8 +23,13 @@ require (
github.com/thoas/go-funk v0.9.3
github.com/tidwall/gjson v1.17.0
github.com/tidwall/pretty v1.2.1
go.mongodb.org/mongo-driver v1.12.1 // indirect
gocloud.dev v0.34.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -80,7 +86,6 @@ require (
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/strfmt v0.21.7 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand All @@ -93,7 +98,6 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -118,6 +122,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
Expand All @@ -131,7 +136,6 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
Expand All @@ -142,9 +146,6 @@ require (
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.149.0 // indirect
Expand All @@ -154,6 +155,5 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/esnet/grafana-swagger-api-golang v0.0.0-20230904013855-9a47b55d30d3 h1:5Pzswqykeauap1602DZwSl1qTQaH93oXxuYeEMk4rKg=
github.com/esnet/grafana-swagger-api-golang v0.0.0-20230904013855-9a47b55d30d3/go.mod h1:KY/r+1ImaUFhABgjy/6imZARoe4uRpu8lj3hGW6KFtI=
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
Expand Down Expand Up @@ -225,8 +223,6 @@ github.com/go-openapi/validate v0.22.1/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUri
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b h1:/vQ+oYKu+JoyaMPDsv5FzwuL2wwWBgBbtj/YLCi4LuA=
github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b/go.mod h1:Xo4aNUOrJnVruqWQJBtW6+bTBDTniY8yZum5rF3b5jw=
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
Expand Down Expand Up @@ -347,8 +343,10 @@ github.com/gosimple/slug v1.13.1 h1:bQ+kpX9Qa6tHRaK+fZR0A0M2Kd7Pa5eHPPsb1JpHD+Q=
github.com/gosimple/slug v1.13.1/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/grafana/grafana-openapi-client-go v0.0.0-20231031181526-6f78415901a3 h1:jZrhPmoUBL+kwwV5e2AIalKnxV0VW/e0QZ7aHP7Zg3c=
github.com/grafana/grafana-openapi-client-go v0.0.0-20231031181526-6f78415901a3/go.mod h1:2vJ8YEgriYoHaNg5eijRU/q7eJTxT078VrGRSTTLeRk=
github.com/grafana/grafana-openapi-client-go v0.0.0-20231112232708-b03b585a9658 h1:ZneazI71K21ZQJmmg/bNq3489iIg69SkLCen3Kxy7T8=
github.com/grafana/grafana-openapi-client-go v0.0.0-20231112232708-b03b585a9658/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/api/accessControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package api
import (
"context"
"fmt"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/datasource_permissions"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/grafana/grafana-openapi-client-go/client/datasource_permissions"
"github.com/grafana/grafana-openapi-client-go/models"
"net/http"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/api/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api

import "github.com/esnet/grafana-swagger-api-golang/goclient/models"
import "github.com/grafana/grafana-openapi-client-go/models"

type ServiceAccountDTOWithTokens struct {
ServiceAccount *models.ServiceAccountDTO
Expand Down
20 changes: 0 additions & 20 deletions internal/api/serviceAccounts.go

This file was deleted.

21 changes: 0 additions & 21 deletions internal/api/users.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/config/config_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/tidwall/gjson"
"log"
"log/slog"
Expand Down
3 changes: 2 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config_test
import (
"fmt"
"github.com/esnet/gdg/internal/config"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/grafana/grafana-openapi-client-go/models"
"golang.org/x/exp/slices"
"log/slog"
"os"
Expand Down Expand Up @@ -60,6 +60,7 @@ func TestSetup(t *testing.T) {
}

func TestWatchedFoldersConfig(t *testing.T) {
os.Setenv("GDG_CONTEXT_NAME", "qa")
//clear all ENV values
for _, key := range os.Environ() {
if strings.Contains(key, "GDG_") {
Expand Down
4 changes: 2 additions & 2 deletions internal/service/alertnotifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package service
import (
"encoding/json"
"github.com/esnet/gdg/internal/config"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/legacy_alerts_notification_channels"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/grafana/grafana-openapi-client-go/client/legacy_alerts_notification_channels"
"github.com/grafana/grafana-openapi-client-go/models"
"log/slog"
"strings"

Expand Down
7 changes: 4 additions & 3 deletions internal/service/connection_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/esnet/gdg/internal/config"
"github.com/esnet/gdg/internal/service/filters"
"github.com/esnet/gdg/internal/tools"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/datasource_permissions"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/gosimple/slug"
"github.com/grafana/grafana-openapi-client-go/client/datasource_permissions"
"github.com/grafana/grafana-openapi-client-go/models"
"log"
"log/slog"
"path/filepath"
Expand Down Expand Up @@ -127,7 +127,8 @@ func (s *DashNGoImpl) UploadConnectionPermissions(filter filters.Filter) []strin
if entry.BuiltInRole != "" {
p.SetBuiltinRole(tools.PtrOf(entry.BuiltInRole))
}
err = s.extended.AddConnectionPermission(p)
_, err = s.client.DatasourcePermissions.AddPermission(p, s.getAuth())
//err = s.extended.AddConnectionPermission(p)
if err != nil {
slog.Error("Failed to update folder permissions")
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/service/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"github.com/esnet/gdg/internal/config"
"github.com/esnet/gdg/internal/service/filters"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/datasources"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/grafana/grafana-openapi-client-go/client/datasources"
"github.com/grafana/grafana-openapi-client-go/models"
"log/slog"
"path/filepath"
"strings"
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/esnet/grafana-swagger-api-golang/goclient/client"
goapi "github.com/grafana/grafana-openapi-client-go/client"
"github.com/spf13/viper"
"log/slog"

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

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

grafanaConf *config.GrafanaConfig
Expand Down
16 changes: 8 additions & 8 deletions internal/service/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"fmt"
"github.com/esnet/gdg/internal/config"
"github.com/esnet/gdg/internal/service/filters"
gapi "github.com/esnet/grafana-swagger-api-golang"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/dashboards"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/folders"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/search"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/esnet/gdg/internal/tools"
"github.com/grafana/grafana-openapi-client-go/client/dashboards"
"github.com/grafana/grafana-openapi-client-go/client/folders"
"github.com/grafana/grafana-openapi-client-go/client/search"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/tidwall/pretty"
"golang.org/x/exp/slices"
"log"
Expand Down Expand Up @@ -136,9 +136,9 @@ func (s *DashNGoImpl) ListDashboards(filterReq filters.Filter) []*models.Hit {
for {
searchParams := search.NewSearchParams()
searchParams.Tag = tagsParams
searchParams.Limit = gapi.ToPtr(int64(limit))
searchParams.Page = gapi.ToPtr(int64(page))
searchParams.Type = gapi.ToPtr(searchTypeDashboard)
searchParams.Limit = tools.PtrOf(int64(limit))
searchParams.Page = tools.PtrOf(int64(page))
searchParams.Type = tools.PtrOf(searchTypeDashboard)

pageBoardLinks, err := s.client.Search.Search(searchParams, s.getAuth())
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions internal/service/folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"fmt"
"github.com/esnet/gdg/internal/config"
"github.com/esnet/gdg/internal/service/filters"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/folder_permissions"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/folders"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/search"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/gosimple/slug"
"github.com/grafana/grafana-openapi-client-go/client/folder_permissions"
"github.com/grafana/grafana-openapi-client-go/client/folders"
"github.com/grafana/grafana-openapi-client-go/client/search"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/tidwall/gjson"
"golang.org/x/exp/slices"
"log"
Expand Down Expand Up @@ -240,7 +240,9 @@ func (s *DashNGoImpl) UploadFolders(filter filters.Filter) []string {
continue
}
}

var newFolder models.CreateFolderCommand
//var newFolder models.CreateFolderCommand
if err = json.Unmarshal(rawFolder, &newFolder); err != nil {
slog.Warn("failed to unmarshall folder", "err", err)
continue
Expand All @@ -262,6 +264,7 @@ func (s *DashNGoImpl) UploadFolders(filter filters.Filter) []string {
}
params := folders.NewCreateFolderParams()
params.Body = &newFolder
//f, err := s.client.Folders.CreateFolder(params, s.getAuth())
f, err := s.client.Folders.CreateFolder(params, s.getAuth())
if err != nil {
slog.Error("failed to create folder.", "folderName", newFolder.Title, "err", err)
Expand Down
4 changes: 2 additions & 2 deletions internal/service/libraryelements.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/esnet/gdg/internal/config"
"github.com/esnet/gdg/internal/service/filters"
"github.com/esnet/gdg/internal/tools"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/library_elements"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/gosimple/slug"
"github.com/grafana/grafana-openapi-client-go/client/library_elements"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/tidwall/gjson"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
Expand Down
Loading

0 comments on commit d145b2e

Please sign in to comment.