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

STAC-0: add locked parameter to import api #88

Merged
merged 2 commits into from
Oct 4, 2024
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 cmd/settings/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const (
AllowReferencesFlag = "allowed-namespace-refs"
NamespaceFlag = "namespace"
UnlockedStrategyFlag = "unlocked-strategy"
LockedStrategyFlag = "locked-strategy"
TimeoutFlag = "timeout"
TimeoutFlagShort = "t"
UnlockFlag = "unlock"

TimeoutUsage = "Timeout in seconds"

Expand Down
5 changes: 4 additions & 1 deletion cmd/settings/impex.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ func DoExport(ctx context.Context, api *stackstate_api.APIClient, ids []int64, n
return api.ExportApi.ExportSettings(ctx).Export(*exportArgs).Execute()
}

func doImport(ctx context.Context, api *stackstate_api.APIClient, body string, namespace string, unlockedStrategy string, timeout int64) ([]map[string]interface{}, *http.Response, error) {
func doImport(ctx context.Context, api *stackstate_api.APIClient, body string, namespace string, unlockedStrategy string, lockedStrategy string, timeout int64) ([]map[string]interface{}, *http.Response, error) {
request := api.ImportApi.ImportSettings(ctx).Body(body)
if namespace != "" {
request = request.Namespace(namespace)
}
if unlockedStrategy != "" {
request = request.Unlocked(unlockedStrategy)
}
if lockedStrategy != "" {
request = request.Locked(lockedStrategy)
}
if timeout > 0 {
request = request.TimeoutSeconds(timeout)
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/settings/settings_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import (

var (
UnlockedStrategyChoices = []string{"fail", "skip", "overwrite"}
LockedStrategyChoices = []string{"fail", "skip", "overwrite"}
)

type ApplyArgs struct {
Filepath string
Namespace string
UnlockedStrategy string
LockedStrategy string
Timeout int64
}

Expand All @@ -41,6 +43,12 @@ func SettingsApplyCommand(cli *di.Deps) *cobra.Command {
UnlockedStrategyChoices,
"Strategy to use when encountering unlocked settings when applying settings to a namespace"+
fmt.Sprintf(" (must be { %s })", strings.Join(UnlockedStrategyChoices, " | ")))
pflags.EnumVar(cmd.Flags(), &args.LockedStrategy,
LockedStrategyFlag,
"",
LockedStrategyChoices,
"Strategy to use when encountering locked settings"+
fmt.Sprintf(" (must be { %s })", strings.Join(LockedStrategyChoices, " | ")))
cmd.Flags().Int64VarP(&args.Timeout, TimeoutFlag, TimeoutFlagShort, 0, TimeoutUsage)

return cmd
Expand All @@ -53,7 +61,7 @@ func RunSettingsApplyCommand(args *ApplyArgs) di.CmdWithApiFn {
return common.NewReadFileError(err, args.Filepath)
}

nodes, resp, err := doImport(cli.Context, api, string(fileBytes), args.Namespace, args.UnlockedStrategy, args.Timeout)
nodes, resp, err := doImport(cli.Context, api, string(fileBytes), args.Namespace, args.UnlockedStrategy, args.LockedStrategy, args.Timeout)
if err != nil {
return common.NewResponseError(err, resp)
}
Expand Down
18 changes: 8 additions & 10 deletions cmd/settings/settings_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type EditArgs struct {
NodeTypes []string
AllowReferences []string
UnlockedStrategy string
LockedStrategy string
Timeout int64
Unlock bool
}

func SettingsEditCommand(cli *di.Deps) *cobra.Command {
Expand All @@ -48,9 +48,14 @@ func SettingsEditCommand(cli *di.Deps) *cobra.Command {
UnlockedStrategyChoices,
"Strategy to use when encountering unlocked settings when applying settings to a namespace"+
fmt.Sprintf(" (must be { %s })", strings.Join(UnlockedStrategyChoices, " | ")))
pflags.EnumVar(cmd.Flags(), &args.LockedStrategy,
LockedStrategyFlag,
"",
LockedStrategyChoices,
"Strategy to use when encountering locked settings"+
fmt.Sprintf(" (must be { %s })", strings.Join(LockedStrategyChoices, " | ")))
cmd.Flags().Int64VarP(&args.Timeout, TimeoutFlag, "t", 0, "Timeout in seconds")
stscobra.MarkMutexFlags(cmd, []string{IdsFlag, TypeNameFlag}, "filter", true)
cmd.Flags().BoolVar(&args.Unlock, UnlockFlag, false, "Unlocks the settings node before saving if needed")

return cmd
}
Expand Down Expand Up @@ -81,14 +86,7 @@ func RunSettingsEditCommand(args *EditArgs) di.CmdWithApiFn {
return nil
}

if args.Unlock {
err := UnlockNodes(cli, api, args.Ids, WildCardType)
if err != nil {
return err
}
}

nodes, resp, err := doImport(cli.Context, api, string(c), "", args.UnlockedStrategy, args.Timeout)
nodes, resp, err := doImport(cli.Context, api, string(c), "", args.UnlockedStrategy, args.LockedStrategy, args.Timeout)
rb3ckers marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return common.NewResponseError(err, resp)
}
Expand Down
11 changes: 0 additions & 11 deletions cmd/settings/settings_edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,5 @@ func TestShouldEditSettings(t *testing.T) {
cli.MockClient.ApiMocks.ExportApi.ExportSettingsResponse.Result = "Hello"
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--ids", "1234")

assert.Len(t, *cli.MockClient.ApiMocks.NodeApi.UnlockCalls, 0)
assert.Equal(t, *(*cli.MockClient.ApiMocks.ImportApi.ImportSettingsCalls)[0].Pbody, "olleH")
}

func TestShouldEditWithUnlock(t *testing.T) {
cli, cmd := setupEditCmd(t)
cli.MockClient.ApiMocks.ExportApi.ExportSettingsResponse.Response = &http.Response{Body: io.NopCloser(strings.NewReader("Hello"))}
cli.MockClient.ApiMocks.ExportApi.ExportSettingsResponse.Result = "Hello"
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--ids", "1234,2345,3456", "--unlock")

assert.Len(t, *cli.MockClient.ApiMocks.NodeApi.UnlockCalls, 3)
assert.Equal(t, *(*cli.MockClient.ApiMocks.ImportApi.ImportSettingsCalls)[0].Pbody, "olleH")
}
2 changes: 1 addition & 1 deletion generated/stackstate_admin_api/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.1
6.1.0
14 changes: 8 additions & 6 deletions generated/stackstate_api/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,10 @@ docs/SpanFilter.md
docs/SpanKind.md
docs/SpanLink.md
docs/SpanParentType.md
docs/SpanQuery.md
docs/SpanSortDirection.md
docs/SpanSortField.md
docs/SpanSortOption.md
docs/SpanSuggestionField.md
docs/SpanSummary.md
docs/Spans.md
docs/StackElementNotFound.md
docs/StackPack.md
docs/StackPackConfiguration.md
Expand Down Expand Up @@ -387,6 +384,10 @@ docs/TraceApiInvalidTimeRange.md
docs/TraceApiSpanNotFound.md
docs/TraceApiSpansBadRequest.md
docs/TraceApiTraceNotFound.md
docs/TraceFilter.md
docs/TraceIdentifier.md
docs/TraceQuery.md
docs/Traces.md
docs/TracesApi.md
docs/UnlicensedSubscription.md
docs/UnmatchedCheckState.md
Expand Down Expand Up @@ -670,13 +671,10 @@ model_span_filter.go
model_span_kind.go
model_span_link.go
model_span_parent_type.go
model_span_query.go
model_span_sort_direction.go
model_span_sort_field.go
model_span_sort_option.go
model_span_suggestion_field.go
model_span_summary.go
model_spans.go
model_stack_element_not_found.go
model_stack_pack.go
model_stack_pack_configuration.go
Expand Down Expand Up @@ -724,6 +722,10 @@ model_trace_api_invalid_time_range.go
model_trace_api_span_not_found.go
model_trace_api_spans_bad_request.go
model_trace_api_trace_not_found.go
model_trace_filter.go
model_trace_identifier.go
model_trace_query.go
model_traces.go
model_unlicensed_subscription.go
model_unmatched_check_state.go
model_user_name_mismatch_error.go
Expand Down
11 changes: 6 additions & 5 deletions generated/stackstate_api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ Class | Method | HTTP request | Description
*TopologySynchronizationApi* | [**PostTopologySynchronizationStreamClearErrors**](docs/TopologySynchronizationApi.md#posttopologysynchronizationstreamclearerrors) | **Post** /synchronization/topology/streams/clearErrors | Clear all the errors related to a specific sync
*TracesApi* | [**GetSpan**](docs/TracesApi.md#getspan) | **Get** /traces/{traceId}/spans/{spanId} | Get a span
*TracesApi* | [**GetTrace**](docs/TracesApi.md#gettrace) | **Get** /traces/{traceId} | Fetch a trace
*TracesApi* | [**QueryDuration**](docs/TracesApi.md#queryduration) | **Post** /traces/spans/duration/histogram | Query duration distribution
*TracesApi* | [**QuerySpans**](docs/TracesApi.md#queryspans) | **Post** /traces/spans | Query for spans
*TracesApi* | [**QueryDuration**](docs/TracesApi.md#queryduration) | **Post** /traces/duration/histogram | Query duration distribution
*TracesApi* | [**QueryTraces**](docs/TracesApi.md#querytraces) | **Post** /traces/query | Query for traces
*TracesApi* | [**SpanComponents**](docs/TracesApi.md#spancomponents) | **Post** /traces/components | Fetch components based on resource attributes
*TracesApi* | [**SuggestionsAttributeName**](docs/TracesApi.md#suggestionsattributename) | **Get** /traces/spans/fields/attributes | Suggestions for attribute names
*TracesApi* | [**SuggestionsAttributeValue**](docs/TracesApi.md#suggestionsattributevalue) | **Get** /traces/spans/fields/attributes/{attributeName}/values | Suggestions for attribute values
Expand Down Expand Up @@ -499,13 +499,10 @@ Class | Method | HTTP request | Description
- [SpanKind](docs/SpanKind.md)
- [SpanLink](docs/SpanLink.md)
- [SpanParentType](docs/SpanParentType.md)
- [SpanQuery](docs/SpanQuery.md)
- [SpanSortDirection](docs/SpanSortDirection.md)
- [SpanSortField](docs/SpanSortField.md)
- [SpanSortOption](docs/SpanSortOption.md)
- [SpanSuggestionField](docs/SpanSuggestionField.md)
- [SpanSummary](docs/SpanSummary.md)
- [Spans](docs/Spans.md)
- [StackElementNotFound](docs/StackElementNotFound.md)
- [StackPack](docs/StackPack.md)
- [StackPackConfiguration](docs/StackPackConfiguration.md)
Expand Down Expand Up @@ -553,6 +550,10 @@ Class | Method | HTTP request | Description
- [TraceApiSpanNotFound](docs/TraceApiSpanNotFound.md)
- [TraceApiSpansBadRequest](docs/TraceApiSpansBadRequest.md)
- [TraceApiTraceNotFound](docs/TraceApiTraceNotFound.md)
- [TraceFilter](docs/TraceFilter.md)
- [TraceIdentifier](docs/TraceIdentifier.md)
- [TraceQuery](docs/TraceQuery.md)
- [Traces](docs/Traces.md)
- [UnlicensedSubscription](docs/UnlicensedSubscription.md)
- [UnmatchedCheckState](docs/UnmatchedCheckState.md)
- [UserNameMismatchError](docs/UserNameMismatchError.md)
Expand Down
Loading
Loading