Skip to content

Commit

Permalink
Renaming officialClient back to client
Browse files Browse the repository at this point in the history
  • Loading branch information
safaci2000 committed Oct 25, 2023
1 parent 95241d7 commit 56bfe7f
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 68 deletions.
8 changes: 4 additions & 4 deletions internal/service/alertnotifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type AlertNotificationsApi interface {

func (s *DashNGoImpl) ListAlertNotifications() []*models.AlertNotification {
params := legacy_alerts_notification_channels.NewGetAlertNotificationChannelsParams()
channels, err := s.officialClient.LegacyAlertsNotificationChannels.GetAlertNotificationChannels(params, s.getAuth())
channels, err := s.client.LegacyAlertsNotificationChannels.GetAlertNotificationChannels(params, s.getAuth())
if err != nil {
log.Panic(err)
}
Expand Down Expand Up @@ -62,7 +62,7 @@ func (s *DashNGoImpl) DeleteAllAlertNotifications() []string {
for _, item := range items {
params := legacy_alerts_notification_channels.NewDeleteAlertNotificationChannelParams()
params.NotificationChannelID = item.ID
_, err := s.officialClient.LegacyAlertsNotificationChannels.DeleteAlertNotificationChannel(params, s.getAuth())
_, err := s.client.LegacyAlertsNotificationChannels.DeleteAlertNotificationChannel(params, s.getAuth())
if err != nil {
log.Error("Failed to delete notification")
continue
Expand Down Expand Up @@ -108,7 +108,7 @@ func (s *DashNGoImpl) UploadAlertNotifications() []string {
if existing.Name == newAlertNotification.Name {
dp := legacy_alerts_notification_channels.NewDeleteAlertNotificationChannelByUIDParams()
dp.NotificationChannelUID = existing.UID
if _, err := s.officialClient.LegacyAlertsNotificationChannels.DeleteAlertNotificationChannelByUID(dp, s.getAuth()); err != nil {
if _, err := s.client.LegacyAlertsNotificationChannels.DeleteAlertNotificationChannelByUID(dp, s.getAuth()); err != nil {
log.Errorf("error on deleting datasource %s with %s", newAlertNotification.Name, err)
}
break
Expand All @@ -117,7 +117,7 @@ func (s *DashNGoImpl) UploadAlertNotifications() []string {

params := legacy_alerts_notification_channels.NewCreateAlertNotificationChannelParams()
params.Body = &newAlertNotification
if _, err = s.officialClient.LegacyAlertsNotificationChannels.CreateAlertNotificationChannel(params, s.getAuth()); err != nil {
if _, err = s.client.LegacyAlertsNotificationChannels.CreateAlertNotificationChannel(params, s.getAuth()); err != nil {
log.Errorf("error on importing datasource %s with %s", newAlertNotification.Name, err)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/connection_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (s *DashNGoImpl) deleteConnectionPermission(permissionId int64, datasourceI
deleteMe := datasource_permissions.NewDeletePermissionsParams()
deleteMe.PermissionID = fmt.Sprintf("%d", permissionId)
deleteMe.DatasourceID = fmt.Sprintf("%d", datasourceId)
resp, err := s.officialClient.DatasourcePermissions.DeletePermissions(deleteMe, s.getAuth())
resp, err := s.client.DatasourcePermissions.DeletePermissions(deleteMe, s.getAuth())
if err != nil {
return false
}
Expand All @@ -178,5 +178,5 @@ func (s *DashNGoImpl) getConnectionPermission(id int64) (*datasource_permissions
p := datasource_permissions.NewGetAllPermissionsParams()
//p.DatasourceID = fmt.Sprintf("%d", connection.ID)
p.DatasourceID = fmt.Sprintf("%d", id)
return s.officialClient.DatasourcePermissions.GetAllPermissions(p, s.getAuth())
return s.client.DatasourcePermissions.GetAllPermissions(p, s.getAuth())
}
8 changes: 4 additions & 4 deletions internal/service/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *DashNGoImpl) ListConnections(filter filters.Filter) []models.DataSource
log.Fatalf("Failed to switch organization ID %d: ", s.grafanaConf.OrganizationId)
}

ds, err := s.officialClient.Datasources.GetDataSources(datasources.NewGetDataSourcesParams(), s.getAuth())
ds, err := s.client.Datasources.GetDataSources(datasources.NewGetDataSourcesParams(), s.getAuth())
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func (s *DashNGoImpl) DeleteAllConnections(filter filters.Filter) []string {
p := datasources.NewDeleteDataSourceByIDParams()
p.ID = fmt.Sprintf("%d", item.ID)

dsItem, err := s.officialClient.Datasources.DeleteDataSourceByID(p, s.getAuth())
dsItem, err := s.client.Datasources.DeleteDataSourceByID(p, s.getAuth())
if err != nil {
log.Warningf("Failed to delete datasource: %s, response: %s", item.Name, dsItem.Error())
continue
Expand Down Expand Up @@ -178,14 +178,14 @@ func (s *DashNGoImpl) UploadConnections(filter filters.Filter) []string {
if existingDS.Name == newDS.Name {
deleteParam := datasources.NewDeleteDataSourceByIDParams()
deleteParam.ID = fmt.Sprintf("%d", existingDS.ID)
if _, err := s.officialClient.Datasources.DeleteDataSourceByID(deleteParam, s.getBasicAuth()); err != nil {
if _, err := s.client.Datasources.DeleteDataSourceByID(deleteParam, s.getBasicAuth()); err != nil {
log.Errorf("error on deleting datasource %s with %s", newDS.Name, err)
}
break
}
}
p := datasources.NewAddDataSourceParams().WithBody(&newDS)
if createStatus, err := s.officialClient.Datasources.AddDataSource(p, s.getAuth()); err != nil {
if createStatus, err := s.client.Datasources.AddDataSource(p, s.getAuth()); err != nil {
log.Errorf("error on importing datasource %s with %s (%s)", newDS.Name, err, createStatus.Error())
} else {
exported = append(exported, fileLocation)
Expand Down
4 changes: 2 additions & 2 deletions internal/service/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var (
)

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

grafanaConf *config.GrafanaConfig
configRef *viper.Viper
Expand Down
12 changes: 6 additions & 6 deletions internal/service/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type DashboardsApi interface {
func (s *DashNGoImpl) getDashboardByUid(uid string) (*models.DashboardFullWithMeta, error) {
params := dashboards.NewGetDashboardByUIDParams()
params.UID = uid
data, err := s.officialClient.Dashboards.GetDashboardByUID(params, s.getAuth())
data, err := s.client.Dashboards.GetDashboardByUID(params, s.getAuth())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func (s *DashNGoImpl) ListDashboards(filterReq filters.Filter) []*models.Hit {
searchParams.Page = tools.PtrOf(int64(page))
searchParams.Type = tools.PtrOf(searchTypeDashboard)

pageBoardLinks, err := s.officialClient.Search.Search(searchParams, s.getAuth())
pageBoardLinks, err := s.client.Search.Search(searchParams, s.getAuth())
if err != nil {
log.Fatal("Failed to retrieve dashboards", err)
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (s *DashNGoImpl) DownloadDashboards(filter filters.Filter) []string {
dp := dashboards.NewGetDashboardByUIDParams()
dp.UID = link.UID

if metaData, err = s.officialClient.Dashboards.GetDashboardByUID(dp, s.getAuth()); err != nil {
if metaData, err = s.client.Dashboards.GetDashboardByUID(dp, s.getAuth()); err != nil {
log.Errorf("%s for %s\n", err, link.URI)
continue
}
Expand Down Expand Up @@ -226,7 +226,7 @@ func (s *DashNGoImpl) createdFolder(folderName string) (int64, error) {
createdFolderRequest.Body = &models.CreateFolderCommand{
Title: folderName,
}
folder, err := s.officialClient.Folders.CreateFolder(createdFolderRequest, s.getAuth())
folder, err := s.client.Folders.CreateFolder(createdFolderRequest, s.getAuth())
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -328,7 +328,7 @@ func (s *DashNGoImpl) UploadDashboards(filterReq filters.Filter) {
Dashboard: data,
}

if _, exportError := s.officialClient.Dashboards.ImportDashboard(importDashReq, s.getAuth()); exportError != nil {
if _, exportError := s.client.Dashboards.ImportDashboard(importDashReq, s.getAuth()); exportError != nil {
log.WithError(err).Printf("error on Exporting dashboard %s", file)
continue
}
Expand All @@ -346,7 +346,7 @@ func (s *DashNGoImpl) DeleteAllDashboards(filter filters.Filter) []string {
if filter.ValidateAll(map[filters.FilterType]string{filters.FolderFilter: item.FolderTitle, filters.DashFilter: item.Slug}) {
dp := dashboards.NewDeleteDashboardByUIDParams()
dp.UID = item.UID
_, err := s.officialClient.Dashboards.DeleteDashboardByUID(dp, s.getAuth())
_, err := s.client.Dashboards.DeleteDashboardByUID(dp, s.getAuth())
if err == nil {
dashboardListing = append(dashboardListing, item.Title)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/service/folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *DashNGoImpl) UploadFolderPermissions(filter filters.Filter) []string {
p := folder_permissions.NewUpdateFolderPermissionsParams()
p.FolderUID = uid.String()
p.Body = payload
_, err := s.officialClient.FolderPermissions.UpdateFolderPermissions(p, s.getAuth())
_, err := s.client.FolderPermissions.UpdateFolderPermissions(p, s.getAuth())
if err != nil {
log.Errorf("Failed to update folder permissions")
} else {
Expand All @@ -139,7 +139,7 @@ func (s *DashNGoImpl) ListFolderPermissions(filter filters.Filter) map[*models.H
for ndx, foldersEntry := range foldersList {
p := folder_permissions.NewGetFolderPermissionListParams()
p.FolderUID = foldersEntry.UID
results, err := s.officialClient.FolderPermissions.GetFolderPermissionList(p, s.getAuth())
results, err := s.client.FolderPermissions.GetFolderPermissionList(p, s.getAuth())
if err != nil {
msg := fmt.Sprintf("Unable to get folder permissions for folderUID: %s", p.FolderUID)

Expand Down Expand Up @@ -169,7 +169,7 @@ func (s *DashNGoImpl) ListFolder(filter filters.Filter) []*models.Hit {
}
p := search.NewSearchParams()
p.Type = &searchTypeFolder
folderListing, err := s.officialClient.Search.Search(p, s.getAuth())
folderListing, err := s.client.Search.Search(p, s.getAuth())
folderListing.GetPayload()
if err != nil {
log.Fatal("unable to retrieve folder list.")
Expand Down Expand Up @@ -265,7 +265,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.officialClient.Folders.CreateFolder(params, s.getAuth())
f, err := s.client.Folders.CreateFolder(params, s.getAuth())
if err != nil {
log.Errorf("failed to create folder %s", newFolder.Title)
continue
Expand All @@ -283,7 +283,7 @@ func (s *DashNGoImpl) DeleteAllFolders(filter filters.Filter) []string {
for _, folder := range folderListing {
params := folders.NewDeleteFolderParams()
params.FolderUID = folder.UID
_, err := s.officialClient.Folders.DeleteFolder(params, s.getAuth())
_, err := s.client.Folders.DeleteFolder(params, s.getAuth())
if err == nil {
result = append(result, folder.Title)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/service/libraryelements.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
func (s *DashNGoImpl) ListLibraryElementsConnections(filter filters.Filter, connectionID string) []*models.DashboardFullWithMeta {
params := library_elements.NewGetLibraryElementConnectionsParams()
params.SetLibraryElementUID(connectionID)
payload, err := s.officialClient.LibraryElements.GetLibraryElementConnections(params, s.getAuth())
payload, err := s.client.LibraryElements.GetLibraryElementConnections(params, s.getAuth())
if err != nil {
log.Fatalf("unable to retrieve a valid connection for %s", connectionID)
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (s *DashNGoImpl) ListLibraryElements(filter filters.Filter) []*models.Libra
params := library_elements.NewGetLibraryElementsParams()
params.FolderFilter = &folderList
params.Kind = tools.PtrOf(listLibraryPanels)
libraryElements, err := s.officialClient.LibraryElements.GetLibraryElements(params, s.getAuth())
libraryElements, err := s.client.LibraryElements.GetLibraryElements(params, s.getAuth())
if err != nil {
log.WithError(err).Fatal("Unable to list Library Elements")

Expand Down Expand Up @@ -180,7 +180,7 @@ func (s *DashNGoImpl) UploadLibraryElements(filter filters.Filter) []string {

params := library_elements.NewCreateLibraryElementParams()
params.Body = &newLibraryRequest
entity, err := s.officialClient.LibraryElements.CreateLibraryElement(params, s.getAuth())
entity, err := s.client.LibraryElements.CreateLibraryElement(params, s.getAuth())
if err != nil {
log.WithError(err).Errorf("Failed to create library element")
} else {
Expand All @@ -199,7 +199,7 @@ func (s *DashNGoImpl) DeleteAllLibraryElements(filter filters.Filter) []string {

params := library_elements.NewDeleteLibraryElementByUIDParams()
params.SetLibraryElementUID(element.UID)
_, err := s.officialClient.LibraryElements.DeleteLibraryElementByUID(params, s.getAuth())
_, err := s.client.LibraryElements.DeleteLibraryElementByUID(params, s.getAuth())
if err != nil {
var logEntry *log.Entry
if serr, ok := err.(*library_elements.DeleteLibraryElementByUIDForbidden); ok {
Expand Down
13 changes: 6 additions & 7 deletions internal/service/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ func (s *DashNGoImpl) Login() {
log.Fatal("invalid Grafana URL")
}
var clientTransport *http.Transport
httpClient := &http.Client{}
httpTransportCfg := client.TransportConfig{
Host: u.Host,
BasePath: "/api",
Schemes: []string{u.Scheme},
NumRetries: 3,
Host: u.Host,
BasePath: "/api",
Schemes: []string{u.Scheme},
//NumRetries: 3,
}

if config.Config().IgnoreSSL() {
httpClient, clientTransport = ignoreSSLErrors()
_, clientTransport = ignoreSSLErrors()
httpTransportCfg.TLSConfig = clientTransport.TLSClientConfig
}
if s.grafanaConf.UserName != "" && s.grafanaConf.Password != "" {
Expand All @@ -51,7 +50,7 @@ func (s *DashNGoImpl) Login() {
if s.grafanaConf.OrganizationId != 0 {
httpTransportCfg.OrgID = s.grafanaConf.OrganizationId
}
s.officialClient = client.NewHTTPClientWithConfig(strfmt.Default, &httpTransportCfg)
s.client = client.NewHTTPClientWithConfig(strfmt.Default, &httpTransportCfg)

userInfo, err := s.GetUserInfo()
//Sets state based on user permissions
Expand Down
24 changes: 12 additions & 12 deletions internal/service/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *DashNGoImpl) InitOrganizations() {
func (s *DashNGoImpl) getOrganization(id int64) (*models.OrgDetailsDTO, error) {
params := orgs.NewGetOrgByIDParams()
params.OrgID = id
data, err := s.officialClient.Orgs.GetOrgByID(params, s.getAuth())
data, err := s.client.Orgs.GetOrgByID(params, s.getAuth())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func (s *DashNGoImpl) ListOrganizations() []*models.OrgDTO {
return nil
}

orgList, err := s.officialClient.Orgs.SearchOrgs(orgs.NewSearchOrgsParams(), s.getGrafanaAdminAuth())
orgList, err := s.client.Orgs.SearchOrgs(orgs.NewSearchOrgsParams(), s.getGrafanaAdminAuth())
if err != nil {
var swaggerErr *orgs.SearchOrgsForbidden
msg := "Cannot retrieve Orgs, you need additional permissions"
Expand Down Expand Up @@ -189,7 +189,7 @@ func (s *DashNGoImpl) UploadOrganizations() []string {

params := orgs.NewCreateOrgParams()
params.Body = &newOrg
_, err = s.officialClient.Orgs.CreateOrg(params, s.getBasicAuth())
_, err = s.client.Orgs.CreateOrg(params, s.getBasicAuth())
if err != nil {
log.Errorf("failed to create folder %s", newOrg.Name)
continue
Expand All @@ -209,7 +209,7 @@ func (s *DashNGoImpl) SwitchOrganization(id int64) error {
valid := false
if id > 1 {
var orgsPayload []*models.OrgDTO
orgList, err := s.officialClient.Orgs.SearchOrgs(orgs.NewSearchOrgsParams(), s.getBasicAuth())
orgList, err := s.client.Orgs.SearchOrgs(orgs.NewSearchOrgsParams(), s.getBasicAuth())
if err != nil {
log.Warn("Error fetch organizations requires (SuperAdmin Basic Auth), assuming valid ID was requested. Cannot validate OrgId")
valid = true
Expand Down Expand Up @@ -239,7 +239,7 @@ func (s *DashNGoImpl) SwitchOrganization(id int64) error {

params := signed_in_user.NewUserSetUsingOrgParams()
params.OrgID = id
status, err := s.officialClient.SignedInUser.UserSetUsingOrg(params, s.getBasicAuth())
status, err := s.client.SignedInUser.UserSetUsingOrg(params, s.getBasicAuth())
if err != nil {
log.WithError(err).Fatalf("%s for %v\n", err, status)
return err
Expand All @@ -261,7 +261,7 @@ func (s *DashNGoImpl) GetTokenOrganization() *models.OrgDetailsDTO {
// getAssociatedActiveOrg returns the Org associated with the given authentication mechanism.
func (s *DashNGoImpl) getAssociatedActiveOrg(auth runtime.ClientAuthInfoWriter) *models.OrgDetailsDTO {
p := org.NewGetCurrentOrgParams()
payload, err := s.officialClient.Org.GetCurrentOrg(p, auth)
payload, err := s.client.Org.GetCurrentOrg(p, auth)
if err != nil {
log.WithError(err).Fatal("Unable to retrieve current organization")
}
Expand All @@ -271,7 +271,7 @@ func (s *DashNGoImpl) getAssociatedActiveOrg(auth runtime.ClientAuthInfoWriter)
func (s *DashNGoImpl) SetUserOrganizations(id int64) error {
p := signed_in_user.NewUserSetUsingOrgParams()
p.OrgID = id
payload, err := s.officialClient.SignedInUser.UserSetUsingOrg(p, s.getBasicAuth())
payload, err := s.client.SignedInUser.UserSetUsingOrg(p, s.getBasicAuth())
if err == nil {
log.Debugf(payload.GetPayload().Message)
}
Expand All @@ -281,14 +281,14 @@ func (s *DashNGoImpl) SetUserOrganizations(id int64) error {
func (s *DashNGoImpl) UpdateCurrentOrganization(name string) error {
p := org.NewUpdateCurrentOrgParams()
p.Body = &models.UpdateOrgForm{Name: name}
_, err := s.officialClient.Org.UpdateCurrentOrg(p, s.getAuth())
_, err := s.client.Org.UpdateCurrentOrg(p, s.getAuth())
return err
}

func (s *DashNGoImpl) ListOrgUsers(orgId int64) []*models.OrgUserDTO {
p := orgs.NewGetOrgUsersParams()
p.OrgID = orgId
resp, err := s.officialClient.Orgs.GetOrgUsers(p, s.getGrafanaAdminAuth())
resp, err := s.client.Orgs.GetOrgUsers(p, s.getGrafanaAdminAuth())
if err != nil {
log.WithError(err).Fatal("failed to get org users")
}
Expand All @@ -306,15 +306,15 @@ func (s *DashNGoImpl) AddUserToOrg(role string, userId, orgId int64) error {
LoginOrEmail: userInfo.Login,
Role: role,
}
_, err = s.officialClient.Orgs.AddOrgUser(p, s.getGrafanaAdminAuth())
_, err = s.client.Orgs.AddOrgUser(p, s.getGrafanaAdminAuth())
return err
}

func (s *DashNGoImpl) DeleteUserFromOrg(userId, orgId int64) error {
p := orgs.NewRemoveOrgUserParams()
p.OrgID = orgId
p.UserID = userId
_, err := s.officialClient.Orgs.RemoveOrgUser(p, s.getGrafanaAdminAuth())
_, err := s.client.Orgs.RemoveOrgUser(p, s.getGrafanaAdminAuth())
return err
}

Expand All @@ -325,6 +325,6 @@ func (s *DashNGoImpl) UpdateUserInOrg(role string, userId, orgId int64) error {
p.Body = &models.UpdateOrgUserCommand{
Role: role,
}
_, err := s.officialClient.Orgs.UpdateOrgUser(p, s.getGrafanaAdminAuth())
_, err := s.client.Orgs.UpdateOrgUser(p, s.getGrafanaAdminAuth())
return err
}
Loading

0 comments on commit 56bfe7f

Please sign in to comment.