Skip to content

Commit 2fe21d3

Browse files
authored
Merge pull request #107 from StackVista/STAC-23108-add-createonly-flag
STAC-23108: add createOnly flag
2 parents d96a4cc + 1920f24 commit 2fe21d3

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

cmd/rbac/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const (
55
Permission = "permission"
66
Resource = "resource"
77
Scope = "scope"
8+
CreateOnly = "create-only"
89

910
SubjectUsage = "The handle of the subject of the permissions. If you're using LDAP, please use the usernameKey configured in StackState"
1011
PermissionRevokeUsage = "The permission to revoke"
@@ -16,6 +17,7 @@ const (
1617
ScopeUsage = "The query in STQL that will be prepended to every topology element retrieved in StackState. " +
1718
"For example, if your scope is \"label = 'A'\", then all STQL executed in StackState" +
1819
" (e.g. Retrieving topology) will only return elements that have the label A"
20+
CreateOnlyUsage = "Fail when a subject with the same name already exists"
1921

2022
DefaultResource = "system"
2123
)

cmd/rbac/rbac_create_subject.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
)
1010

1111
type CreateSubjectArgs struct {
12-
Subject string
13-
Scope string
12+
Subject string
13+
Scope string
14+
CreateOnly bool
1415
}
1516

1617
func CreateSubjectCommand(deps *di.Deps) *cobra.Command {
@@ -26,6 +27,7 @@ func CreateSubjectCommand(deps *di.Deps) *cobra.Command {
2627
cmd.MarkFlagRequired(Subject) //nolint:errcheck
2728

2829
cmd.Flags().StringVar(&args.Scope, Scope, "", ScopeUsage)
30+
cmd.Flags().BoolVar(&args.CreateOnly, CreateOnly, false, CreateOnlyUsage)
2931

3032
return cmd
3133
}
@@ -45,6 +47,7 @@ func RunCreateSubjectCommand(args *CreateSubjectArgs) di.CmdWithApiFn {
4547

4648
resp, err := api.SubjectApi.CreateSubject(cli.Context, args.Subject).
4749
CreateSubject(*subject).
50+
CreateOnly(args.CreateOnly).
4851
Execute()
4952

5053
if err != nil {

generated/stackstate_api/api/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,6 +3860,11 @@ paths:
38603860
required: true
38613861
schema:
38623862
$ref: '#/components/schemas/Subject'
3863+
- in: query
3864+
name: createOnly
3865+
required: false
3866+
schema:
3867+
type: boolean
38633868
requestBody:
38643869
content:
38653870
application/json:

generated/stackstate_api/api_subject.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/stackstate_api/docs/SubjectApi.md

Lines changed: 4 additions & 2 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).CreateSubject(createSubject).Execute()
16+
> CreateSubject(ctx, subject).CreateSubject(createSubject).CreateOnly(createOnly).Execute()
1717
1818
Create a subject
1919

@@ -34,10 +34,11 @@ import (
3434
func main() {
3535
subject := "subject_example" // string |
3636
createSubject := *openapiclient.NewCreateSubject() // CreateSubject |
37+
createOnly := true // bool | (optional)
3738

3839
configuration := openapiclient.NewConfiguration()
3940
apiClient := openapiclient.NewAPIClient(configuration)
40-
resp, r, err := apiClient.SubjectApi.CreateSubject(context.Background(), subject).CreateSubject(createSubject).Execute()
41+
resp, r, err := apiClient.SubjectApi.CreateSubject(context.Background(), subject).CreateSubject(createSubject).CreateOnly(createOnly).Execute()
4142
if err != nil {
4243
fmt.Fprintf(os.Stderr, "Error when calling `SubjectApi.CreateSubject``: %v\n", err)
4344
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
@@ -62,6 +63,7 @@ Name | Type | Description | Notes
6263
------------- | ------------- | ------------- | -------------
6364

6465
**createSubject** | [**CreateSubject**](CreateSubject.md) | |
66+
**createOnly** | **bool** | |
6567

6668
### Return type
6769

stackstate_openapi/openapi_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d8fc5194c51017c8e938a1b54f94bdb8a857d6c8
1+
674af5775997226a77151f9ef90cc9d6ef95c7eb

0 commit comments

Comments
 (0)