Skip to content

Commit 30cd9fa

Browse files
Merge pull request #98 from StackVista/stac-22196-stoken
STAC-22916: Setup branch deploy with a bootstrap service token using …
2 parents d33eaf2 + ee84226 commit 30cd9fa

File tree

12 files changed

+182
-30
lines changed

12 files changed

+182
-30
lines changed

cmd/servicetoken/servicetoken_create.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ const (
1616
)
1717

1818
type CreateArgs struct {
19-
Name string
20-
Expiration time.Time
21-
Roles []string
19+
Name string
20+
Expiration time.Time
21+
Roles []string
22+
DedicatedSubject string
2223
}
2324

2425
func CreateCommand(deps *di.Deps) *cobra.Command {
@@ -33,15 +34,17 @@ func CreateCommand(deps *di.Deps) *cobra.Command {
3334
common.AddRequiredNameFlagVar(cmd, &args.Name, "Name of the service token")
3435
cmd.Flags().TimeVar(&args.Expiration, "expiration", time.Time{}, []string{DateFormat}, "Expiration date of the service token")
3536
cmd.Flags().StringSliceVar(&args.Roles, "roles", []string{}, "Roles assigned to the service token")
37+
cmd.Flags().StringVar(&args.DedicatedSubject, "dedicatedSubject", "", "Subject solely created for usage with this token. The dedicated subject is cleaned after the token is deleted")
3638
cmd.MarkFlagRequired("roles") //nolint:errcheck
3739
return cmd
3840
}
3941

4042
func RunServiceTokenCreateCommand(args *CreateArgs) di.CmdWithApiFn {
4143
return func(cmd *cobra.Command, cli *di.Deps, api *stackstate_api.APIClient, serverInfo *stackstate_api.ServerInfo) common.CLIError {
4244
req := stackstate_api.NewServiceTokenRequest{
43-
Name: args.Name,
44-
Roles: args.Roles,
45+
Name: args.Name,
46+
Roles: args.Roles,
47+
DedicatedSubject: &args.DedicatedSubject,
4548
}
4649

4750
if !args.Expiration.IsZero() {

cmd/servicetoken/servicetoken_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func RunServiceTokenListCommand(cmd *cobra.Command, cli *di.Deps, api *stackstat
4444
if serviceToken.Expiration != nil {
4545
exp = time.UnixMilli(*serviceToken.Expiration).Format(DateFormat)
4646
}
47-
data = append(data, []interface{}{sid, serviceToken.Name, exp, serviceToken.Roles})
47+
data = append(data, []interface{}{sid, serviceToken.Name, exp, serviceToken.Roles, serviceToken.DedicatedSubject})
4848
}
4949

5050
cli.Printer.Table(printer.TableData{
51-
Header: []string{"id", "name", "expiration", "roles"},
51+
Header: []string{"id", "name", "expiration", "roles", "dedicated_Subject"},
5252
Data: data,
5353
MissingTableDataMsg: printer.NotFoundMsg{Types: "service tokens"},
5454
})

cmd/servicetoken/servicetoken_list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ func TestServiceTokenList(t *testing.T) {
3737

3838
tableData := []printer.TableData{
3939
{
40-
Header: []string{"id", "name", "expiration", "roles"},
40+
Header: []string{"id", "name", "expiration", "roles", "dedicated_Subject"},
4141
Data: [][]interface{}{
42-
{int64(1), "test", "2020-05-22", []string{"test-role", "another-role"}},
43-
{int64(2), "test2", "", []string{"test-role"}},
42+
{int64(1), "test", "2020-05-22", []string{"test-role", "another-role"}, (*string)(nil)},
43+
{int64(2), "test2", "", []string{"test-role"}, (*string)(nil)},
4444
},
4545
MissingTableDataMsg: printer.NotFoundMsg{Types: "service tokens"},
4646
},

generated/stackstate_api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Class | Method | HTTP request | Description
232232
*TracesApi* | [**SuggestionsAttributeName**](docs/TracesApi.md#suggestionsattributename) | **Get** /traces/spans/fields/attributes | Suggestions for attribute names
233233
*TracesApi* | [**SuggestionsAttributeValue**](docs/TracesApi.md#suggestionsattributevalue) | **Get** /traces/spans/fields/attributes/{attributeName}/values | Suggestions for attribute values
234234
*TracesApi* | [**SuggestionsFieldValues**](docs/TracesApi.md#suggestionsfieldvalues) | **Get** /traces/spans/fields/{field}/values | Suggestions for span fields
235-
*UserAuthorizationApi* | [**GetUserAuthorizationFor**](docs/UserAuthorizationApi.md#getuserauthorizationfor) | **Get** /user/authorization/for | Is the current user authorized for the provided permission
235+
*UserAuthorizationApi* | [**GetUserAuthorizationFor**](docs/UserAuthorizationApi.md#getuserauthorizationfor) | **Get** /user/authorization/for | Is the current user authorized for the provided permission and resource
236236
*UserProfileApi* | [**GetCurrentUserProfile**](docs/UserProfileApi.md#getcurrentuserprofile) | **Get** /user/profile | Get current user profile
237237
*UserProfileApi* | [**SaveCurrentUserProfile**](docs/UserProfileApi.md#savecurrentuserprofile) | **Put** /user/profile | Save current user profile
238238
*UserSessionApi* | [**GetUserSessionAssumedRole**](docs/UserSessionApi.md#getusersessionassumedrole) | **Get** /user/session/assumedRole | Get the assumed a role for the current session

generated/stackstate_api/api/openapi.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,14 +2596,20 @@ paths:
25962596
- userSession
25972597
/user/authorization/for:
25982598
get:
2599-
description: Is the current user authorized for the provided permission
2599+
description: Is the current user authorized for the provided permission and
2600+
resource
26002601
operationId: getUserAuthorizationFor
26012602
parameters:
26022603
- in: query
26032604
name: permission
26042605
required: true
26052606
schema:
26062607
type: string
2608+
- in: query
2609+
name: resourceName
2610+
required: false
2611+
schema:
2612+
type: string
26072613
responses:
26082614
"204":
26092615
description: User is authorized
@@ -2619,7 +2625,7 @@ paths:
26192625
schema:
26202626
$ref: '#/components/schemas/GenericErrorsResponse'
26212627
description: Error when handling the request on the server side.
2622-
summary: Is the current user authorized for the provided permission
2628+
summary: Is the current user authorized for the provided permission and resource
26232629
tags:
26242630
- userAuthorization
26252631
/events:
@@ -10685,6 +10691,7 @@ components:
1068510691
- roles
1068610692
- roles
1068710693
name: name
10694+
dedicatedSubject: dedicatedSubject
1068810695
properties:
1068910696
name:
1069010697
type: string
@@ -10695,6 +10702,8 @@ components:
1069510702
items:
1069610703
type: string
1069710704
type: array
10705+
dedicatedSubject:
10706+
type: string
1069810707
required:
1069910708
- name
1070010709
- roles
@@ -10709,6 +10718,7 @@ components:
1070910718
description: description
1071010719
expiration: 1
1071110720
id: 0
10721+
dedicatedSubject: dedicatedSubject
1071210722
properties:
1071310723
id:
1071410724
format: int64
@@ -10729,6 +10739,8 @@ components:
1072910739
items:
1073010740
type: string
1073110741
type: array
10742+
dedicatedSubject:
10743+
type: string
1073210744
required:
1073310745
- name
1073410746
- roles

generated/stackstate_api/api_user_authorization.go

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

generated/stackstate_api/docs/NewServiceTokenRequest.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Name | Type | Description | Notes
77
**Name** | **string** | |
88
**ExpiryDate** | Pointer to **int64** | | [optional]
99
**Roles** | **[]string** | |
10+
**DedicatedSubject** | Pointer to **string** | | [optional]
1011

1112
## Methods
1213

@@ -92,6 +93,31 @@ and a boolean to check if the value has been set.
9293
SetRoles sets Roles field to given value.
9394

9495

96+
### GetDedicatedSubject
97+
98+
`func (o *NewServiceTokenRequest) GetDedicatedSubject() string`
99+
100+
GetDedicatedSubject returns the DedicatedSubject field if non-nil, zero value otherwise.
101+
102+
### GetDedicatedSubjectOk
103+
104+
`func (o *NewServiceTokenRequest) GetDedicatedSubjectOk() (*string, bool)`
105+
106+
GetDedicatedSubjectOk returns a tuple with the DedicatedSubject field if it's non-nil, zero value otherwise
107+
and a boolean to check if the value has been set.
108+
109+
### SetDedicatedSubject
110+
111+
`func (o *NewServiceTokenRequest) SetDedicatedSubject(v string)`
112+
113+
SetDedicatedSubject sets DedicatedSubject field to given value.
114+
115+
### HasDedicatedSubject
116+
117+
`func (o *NewServiceTokenRequest) HasDedicatedSubject() bool`
118+
119+
HasDedicatedSubject returns a boolean if a field has been set.
120+
95121

96122
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
97123

generated/stackstate_api/docs/ServiceToken.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Name | Type | Description | Notes
1010
**Description** | Pointer to **string** | | [optional]
1111
**Expiration** | Pointer to **int64** | | [optional]
1212
**Roles** | **[]string** | |
13+
**DedicatedSubject** | Pointer to **string** | | [optional]
1314

1415
## Methods
1516

@@ -170,6 +171,31 @@ and a boolean to check if the value has been set.
170171
SetRoles sets Roles field to given value.
171172

172173

174+
### GetDedicatedSubject
175+
176+
`func (o *ServiceToken) GetDedicatedSubject() string`
177+
178+
GetDedicatedSubject returns the DedicatedSubject field if non-nil, zero value otherwise.
179+
180+
### GetDedicatedSubjectOk
181+
182+
`func (o *ServiceToken) GetDedicatedSubjectOk() (*string, bool)`
183+
184+
GetDedicatedSubjectOk returns a tuple with the DedicatedSubject field if it's non-nil, zero value otherwise
185+
and a boolean to check if the value has been set.
186+
187+
### SetDedicatedSubject
188+
189+
`func (o *ServiceToken) SetDedicatedSubject(v string)`
190+
191+
SetDedicatedSubject sets DedicatedSubject field to given value.
192+
193+
### HasDedicatedSubject
194+
195+
`func (o *ServiceToken) HasDedicatedSubject() bool`
196+
197+
HasDedicatedSubject returns a boolean if a field has been set.
198+
173199

174200
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
175201

generated/stackstate_api/docs/UserAuthorizationApi.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ All URIs are relative to *http://localhost*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7-
[**GetUserAuthorizationFor**](UserAuthorizationApi.md#GetUserAuthorizationFor) | **Get** /user/authorization/for | Is the current user authorized for the provided permission
7+
[**GetUserAuthorizationFor**](UserAuthorizationApi.md#GetUserAuthorizationFor) | **Get** /user/authorization/for | Is the current user authorized for the provided permission and resource
88

99

1010

1111
## GetUserAuthorizationFor
1212

13-
> GetUserAuthorizationFor(ctx).Permission(permission).Execute()
13+
> GetUserAuthorizationFor(ctx).Permission(permission).ResourceName(resourceName).Execute()
1414
15-
Is the current user authorized for the provided permission
15+
Is the current user authorized for the provided permission and resource
1616

1717

1818

@@ -30,10 +30,11 @@ import (
3030

3131
func main() {
3232
permission := "permission_example" // string |
33+
resourceName := "resourceName_example" // string | (optional)
3334

3435
configuration := openapiclient.NewConfiguration()
3536
apiClient := openapiclient.NewAPIClient(configuration)
36-
resp, r, err := apiClient.UserAuthorizationApi.GetUserAuthorizationFor(context.Background()).Permission(permission).Execute()
37+
resp, r, err := apiClient.UserAuthorizationApi.GetUserAuthorizationFor(context.Background()).Permission(permission).ResourceName(resourceName).Execute()
3738
if err != nil {
3839
fmt.Fprintf(os.Stderr, "Error when calling `UserAuthorizationApi.GetUserAuthorizationFor``: %v\n", err)
3940
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
@@ -53,6 +54,7 @@ Other parameters are passed through a pointer to a apiGetUserAuthorizationForReq
5354
Name | Type | Description | Notes
5455
------------- | ------------- | ------------- | -------------
5556
**permission** | **string** | |
57+
**resourceName** | **string** | |
5658

5759
### Return type
5860

generated/stackstate_api/model_new_service_token_request.go

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

0 commit comments

Comments
 (0)