Skip to content

feat(cockpit): add update datasource method #2132

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

Merged
merged 1 commit into from
Jul 4, 2024
Merged
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
48 changes: 48 additions & 0 deletions api/cockpit/v1/cockpit_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,18 @@ type RegionalAPITriggerTestAlertRequest struct {
ProjectID string `json:"project_id"`
}

// RegionalAPIUpdateDataSourceRequest: Update a data source name.
type RegionalAPIUpdateDataSourceRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Region scw.Region `json:"-"`

// DataSourceID: ID of the data source to update.
DataSourceID string `json:"-"`

// Name: updated name of the data source.
Name *string `json:"name,omitempty"`
}

// UsageOverview: usage overview.
type UsageOverview struct {
ScalewayMetricsUsage *Usage `json:"scaleway_metrics_usage"`
Expand Down Expand Up @@ -1790,6 +1802,42 @@ func (s *RegionalAPI) ListDataSources(req *RegionalAPIListDataSourcesRequest, op
return &resp, nil
}

// UpdateDataSource: Update a given data source name, specified by the data source ID.
func (s *RegionalAPI) UpdateDataSource(req *RegionalAPIUpdateDataSourceRequest, opts ...scw.RequestOption) (*DataSource, error) {
var err error

if req.Region == "" {
defaultRegion, _ := s.client.GetDefaultRegion()
req.Region = defaultRegion
}

if fmt.Sprint(req.Region) == "" {
return nil, errors.New("field Region cannot be empty in request")
}

if fmt.Sprint(req.DataSourceID) == "" {
return nil, errors.New("field DataSourceID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "PATCH",
Path: "/cockpit/v1/regions/" + fmt.Sprint(req.Region) + "/data-sources/" + fmt.Sprint(req.DataSourceID) + "",
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp DataSource

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// GetUsageOverview: Retrieve the data source usage overview per type for the specified Project.
func (s *RegionalAPI) GetUsageOverview(req *RegionalAPIGetUsageOverviewRequest, opts ...scw.RequestOption) (*UsageOverview, error) {
var err error
Expand Down
Loading