Skip to content

Commit

Permalink
error instead of forcing empty value
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Dec 4, 2024
1 parent 4bbd510 commit 96448a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 11 additions & 4 deletions apstra/api_iba_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ func (o *Client) getIbaDashboardByLabel(ctx context.Context, blueprintId ObjectI
func (o *Client) createIbaDashboard(ctx context.Context, blueprintId ObjectId, in *IbaDashboardData) (ObjectId, error) {
var response objectIdResponse
if in.UpdatedBy != "" {
return "", errors.New("UpdatedBy is set by Apstra")
return "", errors.New("attempt to create dashboard with non-empty updated_by value - this value can be set only by the server")
}
if in.PredefinedDashboard != "" {
return "", errors.New("to instantiate predefined dashboard, please use InstantiatePredefinedDashboard")
return "", errors.New("attempt to create dashboard with non-empty predefined_dashboard value - this value can " +
"be set only by the server, and only when a dashboard is instantiated from a predefined template")
}
err := o.talkToApstra(ctx, &talkToApstraIn{
method: http.MethodPost,
Expand Down Expand Up @@ -251,8 +252,14 @@ func (o *Client) createIbaDashboard(ctx context.Context, blueprintId ObjectId, i
}

func (o *Client) updateIbaDashboard(ctx context.Context, blueprintId ObjectId, id ObjectId, in *IbaDashboardData) error {
in.UpdatedBy = ""
in.PredefinedDashboard = ""
if in.UpdatedBy != "" {
return errors.New("attempt to update dashboard with non-empty updated_by value - this value can be set only by the server")
}
if in.PredefinedDashboard != "" {
return errors.New("attempt to update dashboard with non-empty predefined_dashboard value - this value can " +
"be set only by the server, and only when a dashboard is instantiated from a predefined template")
}

err := o.talkToApstra(ctx, &talkToApstraIn{
method: http.MethodPut, urlStr: fmt.Sprintf(apiUrlIbaDashboardsById, blueprintId, id), apiInput: in,
})
Expand Down
3 changes: 0 additions & 3 deletions apstra/api_iba_dashboards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ func TestCreateReadUpdateDeleteIbaDashboards(t *testing.T) {
}

id, err := bpClient.InstantiateIbaPredefinedDashboard(ctx, d, d.String())
if err != nil {
t.Log(err)
}
require.NoError(t, err)

t.Logf("Name :%s Created Id :%s", d, id)
Expand Down

0 comments on commit 96448a7

Please sign in to comment.