Skip to content

Commit df5e937

Browse files
committed
STAC-22844: restore backwards compatibility - bring back the scope query
1 parent cc1ce62 commit df5e937

File tree

11 files changed

+238
-14
lines changed

11 files changed

+238
-14
lines changed

cmd/rbac/flags.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ const (
44
Subject = "subject"
55
Permission = "permission"
66
Resource = "resource"
7+
Scope = "scope"
78

89
SubjectUsage = "The handle of the subject of the permissions. If you're using LDAP, please use the usernameKey configured in StackState"
910
PermissionRevokeUsage = "The permission to revoke"
1011
PermissionGrantUsage = "The permission to grant"
1112
PermissionDescribeUsage = "Filter the permissions by permission name"
12-
ResourceDescribeUsage = "Filter the permissions by a resource identifier (e.g. system, a resource name or tag)"
13-
ResourceGrantUsage = "The resource to grant the permission to (e.g. \"system\" or a resource name or tag)"
14-
ResourceRevokeUsage = "The resource to revoke the permission to (e.g. \"system\" or a resource name or tag)"
13+
ResourceDescribeUsage = "Filter the permissions by a resource identifier (e.g. system or a view name)"
14+
ResourceGrantUsage = "The resource to grant the permission to (e.g. \"system\" or a view name)"
15+
ResourceRevokeUsage = "The resource to revoke the permission to (e.g. \"system\" or a view name)"
16+
ScopeUsage = "The query in STQL that will be prepended to every topology element retrieved in StackState. " +
17+
"For example, if your scope is \"label = 'A'\", then all STQL executed in StackState" +
18+
" (e.g. Retrieving topology) will only return elements that have the label A"
1519

1620
DefaultResource = "system"
1721
)

cmd/rbac/rbac_create_subject.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
type CreateSubjectArgs struct {
1212
Subject string
13+
Scope string
1314
}
1415

