Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching to official grafana OpenAPI #208

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/backup/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/esnet/gdg/cli/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 cli/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/cli/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
23 changes: 11 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ require (
github.com/aws/aws-sdk-go v1.47.10
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-20231121122459-f5f9577785f0
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 Down Expand Up @@ -74,7 +75,7 @@ require (
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -87,9 +88,8 @@ 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/go-openapi/validate v0.22.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -99,7 +99,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/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand Down Expand Up @@ -150,9 +149,9 @@ require (
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.mongodb.org/mongo-driver v1.13.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.20.0 // indirect
go.opentelemetry.io/otel/metric v1.20.0 // indirect
go.opentelemetry.io/otel/trace v1.20.0 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/mod v0.14.0 // indirect
Expand All @@ -165,11 +164,11 @@ require (
golang.org/x/time v0.4.0 // indirect
golang.org/x/tools v0.15.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.150.0 // indirect
google.golang.org/api v0.151.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // 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
Expand Down
119 changes: 20 additions & 99 deletions go.sum

Large diffs are not rendered by default.

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: 1 addition & 2 deletions 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 @@ -36,7 +36,6 @@ func DuplicateConfig(t *testing.T) string {
}

func TestSetup(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
12 changes: 7 additions & 5 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
safaci2000 marked this conversation as resolved.
Show resolved Hide resolved
//var newFolder models.CreateFolderCommand
if err = json.Unmarshal(rawFolder, &newFolder); err != nil {
slog.Warn("failed to unmarshall folder", "err", err)
continue
Expand Down Expand Up @@ -273,7 +275,7 @@ func (s *DashNGoImpl) UploadFolders(filter filters.Filter) []string {
return result
}

// DeleteAllFolder deletes all the matching folders from grafana
// DeleteAllFolders deletes all the matching folders from grafana
func (s *DashNGoImpl) DeleteAllFolders(filter filters.Filter) []string {
var result []string
folderListing := s.ListFolder(filter)
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
Loading