Skip to content
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
4 changes: 1 addition & 3 deletions cmd/rbac/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ const (
"For example, if your scope is \"label = 'A'\", then all STQL executed in StackState" +
" (e.g. Retrieving topology) will only return elements that have the label A"

DefaultResource = "system"
DefaultScope = "id = '-1'"
DefaultSTQLVersion = "0.0.1"
DefaultResource = "system"
)
9 changes: 7 additions & 2 deletions cmd/rbac/rbac_create_subject.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:dupl
package rbac

import (
Expand All @@ -24,7 +25,7 @@ func CreateSubjectCommand(deps *di.Deps) *cobra.Command {
cmd.Flags().StringVar(&args.Subject, Subject, "", SubjectUsage)
cmd.MarkFlagRequired(Subject) //nolint:errcheck

cmd.Flags().StringVar(&args.Scope, Scope, DefaultScope, ScopeUsage)
cmd.Flags().StringVar(&args.Scope, Scope, "", ScopeUsage)

return cmd
}
Expand All @@ -36,7 +37,11 @@ func RunCreateSubjectCommand(args *CreateSubjectArgs) di.CmdWithApiFn {
api *stackstate_api.APIClient,
serverInfo *stackstate_api.ServerInfo,
) common.CLIError {
subject := stackstate_api.NewCreateSubject(args.Scope, DefaultSTQLVersion)
subject := stackstate_api.NewCreateSubject()
if args.Scope != "" {
subject.SetQuery(args.Scope)
}

resp, err := api.SubjectApi.CreateSubject(cli.Context, args.Subject).
CreateSubject(*subject).
Execute()
Expand Down
7 changes: 3 additions & 4 deletions cmd/rbac/rbac_create_subject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func TestCreateSubjectJson(t *testing.T) {
assert.Len(t, calls, 1)
assert.Equal(t, SomeSubject, calls[0].Psubject)

expectedSubject := stackstate_api.NewCreateSubject(DefaultScope, DefaultSTQLVersion)

expectedSubject := stackstate_api.NewCreateSubject()
assert.Equal(t, expectedSubject, calls[0].PcreateSubject)

expectedJson := []map[string]interface{}{
Expand All @@ -47,8 +46,8 @@ func TestCreateSubject(t *testing.T) {
assert.Len(t, calls, 1)
assert.Equal(t, SomeOtherSubject, calls[0].Psubject)

otherExpectedSubject := stackstate_api.NewCreateSubject(SomeScope, DefaultSTQLVersion)

otherExpectedSubject := stackstate_api.NewCreateSubject()
otherExpectedSubject.SetQuery(SomeScope)
assert.Equal(t, otherExpectedSubject, calls[0].PcreateSubject)

expectedStrings := []string{
Expand Down
1 change: 1 addition & 0 deletions cmd/rbac/rbac_delete_subject.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:dupl
package rbac

import (
Expand Down
17 changes: 4 additions & 13 deletions cmd/rbac/rbac_describe_subjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ func RunDescribeSubjectsCommand(args *DescribeSubjectsArgs) di.CmdWithApiFn {

if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"handle": subject.Handle,
"scopeQuery": safeDeref(subject.ScopeQuery),
"handle": subject.Handle,
})
} else {
cli.Printer.Table(printer.TableData{
Header: []string{"Subject", "Scope Query"},
Header: []string{"Subject"},
Data: [][]interface{}{
{
subject.Handle,
safeDeref(subject.ScopeQuery),
},
},
MissingTableDataMsg: printer.NotFoundMsg{Types: "matching subjects"},
Expand All @@ -72,11 +70,11 @@ func RunDescribeSubjectsCommand(args *DescribeSubjectsArgs) di.CmdWithApiFn {
data := make([][]interface{}, 0)

for _, subject := range subjects {
data = append(data, []interface{}{subject.Handle, safeDeref(subject.ScopeQuery)})
data = append(data, []interface{}{subject.Handle})
}

cli.Printer.Table(printer.TableData{
Header: []string{"Subject", "Scope Query"},
Header: []string{"Subject"},
Data: data,
MissingTableDataMsg: printer.NotFoundMsg{Types: "subjects"},
})
Expand All @@ -85,10 +83,3 @@ func RunDescribeSubjectsCommand(args *DescribeSubjectsArgs) di.CmdWithApiFn {
return nil
}
}

func safeDeref(text *string) string {
if text == nil {
return ""
}
return *text
}
28 changes: 11 additions & 17 deletions cmd/rbac/rbac_describe_subjects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ import (
var (
SomeScopeVar = SomeScope
SubjectConfig1 = stackstate_api.SubjectConfig{
Handle: SomeSubject,
ScopeQuery: &SomeScopeVar,
Handle: SomeSubject,
}

SomeOtherSubject = "handle"
SomeOtherScope = "meaningOfLife = 23"

SubjectConfig2 = stackstate_api.SubjectConfig{
Handle: SomeOtherSubject,
ScopeQuery: &SomeOtherScope,
Handle: SomeOtherSubject,
}

SubjectConfig3 = stackstate_api.SubjectConfig{
Handle: SubjectHandle,
ScopeQuery: nil,
Handle: SubjectHandle,
}
)

Expand All @@ -47,11 +43,11 @@ func TestDescribeSubjectsTable(t *testing.T) {

expected := []printer.TableData{
{
Header: []string{"Subject", "Scope Query"},
Header: []string{"Subject"},
Data: [][]interface{}{
{SubjectConfig1.Handle, *SubjectConfig1.ScopeQuery},
{SubjectConfig2.Handle, *SubjectConfig2.ScopeQuery},
{SubjectConfig3.Handle, ""},
{SubjectConfig1.Handle},
{SubjectConfig2.Handle},
{SubjectConfig3.Handle},
},
MissingTableDataMsg: printer.NotFoundMsg{Types: "subjects"},
},
Expand Down Expand Up @@ -100,9 +96,9 @@ func TestDescribeSubjectsTableWithFilter(t *testing.T) {

expected := []printer.TableData{
{
Header: []string{"Subject", "Scope Query"},
Header: []string{"Subject"},
Data: [][]interface{}{
{SubjectConfig1.Handle, *SubjectConfig1.ScopeQuery},
{SubjectConfig1.Handle},
},
MissingTableDataMsg: printer.NotFoundMsg{Types: "matching subjects"},
},
Expand Down Expand Up @@ -130,12 +126,10 @@ func TestDescribeSubjectsJsonWithFilter(t *testing.T) {

expectedJson := []map[string]interface{}{
{
"handle": SubjectConfig1.Handle,
"scopeQuery": *SubjectConfig1.ScopeQuery,
"handle": SubjectConfig1.Handle,
},
{
"handle": SubjectConfig3.Handle,
"scopeQuery": "",
"handle": SubjectConfig3.Handle,
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/rbac/rbac_revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func RunRevokePermissionsCommand(args *RevokePermissionsArgs) di.CmdWithApiFn {
return common.NewResponseError(revokeErr, revokeResp)
}

description, descrResp, descrErr := describePermissions(cli, api, args.Subject, args.Permission, args.Resource).Execute()
description, descrResp, descrErr := describePermissions(cli, api, args.Subject, args.Permission, "").Execute()

if descrErr != nil {
return common.NewResponseError(descrErr, descrResp)
Expand Down
2 changes: 0 additions & 2 deletions cmd/rbac/rbac_revoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestRevokePermissions(t *testing.T) {
assert.Len(t, describeCalls, 1)
assert.Equal(t, SomeSubject, describeCalls[0].Psubject)
assert.Equal(t, SomePermission, *describeCalls[0].Ppermission)
assert.Equal(t, "system", *describeCalls[0].Presource)

di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--subject", SomeSubject, "--permission", SomePermission, "--resource", SomeResource)

Expand All @@ -40,7 +39,6 @@ func TestRevokePermissions(t *testing.T) {
assert.Len(t, describeCalls, 2)
assert.Equal(t, SomeSubject, describeCalls[1].Psubject)
assert.Equal(t, SomePermission, *describeCalls[1].Ppermission)
assert.Equal(t, SomeResource, *describeCalls[1].Presource)

expectedResult := []printer.TableData{
ExpectedTable,
Expand Down
112 changes: 108 additions & 4 deletions generated/stackstate_api/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ api_agent_registrations.go
api_api_token.go
api_authorize_ingestion_api_key.go
api_component.go
api_dashboards.go
api_dummy.go
api_event.go
api_export.go
Expand Down Expand Up @@ -85,6 +86,23 @@ docs/ComponentNotFoundError.md
docs/ComponentQuery.md
docs/ComponentViewArguments.md
docs/CreateSubject.md
docs/DashboardAuthorizationError.md
docs/DashboardClientErrors.md
docs/DashboardCloneSchema.md
docs/DashboardInvalidIdentifierError.md
docs/DashboardList.md
docs/DashboardNotFoundError.md
docs/DashboardPatchSchema.md
docs/DashboardReadBaseSchema.md
docs/DashboardReadFullSchema.md
docs/DashboardReadFullSchemaAllOf.md
docs/DashboardReadMetadataSchema.md
docs/DashboardReadMetadataSchemaAllOf.md
docs/DashboardReadSchema.md
docs/DashboardScope.md
docs/DashboardValidationError.md
docs/DashboardWriteSchema.md
docs/DashboardsApi.md
docs/DataUnavailable.md
docs/DependencyDirection.md
docs/DummyApi.md
Expand Down Expand Up @@ -278,10 +296,42 @@ docs/OpsgenieChannelRefId.md
docs/OpsgenieChannelWriteSchema.md
docs/OpsgenieNotificationChannel.md
docs/OpsgenieNotificationChannelAllOf.md
docs/OpsgeniePriority.md
docs/OpsgenieRegion.md
docs/OpsgenieResponder.md
docs/OpsgenieResponderType.md
docs/PermissionDescription.md
docs/Permissions.md
docs/PermissionsApi.md
docs/PersesDashboard.md
docs/PersesDashboardDisplaySpec.md
docs/PersesDashboardSpec.md
docs/PersesDatasourceSpec.md
docs/PersesGridItem.md
docs/PersesGridLayoutCollapse.md
docs/PersesGridLayoutDisplay.md
docs/PersesJSONRef.md
docs/PersesLayout.md
docs/PersesLayoutKind.md
docs/PersesLayoutSpec.md
docs/PersesLink.md
docs/PersesListVariable.md
docs/PersesListVariableDefaultSingleValue.md
docs/PersesListVariableDefaultSliceValues.md
docs/PersesListVariableDefaultValue.md
docs/PersesListVariableSpec.md
docs/PersesPanel.md
docs/PersesPanelDisplay.md
docs/PersesPanelSpec.md
docs/PersesPlugin.md
docs/PersesProjectMetadata.md
docs/PersesQuery.md
docs/PersesQuerySpec.md
docs/PersesTextVariable.md
docs/PersesTextVariableSpec.md
docs/PersesVariableDisplaySpec.md
docs/PersesVariableSort.md
docs/PersesVariableTypes.md
docs/ProblemApi.md
docs/ProblemNotFound.md
docs/PromData.md
Expand Down Expand Up @@ -332,6 +382,7 @@ docs/SpanFilter.md
docs/SpanKind.md
docs/SpanLink.md
docs/SpanParentType.md
docs/SpanResponse.md
docs/SpanSortDirection.md
docs/SpanSortField.md
docs/SpanSortOption.md
Expand Down Expand Up @@ -369,6 +420,7 @@ docs/TimelineSummary.md
docs/TimelineSummaryError.md
docs/TimelineSummaryEventBucket.md
docs/TimelineSummaryHealthChange.md
docs/TimelineSummaryOverflow.md
docs/TimelineSummaryRequest.md
docs/TimelineSummaryRequestArguments.md
docs/TooManyActiveQueries.md
Expand Down Expand Up @@ -397,9 +449,10 @@ docs/TraceApiSpanNotFound.md
docs/TraceApiSpansBadRequest.md
docs/TraceApiTraceNotFound.md
docs/TraceFilter.md
docs/TraceIdentifier.md
docs/TraceQuery.md
docs/Traces.md
docs/TraceQueryMatch.md
docs/TraceQueryMatchAllOf.md
docs/TraceQueryResponse.md
docs/TracesApi.md
docs/UnlicensedSubscription.md
docs/UnmatchedCheckState.md
Expand Down Expand Up @@ -459,6 +512,22 @@ model_component_not_found_error.go
model_component_query.go
model_component_view_arguments.go
model_create_subject.go
model_dashboard_authorization_error.go
model_dashboard_client_errors.go
model_dashboard_clone_schema.go
model_dashboard_invalid_identifier_error.go
model_dashboard_list.go
model_dashboard_not_found_error.go
model_dashboard_patch_schema.go
model_dashboard_read_base_schema.go
model_dashboard_read_full_schema.go
model_dashboard_read_full_schema_all_of.go
model_dashboard_read_metadata_schema.go
model_dashboard_read_metadata_schema_all_of.go
model_dashboard_read_schema.go
model_dashboard_scope.go
model_dashboard_validation_error.go
model_dashboard_write_schema.go
model_data_unavailable.go
model_dependency_direction.go
model_duration_histogram.go
Expand Down Expand Up @@ -638,9 +707,41 @@ model_opsgenie_channel_ref_id.go
model_opsgenie_channel_write_schema.go
model_opsgenie_notification_channel.go
model_opsgenie_notification_channel_all_of.go
model_opsgenie_priority.go
model_opsgenie_region.go
model_opsgenie_responder.go
model_opsgenie_responder_type.go
model_permission_description.go
model_permissions.go
model_perses_dashboard.go
model_perses_dashboard_display_spec.go
model_perses_dashboard_spec.go
model_perses_datasource_spec.go
model_perses_grid_item.go
model_perses_grid_layout_collapse.go
model_perses_grid_layout_display.go
model_perses_json_ref.go
model_perses_layout.go
model_perses_layout_kind.go
model_perses_layout_spec.go
model_perses_link.go
model_perses_list_variable.go
model_perses_list_variable_default_single_value.go
model_perses_list_variable_default_slice_values.go
model_perses_list_variable_default_value.go
model_perses_list_variable_spec.go
model_perses_panel.go
model_perses_panel_display.go
model_perses_panel_spec.go
model_perses_plugin.go
model_perses_project_metadata.go
model_perses_query.go
model_perses_query_spec.go
model_perses_text_variable.go
model_perses_text_variable_spec.go
model_perses_variable_display_spec.go
model_perses_variable_sort.go
model_perses_variable_types.go
model_problem_not_found.go
model_prom_data.go
model_prom_data_result.go
Expand Down Expand Up @@ -687,6 +788,7 @@ model_span_filter.go
model_span_kind.go
model_span_link.go
model_span_parent_type.go
model_span_response.go
model_span_sort_direction.go
model_span_sort_field.go
model_span_sort_option.go
Expand Down Expand Up @@ -719,6 +821,7 @@ model_timeline_summary.go
model_timeline_summary_error.go
model_timeline_summary_event_bucket.go
model_timeline_summary_health_change.go
model_timeline_summary_overflow.go
model_timeline_summary_request.go
model_timeline_summary_request_arguments.go
model_too_many_active_queries.go
Expand All @@ -745,9 +848,10 @@ 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_trace_query_match.go
model_trace_query_match_all_of.go
model_trace_query_response.go
model_unlicensed_subscription.go
model_unmatched_check_state.go
model_user_name_mismatch_error.go
Expand Down
Loading
Loading