1516
func CreateSubjectCommand(deps *di.Deps) *cobra.Command {
@@ -24,6 +25,8 @@ func CreateSubjectCommand(deps *di.Deps) *cobra.Command {
2425
cmd.Flags().StringVar(&args.Subject, Subject, "", SubjectUsage)
2526
cmd.MarkFlagRequired(Subject) //nolint:errcheck
2627

28+
cmd.Flags().StringVar(&args.Scope, Scope, "", ScopeUsage)
29+
2730
return cmd
2831
}
2932

@@ -34,7 +37,13 @@ func RunCreateSubjectCommand(args *CreateSubjectArgs) di.CmdWithApiFn {
3437
api *stackstate_api.APIClient,
3538
serverInfo *stackstate_api.ServerInfo,
3639
) common.CLIError {
40+
subject := stackstate_api.NewCreateSubject()
41+
if args.Scope != "" {
42+
subject.SetQuery(args.Scope)
43+
}
44+
3745
resp, err := api.SubjectApi.CreateSubject(cli.Context, args.Subject).
46+
CreateSubject(*subject).
3847
Execute()
3948

4049
if err != nil {

cmd/rbac/rbac_create_subject_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rbac
22

33
import (
44
"fmt"
5+
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
56
"testing"
67

78
"github.com/stackvista/stackstate-cli/internal/di"
@@ -23,6 +24,9 @@ func TestCreateSubjectJson(t *testing.T) {
2324
assert.Len(t, calls, 1)
2425
assert.Equal(t, SomeSubject, calls[0].Psubject)
2526

27+
expectedSubject := stackstate_api.NewCreateSubject()
28+
assert.Equal(t, expectedSubject, calls[0].PcreateSubject)
29+
2630
expectedJson := []map[string]interface{}{
2731
{
2832
"created-subject": SomeSubject,
@@ -36,12 +40,16 @@ func TestCreateSubject(t *testing.T) {
3640
cli := di.NewMockDeps(t)
3741
cmd := CreateSubjectCommand(&cli.Deps)
3842

39-
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--subject", SomeOtherSubject)
43+
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--subject", SomeOtherSubject, "--scope", SomeScope)
4044

4145
calls := *cli.MockClient.ApiMocks.SubjectApi.CreateSubjectCalls
4246
assert.Len(t, calls, 1)
4347
assert.Equal(t, SomeOtherSubject, calls[0].Psubject)
4448

49+
otherExpectedSubject := stackstate_api.NewCreateSubject()
50+
otherExpectedSubject.SetQuery(SomeScope)
51+
assert.Equal(t, otherExpectedSubject, calls[0].PcreateSubject)
52+
4553
expectedStrings := []string{
4654
fmt.Sprintf("Created subject '%s'", SomeOtherSubject),
4755
}

generated/stackstate_api/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ docs/ComponentHighlightMetricSectionAllOf.md
8585
docs/ComponentNotFoundError.md
8686
docs/ComponentQuery.md
8787
docs/ComponentViewArguments.md
88+
docs/CreateSubject.md
8889
docs/DashboardAuthorizationError.md
8990
docs/DashboardClientErrors.md
9091
docs/DashboardCloneSchema.md
@@ -510,6 +511,7 @@ model_component_highlight_metric_section_all_of.go
510511
model_component_not_found_error.go
511512
model_component_query.go
512513
model_component_view_arguments.go
514+
model_create_subject.go
513515
model_dashboard_authorization_error.go
514516
model_dashboard_client_errors.go
515517
model_dashboard_clone_schema.go

generated/stackstate_api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ Class | Method | HTTP request | Description
281281
- [ComponentNotFoundError](docs/ComponentNotFoundError.md)
282282
- [ComponentQuery](docs/ComponentQuery.md)
283283
- [ComponentViewArguments](docs/ComponentViewArguments.md)
284+
- [CreateSubject](docs/CreateSubject.md)
284285
- [DashboardAuthorizationError](docs/DashboardAuthorizationError.md)
285286
- [DashboardClientErrors](docs/DashboardClientErrors.md)
286287
- [DashboardCloneSchema](docs/DashboardCloneSchema.md)

generated/stackstate_api/api/openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,6 +3959,12 @@ paths:
39593959
required: true
39603960
schema:
39613961
$ref: '#/components/schemas/Subject'
3962+
requestBody:
3963+
content:
3964+
application/json:
3965+
schema:
3966+
$ref: '#/components/schemas/CreateSubject'
3967+
required: true
39623968
responses:
39633969
"200":
39643970
description: Subject created
@@ -10902,6 +10908,15 @@ components:
1090210908
required:
1090310909
- handle
1090410910
type: object
10911+
CreateSubject:
10912+
example:
10913+
query: query
10914+
properties:
10915+
query:
10916+
type: string
10917+
type: object
10918+
Query:
10919+
type: string
1090510920
SubscriptionState:
1090610921
discriminator:
1090710922
propertyName: _type

generated/stackstate_api/api_subject.go

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# CreateSubject
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**Query** | Pointer to **string** | | [optional]
8+
9+
## Methods
10+
11+
### NewCreateSubject
12+
13+
`func NewCreateSubject() *CreateSubject`
14+
15+
NewCreateSubject instantiates a new CreateSubject object
16+
This constructor will assign default values to properties that have it defined,
17+
and makes sure properties required by API are set, but the set of arguments
18+
will change when the set of required properties is changed
19+
20+
### NewCreateSubjectWithDefaults
21+
22+
`func NewCreateSubjectWithDefaults() *CreateSubject`
23+
24+
NewCreateSubjectWithDefaults instantiates a new CreateSubject object
25+
This constructor will only assign default values to properties that have it defined,
26+
but it doesn't guarantee that properties required by API are set
27+
28+
### GetQuery
29+
30+
`func (o *CreateSubject) GetQuery() string`
31+
32+
GetQuery returns the Query field if non-nil, zero value otherwise.
33+
34+
### GetQueryOk
35+
36+
`func (o *CreateSubject) GetQueryOk() (*string, bool)`
37+
38+
GetQueryOk returns a tuple with the Query field if it's non-nil, zero value otherwise
39+
and a boolean to check if the value has been set.
40+
41+
### SetQuery
42+
43+
`func (o *CreateSubject) SetQuery(v string)`
44+
45+
SetQuery sets Query field to given value.
46+
47+
### HasQuery
48+
49+
`func (o *CreateSubject) HasQuery() bool`
50+
51+
HasQuery returns a boolean if a field has been set.
52+
53+
54+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
55+
56+

generated/stackstate_api/docs/SubjectApi.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Method | HTTP request | Description
1313

1414
## CreateSubject
1515

16-
> CreateSubject(ctx, subject).Execute()
16+
> CreateSubject(ctx, subject).CreateSubject(createSubject).Execute()
1717
1818
Create a subject
1919

@@ -33,10 +33,11 @@ import (
3333

3434
func main() {
3535
subject := "subject_example" // string |
36+
createSubject := *openapiclient.NewCreateSubject() // CreateSubject |
3637

3738
configuration := openapiclient.NewConfiguration()
3839
apiClient := openapiclient.NewAPIClient(configuration)
39-
resp, r, err := apiClient.SubjectApi.CreateSubject(context.Background(), subject).Execute()
40+
resp, r, err := apiClient.SubjectApi.CreateSubject(context.Background(), subject).CreateSubject(createSubject).Execute()
4041
if err != nil {
4142
fmt.Fprintf(os.Stderr, "Error when calling `SubjectApi.CreateSubject``: %v\n", err)
4243
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
@@ -60,6 +61,7 @@ Other parameters are passed through a pointer to a apiCreateSubjectRequest struc
6061
Name | Type | Description | Notes
6162
------------- | ------------- | ------------- | -------------
6263

64+
**createSubject** | [**CreateSubject**](CreateSubject.md) | |
6365

6466
### Return type
6567

@@ -71,7 +73,7 @@ Name | Type | Description | Notes
7173

7274
### HTTP request headers
7375

74-
- **Content-Type**: Not defined
76+
- **Content-Type**: application/json
7577
- **Accept**: application/json
7678

7779
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints)

0 commit comments

Comments
 (0)