Skip to content

Commit

Permalink
feat: Add metadata on client secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Aug 11, 2022
1 parent fe85f64 commit 6335dd9
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 17 deletions.
10 changes: 10 additions & 0 deletions authclient/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ components:
type: string
id:
type: string
metadata:
additionalProperties:
type: string
type: object
required:
- id
- lastDigits
Expand Down Expand Up @@ -410,10 +414,16 @@ components:
- $ref: '#/components/schemas/Scope_allOf'
SecretOptions:
example:
metadata:
key: metadata
name: name
properties:
name:
type: string
metadata:
additionalProperties:
type: string
type: object
required:
- name
type: object
Expand Down
26 changes: 26 additions & 0 deletions authclient/docs/ClientSecret.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
**LastDigits** | **string** | |
**Name** | **string** | |
**Id** | **string** | |
**Metadata** | Pointer to **map[string]string** | | [optional]

## Methods

Expand Down Expand Up @@ -87,6 +88,31 @@ and a boolean to check if the value has been set.
SetId sets Id field to given value.


### GetMetadata

`func (o *ClientSecret) GetMetadata() map[string]string`

GetMetadata returns the Metadata field if non-nil, zero value otherwise.

### GetMetadataOk

`func (o *ClientSecret) GetMetadataOk() (*map[string]string, bool)`

GetMetadataOk returns a tuple with the Metadata field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetMetadata

`func (o *ClientSecret) SetMetadata(v map[string]string)`

SetMetadata sets Metadata field to given value.

### HasMetadata

`func (o *ClientSecret) HasMetadata() bool`

HasMetadata returns a boolean if a field has been set.


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

Expand Down
26 changes: 26 additions & 0 deletions authclient/docs/Secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Name** | **string** | |
**Metadata** | Pointer to **map[string]string** | | [optional]
**Id** | **string** | |
**LastDigits** | **string** | |
**Clear** | **string** | |
Expand Down Expand Up @@ -48,6 +49,31 @@ and a boolean to check if the value has been set.
SetName sets Name field to given value.


### GetMetadata

`func (o *Secret) GetMetadata() map[string]string`

GetMetadata returns the Metadata field if non-nil, zero value otherwise.

### GetMetadataOk

`func (o *Secret) GetMetadataOk() (*map[string]string, bool)`

GetMetadataOk returns a tuple with the Metadata field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetMetadata

`func (o *Secret) SetMetadata(v map[string]string)`

SetMetadata sets Metadata field to given value.

### HasMetadata

`func (o *Secret) HasMetadata() bool`

HasMetadata returns a boolean if a field has been set.

### GetId

`func (o *Secret) GetId() string`
Expand Down
26 changes: 26 additions & 0 deletions authclient/docs/SecretOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Name** | **string** | |
**Metadata** | Pointer to **map[string]string** | | [optional]

## Methods

Expand Down Expand Up @@ -45,6 +46,31 @@ and a boolean to check if the value has been set.
SetName sets Name field to given value.


### GetMetadata

`func (o *SecretOptions) GetMetadata() map[string]string`

GetMetadata returns the Metadata field if non-nil, zero value otherwise.

### GetMetadataOk

`func (o *SecretOptions) GetMetadataOk() (*map[string]string, bool)`

GetMetadataOk returns a tuple with the Metadata field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetMetadata

`func (o *SecretOptions) SetMetadata(v map[string]string)`

SetMetadata sets Metadata field to given value.

### HasMetadata

`func (o *SecretOptions) HasMetadata() bool`

HasMetadata returns a boolean if a field has been set.


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

Expand Down
36 changes: 36 additions & 0 deletions authclient/model_client_secret.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions authclient/model_secret.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions authclient/model_secret_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions pkg/api/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ func mapBusinessClient(c auth.Client) clientView {
}
}

type secretCreate struct {
Name string `json:"name"`
}

type secretCreateResult struct {
ID string `json:"id"`
LastDigits string `json:"lastDigits"`
Expand Down Expand Up @@ -103,12 +99,12 @@ func createSecret(db *gorm.DB) http.HandlerFunc {
return
}

sc := readJSONObject[secretCreate](w, r)
sc := readJSONObject[auth.SecretCreate](w, r)
if sc == nil {
return
}

secret, clear := client.GenerateNewSecret(sc.Name)
secret, clear := client.GenerateNewSecret(*sc)

if err := saveObject(w, r, db, client); err != nil {
return
Expand Down
10 changes: 7 additions & 3 deletions pkg/api/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ func TestReadClient(t *testing.T) {
}
client1 := auth.NewClient(opts)
client1.Scopes = append(client1.Scopes, *scope1)
secret, _ := client1.GenerateNewSecret("testing")
secret, _ := client1.GenerateNewSecret(auth.SecretCreate{
Name: "testing",
})
require.NoError(t, db.Create(client1).Error)

req := httptest.NewRequest(http.MethodGet, "/clients/"+client1.Id, nil)
Expand Down Expand Up @@ -281,7 +283,7 @@ func TestGenerateNewSecret(t *testing.T) {
client := auth.NewClient(auth.ClientOptions{})
require.NoError(t, db.Create(client).Error)

req := httptest.NewRequest(http.MethodPost, "/clients/"+client.Id+"/secrets", createJSONBuffer(t, secretCreate{
req := httptest.NewRequest(http.MethodPost, "/clients/"+client.Id+"/secrets", createJSONBuffer(t, auth.SecretCreate{
Name: "secret1",
}))
res := httptest.NewRecorder()
Expand All @@ -303,7 +305,9 @@ func TestGenerateNewSecret(t *testing.T) {
func TestDeleteSecret(t *testing.T) {
withDbAndClientRouter(t, func(router *mux.Router, db *gorm.DB) {
client := auth.NewClient(auth.ClientOptions{})
secret, _ := client.GenerateNewSecret("testing")
secret, _ := client.GenerateNewSecret(auth.SecretCreate{
Name: "testing",
})
require.NoError(t, db.Create(client).Error)

req := httptest.NewRequest(http.MethodDelete, "/clients/"+client.Id+"/secrets/"+secret.ID, nil)
Expand Down
Loading

0 comments on commit 6335dd9

Please sign in to comment.