mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
NOISSUE - Remove public metadata, introduce private metadata (#3322)
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
@@ -155,26 +155,26 @@ func (x *RetrieveUsersRes) GetUsers() []*User {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
FirstName string `protobuf:"bytes,2,opt,name=first_name,json=firstName,proto3" json:"first_name,omitempty"`
|
||||
LastName string `protobuf:"bytes,3,opt,name=last_name,json=lastName,proto3" json:"last_name,omitempty"`
|
||||
Tags []string `protobuf:"bytes,4,rep,name=tags,proto3" json:"tags,omitempty"`
|
||||
Metadata *structpb.Struct `protobuf:"bytes,5,opt,name=metadata,proto3" json:"metadata,omitempty"`
|
||||
PublicMetadata *structpb.Struct `protobuf:"bytes,6,opt,name=public_metadata,json=publicMetadata,proto3" json:"public_metadata,omitempty"`
|
||||
Status uint32 `protobuf:"varint,7,opt,name=status,proto3" json:"status,omitempty"`
|
||||
Role uint32 `protobuf:"varint,8,opt,name=role,proto3" json:"role,omitempty"`
|
||||
ProfilePicture string `protobuf:"bytes,9,opt,name=profile_picture,json=profilePicture,proto3" json:"profile_picture,omitempty"`
|
||||
Username string `protobuf:"bytes,10,opt,name=username,proto3" json:"username,omitempty"`
|
||||
Email string `protobuf:"bytes,11,opt,name=email,proto3" json:"email,omitempty"`
|
||||
CreatedAt *timestamppb.Timestamp `protobuf:"bytes,12,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
||||
UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,13,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
|
||||
UpdatedBy string `protobuf:"bytes,14,opt,name=updated_by,json=updatedBy,proto3" json:"updated_by,omitempty"`
|
||||
VerifiedAt *timestamppb.Timestamp `protobuf:"bytes,15,opt,name=verified_at,json=verifiedAt,proto3" json:"verified_at,omitempty"`
|
||||
AuthProvider string `protobuf:"bytes,16,opt,name=auth_provider,json=authProvider,proto3" json:"auth_provider,omitempty"`
|
||||
Permissions []string `protobuf:"bytes,17,rep,name=permissions,proto3" json:"permissions,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
FirstName string `protobuf:"bytes,2,opt,name=first_name,json=firstName,proto3" json:"first_name,omitempty"`
|
||||
LastName string `protobuf:"bytes,3,opt,name=last_name,json=lastName,proto3" json:"last_name,omitempty"`
|
||||
Tags []string `protobuf:"bytes,4,rep,name=tags,proto3" json:"tags,omitempty"`
|
||||
Metadata *structpb.Struct `protobuf:"bytes,5,opt,name=metadata,proto3" json:"metadata,omitempty"`
|
||||
PrivateMetadata *structpb.Struct `protobuf:"bytes,6,opt,name=private_metadata,json=privateMetadata,proto3" json:"private_metadata,omitempty"`
|
||||
Status uint32 `protobuf:"varint,7,opt,name=status,proto3" json:"status,omitempty"`
|
||||
Role uint32 `protobuf:"varint,8,opt,name=role,proto3" json:"role,omitempty"`
|
||||
ProfilePicture string `protobuf:"bytes,9,opt,name=profile_picture,json=profilePicture,proto3" json:"profile_picture,omitempty"`
|
||||
Username string `protobuf:"bytes,10,opt,name=username,proto3" json:"username,omitempty"`
|
||||
Email string `protobuf:"bytes,11,opt,name=email,proto3" json:"email,omitempty"`
|
||||
CreatedAt *timestamppb.Timestamp `protobuf:"bytes,12,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
||||
UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,13,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
|
||||
UpdatedBy string `protobuf:"bytes,14,opt,name=updated_by,json=updatedBy,proto3" json:"updated_by,omitempty"`
|
||||
VerifiedAt *timestamppb.Timestamp `protobuf:"bytes,15,opt,name=verified_at,json=verifiedAt,proto3" json:"verified_at,omitempty"`
|
||||
AuthProvider string `protobuf:"bytes,16,opt,name=auth_provider,json=authProvider,proto3" json:"auth_provider,omitempty"`
|
||||
Permissions []string `protobuf:"bytes,17,rep,name=permissions,proto3" json:"permissions,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *User) Reset() {
|
||||
@@ -242,9 +242,9 @@ func (x *User) GetMetadata() *structpb.Struct {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *User) GetPublicMetadata() *structpb.Struct {
|
||||
func (x *User) GetPrivateMetadata() *structpb.Struct {
|
||||
if x != nil {
|
||||
return x.PublicMetadata
|
||||
return x.PrivateMetadata
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -339,15 +339,15 @@ const file_users_v1_users_proto_rawDesc = "" +
|
||||
"\x05total\x18\x01 \x01(\x04R\x05total\x12\x14\n" +
|
||||
"\x05limit\x18\x02 \x01(\x04R\x05limit\x12\x16\n" +
|
||||
"\x06offset\x18\x03 \x01(\x04R\x06offset\x12$\n" +
|
||||
"\x05users\x18\x04 \x03(\v2\x0e.users.v1.UserR\x05users\"\xfd\x04\n" +
|
||||
"\x05users\x18\x04 \x03(\v2\x0e.users.v1.UserR\x05users\"\xff\x04\n" +
|
||||
"\x04User\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\tR\x02id\x12\x1d\n" +
|
||||
"\n" +
|
||||
"first_name\x18\x02 \x01(\tR\tfirstName\x12\x1b\n" +
|
||||
"\tlast_name\x18\x03 \x01(\tR\blastName\x12\x12\n" +
|
||||
"\x04tags\x18\x04 \x03(\tR\x04tags\x123\n" +
|
||||
"\bmetadata\x18\x05 \x01(\v2\x17.google.protobuf.StructR\bmetadata\x12@\n" +
|
||||
"\x0fpublic_metadata\x18\x06 \x01(\v2\x17.google.protobuf.StructR\x0epublicMetadata\x12\x16\n" +
|
||||
"\bmetadata\x18\x05 \x01(\v2\x17.google.protobuf.StructR\bmetadata\x12B\n" +
|
||||
"\x10private_metadata\x18\x06 \x01(\v2\x17.google.protobuf.StructR\x0fprivateMetadata\x12\x16\n" +
|
||||
"\x06status\x18\a \x01(\rR\x06status\x12\x12\n" +
|
||||
"\x04role\x18\b \x01(\rR\x04role\x12'\n" +
|
||||
"\x0fprofile_picture\x18\t \x01(\tR\x0eprofilePicture\x12\x1a\n" +
|
||||
@@ -390,7 +390,7 @@ var file_users_v1_users_proto_goTypes = []any{
|
||||
var file_users_v1_users_proto_depIdxs = []int32{
|
||||
2, // 0: users.v1.RetrieveUsersRes.users:type_name -> users.v1.User
|
||||
3, // 1: users.v1.User.metadata:type_name -> google.protobuf.Struct
|
||||
3, // 2: users.v1.User.public_metadata:type_name -> google.protobuf.Struct
|
||||
3, // 2: users.v1.User.private_metadata:type_name -> google.protobuf.Struct
|
||||
4, // 3: users.v1.User.created_at:type_name -> google.protobuf.Timestamp
|
||||
4, // 4: users.v1.User.updated_at:type_name -> google.protobuf.Timestamp
|
||||
4, // 5: users.v1.User.verified_at:type_name -> google.protobuf.Timestamp
|
||||
|
||||
@@ -181,7 +181,7 @@ paths:
|
||||
|
||||
patch:
|
||||
operationId: updateClient
|
||||
summary: Updates name and metadata of the client.
|
||||
summary: Updates name, metadata, and private metadata of the client.
|
||||
description: |
|
||||
Update is performed by replacing the current resource data with values
|
||||
provided in a request payload. Note that the client's type and ID
|
||||
@@ -943,14 +943,14 @@ components:
|
||||
example: bb7edb32-2eac-4aad-aebe-ed96fe073879
|
||||
minimum: 8
|
||||
description: Free-form account secret used for acquiring auth token(s).
|
||||
public_metadata:
|
||||
private_metadata:
|
||||
type: object
|
||||
example: { "model": "example" }
|
||||
description: Arbitrary, object-encoded client's data.
|
||||
description: Arbitrary, object-encoded client's data private to the client.
|
||||
metadata:
|
||||
type: object
|
||||
example: { "model": "example" }
|
||||
description: Arbitrary, object-encoded client's data, private to the client.
|
||||
description: Arbitrary, object-encoded client's data visible to other clients.
|
||||
status:
|
||||
type: string
|
||||
description: Client Status
|
||||
@@ -1005,14 +1005,14 @@ components:
|
||||
type: string
|
||||
example: bb7edb32-2eac-4aad-aebe-ed96fe073879
|
||||
description: Client secret password.
|
||||
public_metadata:
|
||||
private_metadata:
|
||||
type: object
|
||||
example: { "model": "example" }
|
||||
description: Arbitrary, object-encoded client's data.
|
||||
description: Arbitrary, object-encoded client's data private to the client.
|
||||
metadata:
|
||||
type: object
|
||||
example: { "model": "example" }
|
||||
description: Arbitrary, object-encoded client's data, private to the client.
|
||||
description: Arbitrary, object-encoded client's data visible to other clients.
|
||||
status:
|
||||
type: string
|
||||
description: Client Status
|
||||
@@ -1066,14 +1066,14 @@ components:
|
||||
type: string
|
||||
example: ""
|
||||
description: Client secret password.
|
||||
public_metadata:
|
||||
private_metadata:
|
||||
type: object
|
||||
example: { "model": "example" }
|
||||
description: Arbitrary, object-encoded client's data.
|
||||
description: Arbitrary, object-encoded client's data private to the client.
|
||||
metadata:
|
||||
type: object
|
||||
example: { "model": "example" }
|
||||
description: Arbitrary, object-encoded client's data, private to the client.
|
||||
description: Arbitrary, object-encoded client's data visible to other clients.
|
||||
status:
|
||||
type: string
|
||||
description: Client Status
|
||||
@@ -1125,14 +1125,14 @@ components:
|
||||
metadata:
|
||||
type: object
|
||||
example: { "role": "general" }
|
||||
description: Arbitrary, object-encoded client's data, private to the client.
|
||||
public_metadata:
|
||||
description: Arbitrary, object-encoded client's data visible to other clients.
|
||||
private_metadata:
|
||||
type: object
|
||||
example: { "role": "general" }
|
||||
description: Arbitrary, object-encoded client's data.
|
||||
description: Arbitrary, object-encoded client's data private to the client.
|
||||
required:
|
||||
- name
|
||||
- public_metadata
|
||||
- private_metadata
|
||||
- metadata
|
||||
|
||||
ClientTags:
|
||||
@@ -1185,7 +1185,7 @@ components:
|
||||
metadata:
|
||||
type: object
|
||||
example: { "model": "example" }
|
||||
description: Arbitrary, object-encoded client's data.
|
||||
description: Arbitrary, object-encoded client's data visible to other clients.
|
||||
status:
|
||||
type: string
|
||||
description: Client Status
|
||||
@@ -1443,7 +1443,7 @@ components:
|
||||
$ref: "#/components/schemas/ClientReqObj"
|
||||
|
||||
ClientUpdateReq:
|
||||
description: JSON-formated document describing the metadata and name of client to be update
|
||||
description: JSON-formated document describing the metadata, private metadata and name of client to be update
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
|
||||
+17
-13
@@ -154,10 +154,10 @@ paths:
|
||||
|
||||
patch:
|
||||
operationId: updateUser
|
||||
summary: Updates first, last name and metadata of the user.
|
||||
summary: Updates first, last name, metadata, and private metadata of the user.
|
||||
description: |
|
||||
Updates name and metadata of the user with provided ID. Name and metadata
|
||||
is updated using authorization token and the new received info.
|
||||
Updates name, metadata and private metadata of the user with provided ID. Name, metadata
|
||||
and private metadata are updated using authorization token and the new received info.
|
||||
tags:
|
||||
- Users
|
||||
parameters:
|
||||
@@ -714,11 +714,11 @@ components:
|
||||
metadata:
|
||||
type: object
|
||||
example: { "domain": "example.com" }
|
||||
description: Arbitrary, object-encoded user's data private to the user.
|
||||
public_metadata:
|
||||
description: Arbitrary, object-encoded user's data visible to other users.
|
||||
private_metadata:
|
||||
type: object
|
||||
example: { "domain": "example.com" }
|
||||
description: Arbitrary, object-encoded user's data.
|
||||
description: Arbitrary, object-encoded user's data private to the user.
|
||||
profile_picture:
|
||||
type: string
|
||||
example: "https://example.com/profile.jpg"
|
||||
@@ -774,11 +774,11 @@ components:
|
||||
metadata:
|
||||
type: object
|
||||
example: { "address": "example" }
|
||||
description: Arbitrary, object-encoded user's data private to the user.
|
||||
public_metadata:
|
||||
description: Arbitrary, object-encoded user's data visible to other users.
|
||||
private_metadata:
|
||||
type: object
|
||||
example: { "address": "example" }
|
||||
description: Arbitrary, object-encoded user's data.
|
||||
description: Arbitrary, object-encoded user's data private to the user.
|
||||
profile_picture:
|
||||
type: string
|
||||
example: "https://example.com/profile.jpg"
|
||||
@@ -843,7 +843,7 @@ components:
|
||||
metadata:
|
||||
type: object
|
||||
example: { "role": "general" }
|
||||
description: Arbitrary, object-encoded user's data.
|
||||
description: Arbitrary, object-encoded user's data visible to other users.
|
||||
status:
|
||||
type: string
|
||||
description: User Status
|
||||
@@ -902,7 +902,11 @@ components:
|
||||
metadata:
|
||||
type: object
|
||||
example: { "role": "general" }
|
||||
description: Arbitrary, object-encoded user's data.
|
||||
description: Arbitrary, object-encoded user's data visible to other users.
|
||||
private_metadata:
|
||||
type: object
|
||||
example: { "role": "general" }
|
||||
description: Arbitrary, object-encoded user's data private to the user.
|
||||
|
||||
UserTags:
|
||||
type: object
|
||||
@@ -1260,7 +1264,7 @@ components:
|
||||
|
||||
Metadata:
|
||||
name: metadata
|
||||
description: Metadata filter. Filtering is performed matching the parameter with public metadata on top level. Parameter is json.
|
||||
description: Metadata filter. Filtering is performed matching the parameter with metadata on top level. Parameter is json.
|
||||
in: query
|
||||
schema:
|
||||
type: object
|
||||
@@ -1342,7 +1346,7 @@ components:
|
||||
$ref: "#/components/schemas/UserReqObj"
|
||||
|
||||
UserUpdateReq:
|
||||
description: JSON-formated document describing the name, metadata and public_metadata of user to be update
|
||||
description: JSON-formated document describing the name, metadata and private_metadata of user to be update
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
|
||||
+8
-8
@@ -298,7 +298,7 @@ func TestUpdateClientCmd(t *testing.T) {
|
||||
newTagString := []string{"tag1", "tag2"}
|
||||
newNameandMeta := "{\"name\": \"clientName\", \"metadata\": {\"role\": \"general\"}}"
|
||||
newMetadata := "{\"metadata\": {\"role\": \"general\"}}"
|
||||
newPublicMeta := "{\"public_metadata\": {\"role\": \"general\"}}"
|
||||
newPrivateMeta := "{\"private_metadata\": {\"role\": \"general\"}}"
|
||||
newSecret := "secret"
|
||||
|
||||
cases := []struct {
|
||||
@@ -310,7 +310,7 @@ func TestUpdateClientCmd(t *testing.T) {
|
||||
logType outputLog
|
||||
}{
|
||||
{
|
||||
desc: "update client name and public metadata successfully",
|
||||
desc: "update client name and metadata successfully",
|
||||
args: []string{
|
||||
client.ID,
|
||||
updateCmd,
|
||||
@@ -320,7 +320,7 @@ func TestUpdateClientCmd(t *testing.T) {
|
||||
},
|
||||
client: smqsdk.Client{
|
||||
Name: "clientName",
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"role": "general",
|
||||
},
|
||||
ID: client.ID,
|
||||
@@ -350,16 +350,16 @@ func TestUpdateClientCmd(t *testing.T) {
|
||||
logType: entityLog,
|
||||
},
|
||||
{
|
||||
desc: "update client public metadata successfully",
|
||||
desc: "update client private metadata successfully",
|
||||
args: []string{
|
||||
client.ID,
|
||||
updateCmd,
|
||||
newPublicMeta,
|
||||
newPrivateMeta,
|
||||
domainID,
|
||||
token,
|
||||
},
|
||||
client: smqsdk.Client{
|
||||
PublicMetadata: map[string]any{
|
||||
PrivateMetadata: map[string]any{
|
||||
"role": "general",
|
||||
},
|
||||
ID: client.ID,
|
||||
@@ -388,11 +388,11 @@ func TestUpdateClientCmd(t *testing.T) {
|
||||
logType: entityLog,
|
||||
},
|
||||
{
|
||||
desc: "update client public metadata with invalid json",
|
||||
desc: "update client private metadata with invalid json",
|
||||
args: []string{
|
||||
client.ID,
|
||||
updateCmd,
|
||||
"{\"public_metadata\": {\"role\": \"general\"}",
|
||||
"{\"private_metadata\": {\"role\": \"general\"}",
|
||||
domainID,
|
||||
token,
|
||||
},
|
||||
|
||||
+4
-4
@@ -520,7 +520,7 @@ func TestUpdateUserCmd(t *testing.T) {
|
||||
newTagsJSON := "[\"tag1\", \"tag2\"]"
|
||||
newNameMetadataJSON := "{\"name\":\"new name\", \"metadata\":{\"key\": \"value\"}}"
|
||||
newMetadataJSON := "{\"metadata\":{\"key\": \"value\"}}"
|
||||
newPublicMetadataJSON := "{\"public_metadata\":{\"key\": \"value\"}}"
|
||||
newPrivateMetadataJSON := "{\"private_metadata\":{\"key\": \"value\"}}"
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -574,7 +574,7 @@ func TestUpdateUserCmd(t *testing.T) {
|
||||
args: []string{
|
||||
userID,
|
||||
updateCmd,
|
||||
newPublicMetadataJSON,
|
||||
newPrivateMetadataJSON,
|
||||
validToken,
|
||||
},
|
||||
logType: entityLog,
|
||||
@@ -585,7 +585,7 @@ func TestUpdateUserCmd(t *testing.T) {
|
||||
args: []string{
|
||||
userID,
|
||||
updateCmd,
|
||||
"{\"public_metadata\":{\"key\": \"value\"",
|
||||
"{\"private_metadata\":{\"key\": \"value\"",
|
||||
validToken,
|
||||
},
|
||||
sdkErr: errors.NewSDKError(errEndJSONInput),
|
||||
@@ -756,7 +756,7 @@ Available update options:
|
||||
case len(tc.args) == 4: // Basic user update
|
||||
sdkCall = sdkMock.On("UpdateUser", mock.Anything, mgsdk.User{
|
||||
FirstName: "new name",
|
||||
PublicMetadata: mgsdk.Metadata{
|
||||
PrivateMetadata: mgsdk.Metadata{
|
||||
"key": "value",
|
||||
},
|
||||
}, tc.args[3]).Return(tc.user, tc.sdkErr)
|
||||
|
||||
@@ -143,10 +143,10 @@ func updateClientEndpoint(svc clients.Service) endpoint.Endpoint {
|
||||
}
|
||||
|
||||
cli := clients.Client{
|
||||
ID: req.id,
|
||||
Name: req.Name,
|
||||
Metadata: req.Metadata,
|
||||
PublicMetadata: req.PublicMetadata,
|
||||
ID: req.id,
|
||||
Name: req.Name,
|
||||
Metadata: req.Metadata,
|
||||
PrivateMetadata: req.PrivateMetadata,
|
||||
}
|
||||
client, err := svc.Update(ctx, session, cli)
|
||||
if err != nil {
|
||||
|
||||
@@ -36,13 +36,13 @@ var (
|
||||
validMetadata = clients.Metadata{"role": "client"}
|
||||
ID = testsutil.GenerateUUID(&testing.T{})
|
||||
client = clients.Client{
|
||||
ID: ID,
|
||||
Name: "clientname",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Credentials: clients.Credentials{Identity: "clientidentity", Secret: secret},
|
||||
PublicMetadata: validMetadata,
|
||||
Metadata: validMetadata,
|
||||
Status: clients.EnabledStatus,
|
||||
ID: ID,
|
||||
Name: "clientname",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Credentials: clients.Credentials{Identity: "clientidentity", Secret: secret},
|
||||
PrivateMetadata: validMetadata,
|
||||
Metadata: validMetadata,
|
||||
Status: clients.EnabledStatus,
|
||||
}
|
||||
validToken = "token"
|
||||
inValidToken = "invalid"
|
||||
@@ -171,7 +171,7 @@ func TestCreateClient(t *testing.T) {
|
||||
Identity: "user@example.com",
|
||||
Secret: "12345678",
|
||||
},
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -261,9 +261,9 @@ func TestCreateClients(t *testing.T) {
|
||||
Identity: fmt.Sprintf("%s@example.com", namesgen.Generate()),
|
||||
Secret: secret,
|
||||
},
|
||||
PublicMetadata: clients.Metadata{},
|
||||
Metadata: clients.Metadata{},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: clients.Metadata{},
|
||||
Metadata: clients.Metadata{},
|
||||
Status: clients.EnabledStatus,
|
||||
}
|
||||
items = append(items, client)
|
||||
}
|
||||
@@ -364,7 +364,7 @@ func TestCreateClients(t *testing.T) {
|
||||
Identity: "user@example.com",
|
||||
Secret: "12345678",
|
||||
},
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -872,14 +872,14 @@ func TestUpdateClient(t *testing.T) {
|
||||
domainID: domainID,
|
||||
id: client.ID,
|
||||
authnRes: smqauthn.Session{DomainUserID: domainID + "_" + validID, UserID: validID, DomainID: domainID},
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"public_metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
token: validToken,
|
||||
contentType: contentType,
|
||||
clientResponse: clients.Client{
|
||||
ID: client.ID,
|
||||
Name: newName,
|
||||
Tags: []string{newTag},
|
||||
PublicMetadata: newMetadata,
|
||||
ID: client.ID,
|
||||
Name: newName,
|
||||
Tags: []string{newTag},
|
||||
Metadata: newMetadata,
|
||||
},
|
||||
status: http.StatusOK,
|
||||
|
||||
@@ -888,7 +888,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
{
|
||||
desc: "update client with invalid token",
|
||||
id: client.ID,
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"public_metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
domainID: domainID,
|
||||
token: inValidToken,
|
||||
contentType: contentType,
|
||||
@@ -899,7 +899,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
{
|
||||
desc: "update client with empty token",
|
||||
id: client.ID,
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"public_metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
contentType: contentType,
|
||||
@@ -909,7 +909,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
{
|
||||
desc: "update client with invalid contentype",
|
||||
id: client.ID,
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"public_metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
authnRes: smqauthn.Session{DomainUserID: domainID + "_" + validID, UserID: validID, DomainID: domainID},
|
||||
@@ -931,7 +931,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
{
|
||||
desc: "update client with empty id",
|
||||
id: " ",
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"public_metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"metadata":%s}`, newName, newTag, toJSON(newMetadata)),
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
authnRes: smqauthn.Session{DomainUserID: domainID + "_" + validID, UserID: validID, DomainID: domainID},
|
||||
@@ -943,7 +943,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
desc: "update client with name that is too long",
|
||||
id: client.ID,
|
||||
authnRes: smqauthn.Session{DomainUserID: domainID + "_" + validID, UserID: validID, DomainID: domainID},
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"public_metadata":%s}`, strings.Repeat("a", api.MaxNameSize+1), newTag, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","tags":["%s"],"metadata":%s}`, strings.Repeat("a", api.MaxNameSize+1), newTag, toJSON(newMetadata)),
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
contentType: contentType,
|
||||
|
||||
@@ -112,11 +112,11 @@ func (req listMembersReq) validate() error {
|
||||
}
|
||||
|
||||
type updateClientReq struct {
|
||||
id string
|
||||
Name string `json:"name,omitempty"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
PublicMetadata map[string]any `json:"public_metadata,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
id string
|
||||
Name string `json:"name,omitempty"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
PrivateMetadata map[string]any `json:"private_metadata,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
func (req updateClientReq) validate() error {
|
||||
|
||||
+13
-13
@@ -153,19 +153,19 @@ type Cache interface {
|
||||
// Client Struct represents a client.
|
||||
|
||||
type Client struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Domain string `json:"domain_id,omitempty"`
|
||||
ParentGroup string `json:"parent_group_id,omitempty"`
|
||||
Credentials Credentials `json:"credentials,omitempty"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
PublicMetadata Metadata `json:"public_metadata,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
UpdatedBy string `json:"updated_by,omitempty"`
|
||||
Status Status `json:"status,omitempty"` // 1 for enabled, 0 for disabled
|
||||
Identity string `json:"identity,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Domain string `json:"domain_id,omitempty"`
|
||||
ParentGroup string `json:"parent_group_id,omitempty"`
|
||||
Credentials Credentials `json:"credentials,omitempty"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
PrivateMetadata Metadata `json:"private_metadata,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
UpdatedBy string `json:"updated_by,omitempty"`
|
||||
Status Status `json:"status,omitempty"` // 1 for enabled, 0 for disabled
|
||||
Identity string `json:"identity,omitempty"`
|
||||
// Extended
|
||||
ParentGroupPath string `json:"parent_group_path,omitempty"`
|
||||
RoleID string `json:"role_id,omitempty"`
|
||||
|
||||
@@ -70,8 +70,8 @@ func (cce createClientEvent) Encode() (map[string]any, error) {
|
||||
if cce.Metadata != nil {
|
||||
val["metadata"] = cce.Metadata
|
||||
}
|
||||
if cce.PublicMetadata != nil {
|
||||
val["public_metadata"] = cce.PublicMetadata
|
||||
if cce.PrivateMetadata != nil {
|
||||
val["private_metadata"] = cce.PrivateMetadata
|
||||
}
|
||||
if cce.Credentials.Identity != "" {
|
||||
val["identity"] = cce.Credentials.Identity
|
||||
@@ -113,8 +113,8 @@ func (uce updateClientEvent) Encode() (map[string]any, error) {
|
||||
if uce.Metadata != nil {
|
||||
val["metadata"] = uce.Metadata
|
||||
}
|
||||
if uce.PublicMetadata != nil {
|
||||
val["public_metadata"] = uce.PublicMetadata
|
||||
if uce.PrivateMetadata != nil {
|
||||
val["private_metadata"] = uce.PrivateMetadata
|
||||
}
|
||||
if !uce.CreatedAt.IsZero() {
|
||||
val["created_at"] = uce.CreatedAt
|
||||
@@ -180,8 +180,8 @@ func (vce viewClientEvent) Encode() (map[string]any, error) {
|
||||
if vce.Metadata != nil {
|
||||
val["metadata"] = vce.Metadata
|
||||
}
|
||||
if vce.PublicMetadata != nil {
|
||||
val["public_metadata"] = vce.PublicMetadata
|
||||
if vce.PrivateMetadata != nil {
|
||||
val["private_metadata"] = vce.PrivateMetadata
|
||||
}
|
||||
if !vce.CreatedAt.IsZero() {
|
||||
val["created_at"] = vce.CreatedAt
|
||||
|
||||
@@ -126,7 +126,7 @@ func (lm *loggingMiddleware) Update(ctx context.Context, session authn.Session,
|
||||
slog.Group("client",
|
||||
slog.String("id", client.ID),
|
||||
slog.String("name", client.Name),
|
||||
slog.Any("public_metadata", client.PublicMetadata),
|
||||
slog.Any("metadata", client.Metadata),
|
||||
),
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
+47
-47
@@ -64,9 +64,9 @@ func (repo *clientRepo) Save(ctx context.Context, cls ...clients.Client) ([]clie
|
||||
}
|
||||
dbClients = append(dbClients, dbcli)
|
||||
}
|
||||
q := `INSERT INTO clients (id, name, tags, domain_id, parent_group_id, identity, secret, metadata, public_metadata, created_at, updated_at, updated_by, status)
|
||||
VALUES (:id, :name, :tags, :domain_id, :parent_group_id, :identity, :secret, :metadata, :public_metadata, :created_at, :updated_at, :updated_by, :status)
|
||||
RETURNING id, name, tags, identity, secret, metadata, public_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`
|
||||
q := `INSERT INTO clients (id, name, tags, domain_id, parent_group_id, identity, secret, metadata, private_metadata, created_at, updated_at, updated_by, status)
|
||||
VALUES (:id, :name, :tags, :domain_id, :parent_group_id, :identity, :secret, :metadata, :private_metadata, :created_at, :updated_at, :updated_by, :status)
|
||||
RETURNING id, name, tags, identity, secret, metadata, private_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`
|
||||
|
||||
row, err := repo.DB.NamedQueryContext(ctx, q, dbClients)
|
||||
if err != nil {
|
||||
@@ -92,7 +92,7 @@ func (repo *clientRepo) Save(ctx context.Context, cls ...clients.Client) ([]clie
|
||||
}
|
||||
|
||||
func (repo *clientRepo) RetrieveBySecret(ctx context.Context, key, id string, prefix authn.AuthPrefix) (clients.Client, error) {
|
||||
q := fmt.Sprintf(`SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, identity, secret, metadata, public_metadata, created_at, updated_at, updated_by, status
|
||||
q := fmt.Sprintf(`SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, identity, secret, metadata, private_metadata, created_at, updated_at, updated_by, status
|
||||
FROM clients
|
||||
WHERE secret = :secret AND status = %d`, clients.EnabledStatus)
|
||||
switch prefix {
|
||||
@@ -139,19 +139,19 @@ func (repo *clientRepo) Update(ctx context.Context, client clients.Client) (clie
|
||||
if client.Name != "" {
|
||||
query = append(query, "name = :name,")
|
||||
}
|
||||
if client.PublicMetadata != nil {
|
||||
query = append(query, "public_metadata = :public_metadata,")
|
||||
}
|
||||
if client.Metadata != nil {
|
||||
query = append(query, "metadata = :metadata,")
|
||||
}
|
||||
if client.PrivateMetadata != nil {
|
||||
query = append(query, "private_metadata = :private_metadata,")
|
||||
}
|
||||
if len(query) > 0 {
|
||||
upq = strings.Join(query, " ")
|
||||
}
|
||||
|
||||
q := fmt.Sprintf(`UPDATE clients SET %s updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, name, tags, identity, secret, metadata, public_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`,
|
||||
RETURNING id, name, tags, identity, secret, metadata, private_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`,
|
||||
upq)
|
||||
client.Status = clients.EnabledStatus
|
||||
return repo.update(ctx, client, q)
|
||||
@@ -160,7 +160,7 @@ func (repo *clientRepo) Update(ctx context.Context, client clients.Client) (clie
|
||||
func (repo *clientRepo) UpdateTags(ctx context.Context, client clients.Client) (clients.Client, error) {
|
||||
q := `UPDATE clients SET tags = :tags, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, name, tags, identity, metadata, public_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`
|
||||
RETURNING id, name, tags, identity, metadata, private_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`
|
||||
client.Status = clients.EnabledStatus
|
||||
return repo.update(ctx, client, q)
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func (repo *clientRepo) UpdateTags(ctx context.Context, client clients.Client) (
|
||||
func (repo *clientRepo) UpdateIdentity(ctx context.Context, client clients.Client) (clients.Client, error) {
|
||||
q := `UPDATE clients SET identity = :identity, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, name, tags, identity, metadata, public_metadata, COALESCE(domain_id, '') AS domain_id, status, COALESCE(parent_group_id, '') AS parent_group_id, created_at, updated_at, updated_by`
|
||||
RETURNING id, name, tags, identity, metadata, private_metadata, COALESCE(domain_id, '') AS domain_id, status, COALESCE(parent_group_id, '') AS parent_group_id, created_at, updated_at, updated_by`
|
||||
client.Status = clients.EnabledStatus
|
||||
return repo.update(ctx, client, q)
|
||||
}
|
||||
@@ -176,7 +176,7 @@ func (repo *clientRepo) UpdateIdentity(ctx context.Context, client clients.Clien
|
||||
func (repo *clientRepo) UpdateSecret(ctx context.Context, client clients.Client) (clients.Client, error) {
|
||||
q := `UPDATE clients SET secret = :secret, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, name, tags, identity, metadata, public_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`
|
||||
RETURNING id, name, tags, identity, metadata, private_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`
|
||||
client.Status = clients.EnabledStatus
|
||||
return repo.update(ctx, client, q)
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (repo *clientRepo) UpdateSecret(ctx context.Context, client clients.Client)
|
||||
func (repo *clientRepo) ChangeStatus(ctx context.Context, client clients.Client) (clients.Client, error) {
|
||||
q := `UPDATE clients SET status = :status, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id
|
||||
RETURNING id, name, tags, identity, metadata, public_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`
|
||||
RETURNING id, name, tags, identity, metadata, private_metadata, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, status, created_at, updated_at, updated_by`
|
||||
|
||||
return repo.update(ctx, client, q)
|
||||
}
|
||||
@@ -356,7 +356,7 @@ func (repo *clientRepo) RetrieveByIDWithRoles(ctx context.Context, id, memberID
|
||||
COALESCE(c2.parent_group_id, '') AS parent_group_id,
|
||||
c2."identity",
|
||||
c2.secret,
|
||||
c2.public_metadata,
|
||||
c2.metadata,
|
||||
c2.created_at,
|
||||
c2.updated_at,
|
||||
c2.updated_by,
|
||||
@@ -389,7 +389,7 @@ func (repo *clientRepo) RetrieveByIDWithRoles(ctx context.Context, id, memberID
|
||||
}
|
||||
|
||||
func (repo *clientRepo) RetrieveByID(ctx context.Context, id string) (clients.Client, error) {
|
||||
q := `SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, identity, secret, metadata, public_metadata, created_at, updated_at, updated_by, status
|
||||
q := `SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, identity, secret, metadata, private_metadata, created_at, updated_at, updated_by, status
|
||||
FROM clients WHERE id = :id`
|
||||
|
||||
dbc := DBClient{
|
||||
@@ -449,7 +449,7 @@ func (repo *clientRepo) RetrieveAll(ctx context.Context, pm clients.Page) (clien
|
||||
c.name,
|
||||
c.tags,
|
||||
c.identity,
|
||||
c.public_metadata,
|
||||
c.metadata,
|
||||
COALESCE(c.domain_id, '') AS domain_id,
|
||||
COALESCE(parent_group_id, '') AS parent_group_id,
|
||||
COALESCE((SELECT path FROM groups WHERE id = c.parent_group_id), ''::::ltree) AS parent_group_path,
|
||||
@@ -564,7 +564,7 @@ func (repo *clientRepo) retrieveClients(ctx context.Context, domainID, userID st
|
||||
c.identity,
|
||||
c.secret,
|
||||
c.tags,
|
||||
c.public_metadata,
|
||||
c.metadata,
|
||||
c.created_at,
|
||||
c.updated_at,
|
||||
c.updated_by,
|
||||
@@ -625,7 +625,7 @@ func (repo *clientRepo) retrieveClients(ctx context.Context, domainID, userID st
|
||||
c.identity,
|
||||
c.secret,
|
||||
c.tags,
|
||||
c.public_metadata,
|
||||
c.metadata,
|
||||
c.created_at,
|
||||
c.updated_at,
|
||||
c.updated_by,
|
||||
@@ -670,7 +670,7 @@ func (repo *clientRepo) userClientBaseQuery(domainID, userID string) string {
|
||||
c.domain_id,
|
||||
c.parent_group_id,
|
||||
c.tags,
|
||||
c.public_metadata,
|
||||
c.metadata,
|
||||
c.identity,
|
||||
c.secret,
|
||||
c.created_at,
|
||||
@@ -835,7 +835,7 @@ func (repo *clientRepo) userClientBaseQuery(domainID, userID string) string {
|
||||
c.domain_id,
|
||||
c.parent_group_id,
|
||||
c.tags,
|
||||
c.public_metadata,
|
||||
c.metadata,
|
||||
c.identity,
|
||||
c.secret,
|
||||
c.created_at,
|
||||
@@ -867,7 +867,7 @@ func (repo *clientRepo) userClientBaseQuery(domainID, userID string) string {
|
||||
gc.domain_id,
|
||||
gc.parent_group_id,
|
||||
gc.tags,
|
||||
gc.public_metadata,
|
||||
gc.metadata,
|
||||
gc.identity,
|
||||
gc.secret,
|
||||
gc.created_at,
|
||||
@@ -892,7 +892,7 @@ func (repo *clientRepo) userClientBaseQuery(domainID, userID string) string {
|
||||
dc.domain_id,
|
||||
dc.parent_group_id,
|
||||
dc.tags,
|
||||
dc.public_metadata,
|
||||
dc.metadata,
|
||||
dc.identity,
|
||||
dc.secret,
|
||||
dc.created_at,
|
||||
@@ -943,7 +943,7 @@ func (repo *clientRepo) SearchClients(ctx context.Context, pm clients.Page) (cli
|
||||
tq := query
|
||||
query = applyOrdering(query, pm)
|
||||
|
||||
q := fmt.Sprintf(`SELECT c.id, c.name, c.public_metadata, c.created_at, c.updated_at FROM clients c %s LIMIT :limit OFFSET :offset;`, query)
|
||||
q := fmt.Sprintf(`SELECT c.id, c.name, c.metadata, c.created_at, c.updated_at FROM clients c %s LIMIT :limit OFFSET :offset;`, query)
|
||||
|
||||
dbPage, err := ToDBClientsPage(pm)
|
||||
if err != nil {
|
||||
@@ -1039,7 +1039,7 @@ type DBClient struct {
|
||||
ParentGroup sql.NullString `db:"parent_group_id,omitempty"`
|
||||
Secret string `db:"secret"`
|
||||
Metadata []byte `db:"metadata,omitempty"`
|
||||
PublicMetadata []byte `db:"public_metadata,omitempty"`
|
||||
PrivateMetadata []byte `db:"private_metadata,omitempty"`
|
||||
CreatedAt time.Time `db:"created_at,omitempty"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at,omitempty"`
|
||||
UpdatedBy *string `db:"updated_by,omitempty"`
|
||||
@@ -1059,13 +1059,13 @@ type DBClient struct {
|
||||
}
|
||||
|
||||
func ToDBClient(c clients.Client) (DBClient, error) {
|
||||
publicMetadata := []byte("{}")
|
||||
if len(c.PublicMetadata) > 0 {
|
||||
b, err := json.Marshal(c.PublicMetadata)
|
||||
privateMetadata := []byte("{}")
|
||||
if len(c.PrivateMetadata) > 0 {
|
||||
b, err := json.Marshal(c.PrivateMetadata)
|
||||
if err != nil {
|
||||
return DBClient{}, errors.Wrap(repoerr.ErrMalformedEntity, err)
|
||||
}
|
||||
publicMetadata = b
|
||||
privateMetadata = b
|
||||
}
|
||||
metadata := []byte("{}")
|
||||
if len(c.Metadata) > 0 {
|
||||
@@ -1089,26 +1089,26 @@ func ToDBClient(c clients.Client) (DBClient, error) {
|
||||
}
|
||||
|
||||
return DBClient{
|
||||
ID: c.ID,
|
||||
Name: c.Name,
|
||||
Tags: tags,
|
||||
Domain: c.Domain,
|
||||
ParentGroup: toNullString(c.ParentGroup),
|
||||
Identity: c.Credentials.Identity,
|
||||
Secret: c.Credentials.Secret,
|
||||
Metadata: metadata,
|
||||
PublicMetadata: publicMetadata,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: updatedBy,
|
||||
Status: c.Status,
|
||||
ID: c.ID,
|
||||
Name: c.Name,
|
||||
Tags: tags,
|
||||
Domain: c.Domain,
|
||||
ParentGroup: toNullString(c.ParentGroup),
|
||||
Identity: c.Credentials.Identity,
|
||||
Secret: c.Credentials.Secret,
|
||||
Metadata: metadata,
|
||||
PrivateMetadata: privateMetadata,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: updatedBy,
|
||||
Status: c.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ToClient(t DBClient) (clients.Client, error) {
|
||||
var publicMetadata, metadata clients.Metadata
|
||||
if t.PublicMetadata != nil {
|
||||
if err := json.Unmarshal([]byte(t.PublicMetadata), &publicMetadata); err != nil {
|
||||
var privateMetadata, metadata clients.Metadata
|
||||
if t.PrivateMetadata != nil {
|
||||
if err := json.Unmarshal([]byte(t.PrivateMetadata), &privateMetadata); err != nil {
|
||||
return clients.Client{}, errors.Wrap(repoerr.ErrMalformedEntity, err)
|
||||
}
|
||||
}
|
||||
@@ -1160,7 +1160,7 @@ func ToClient(t DBClient) (clients.Client, error) {
|
||||
Secret: t.Secret,
|
||||
},
|
||||
Metadata: metadata,
|
||||
PublicMetadata: publicMetadata,
|
||||
PrivateMetadata: privateMetadata,
|
||||
CreatedAt: t.CreatedAt.UTC(),
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: updatedBy,
|
||||
@@ -1278,7 +1278,7 @@ func PageQuery(pm clients.Page) (string, error) {
|
||||
query = append(query, "c.actions @> :actions")
|
||||
}
|
||||
if len(pm.Metadata) > 0 {
|
||||
query = append(query, "c.public_metadata @> :metadata")
|
||||
query = append(query, "c.metadata @> :metadata")
|
||||
}
|
||||
|
||||
var emq string
|
||||
@@ -1343,7 +1343,7 @@ func (repo *clientRepo) RetrieveByIds(ctx context.Context, ids []string) (client
|
||||
return clients.ClientsPage{}, errors.Wrap(repoerr.ErrViewEntity, err)
|
||||
}
|
||||
|
||||
q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.public_metadata, COALESCE(c.domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, c.status,
|
||||
q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.metadata, COALESCE(c.domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, c.status,
|
||||
c.created_at, c.updated_at, COALESCE(c.updated_by, '') AS updated_by FROM clients c %s ORDER BY c.created_at`, query)
|
||||
|
||||
dbPage, err := ToDBClientsPage(pm)
|
||||
@@ -1508,7 +1508,7 @@ func (repo *clientRepo) RemoveClientConnections(ctx context.Context, clientID st
|
||||
}
|
||||
|
||||
func (repo *clientRepo) RetrieveParentGroupClients(ctx context.Context, parentGroupID string) ([]clients.Client, error) {
|
||||
query := `SELECT c.id, c.name, c.tags, c.public_metadata, COALESCE(c.domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, c.status,
|
||||
query := `SELECT c.id, c.name, c.tags, c.metadata, COALESCE(c.domain_id, '') AS domain_id, COALESCE(parent_group_id, '') AS parent_group_id, c.status,
|
||||
c.created_at, c.updated_at, COALESCE(c.updated_by, '') AS updated_by FROM clients c WHERE c.parent_group_id = :parent_group_id ;`
|
||||
|
||||
rows, err := repo.DB.NamedQueryContext(ctx, query, DBClient{ParentGroup: toNullString(parentGroupID)})
|
||||
|
||||
+130
-130
@@ -44,13 +44,13 @@ var (
|
||||
namegen = namegenerator.NewGenerator()
|
||||
validTimestamp = time.Now().UTC().Truncate(time.Millisecond)
|
||||
validClient = clients.Client{
|
||||
ID: testsutil.GenerateUUID(&testing.T{}),
|
||||
Domain: testsutil.GenerateUUID(&testing.T{}),
|
||||
Name: namegen.Generate(),
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
CreatedAt: time.Now().UTC().Truncate(time.Microsecond),
|
||||
Status: clients.EnabledStatus,
|
||||
ID: testsutil.GenerateUUID(&testing.T{}),
|
||||
Domain: testsutil.GenerateUUID(&testing.T{}),
|
||||
Name: namegen.Generate(),
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
CreatedAt: time.Now().UTC().Truncate(time.Microsecond),
|
||||
Status: clients.EnabledStatus,
|
||||
}
|
||||
invalidID = strings.Repeat("a", 37)
|
||||
directAccess = "direct"
|
||||
@@ -135,9 +135,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: clientIdentity,
|
||||
Secret: secret,
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
@@ -152,9 +152,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Credentials: clients.Credentials{
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
@@ -163,9 +163,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Credentials: clients.Credentials{
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
@@ -174,9 +174,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Credentials: clients.Credentials{
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
@@ -192,9 +192,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: clientIdentity,
|
||||
Secret: secret,
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: errClientSecretNotAvailable,
|
||||
@@ -209,9 +209,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Credentials: clients.Credentials{
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
@@ -221,9 +221,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: clientIdentity,
|
||||
Secret: secret,
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: errClientSecretNotAvailable,
|
||||
@@ -238,9 +238,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: "withoutdomain-client@example.com",
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
@@ -256,9 +256,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: "invalidid-client@example.com",
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: repoerr.ErrCreateEntity,
|
||||
@@ -273,9 +273,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Credentials: clients.Credentials{
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
{
|
||||
ID: invalidName,
|
||||
@@ -284,9 +284,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Credentials: clients.Credentials{
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: repoerr.ErrCreateEntity,
|
||||
@@ -302,9 +302,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: "invalidname-client@example.com",
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: repoerr.ErrCreateEntity,
|
||||
@@ -319,9 +319,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: "invaliddomainid-client@example.com",
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: repoerr.ErrCreateEntity,
|
||||
@@ -336,9 +336,9 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: invalidName,
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: repoerr.ErrCreateEntity,
|
||||
@@ -354,8 +354,8 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: "",
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
@@ -370,14 +370,14 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: "missing-client-secret@example.com",
|
||||
Secret: "",
|
||||
},
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "add a client with invalid public metadata",
|
||||
desc: "add a client with invalid private metadata",
|
||||
clients: []clients.Client{
|
||||
{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
@@ -386,7 +386,7 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: fmt.Sprintf("%s@example.com", namegen.Generate()),
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{
|
||||
PrivateMetadata: map[string]any{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -403,7 +403,7 @@ func TestClientsSave(t *testing.T) {
|
||||
Identity: fmt.Sprintf("%s@example.com", namegen.Generate()),
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: map[string]any{
|
||||
PrivateMetadata: map[string]any{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -414,13 +414,13 @@ func TestClientsSave(t *testing.T) {
|
||||
desc: "add client with duplicate name",
|
||||
clients: []clients.Client{
|
||||
{
|
||||
ID: duplicateClientID,
|
||||
Domain: validClient.Domain,
|
||||
Name: validClient.Name,
|
||||
PublicMetadata: map[string]any{"key": "different_value"},
|
||||
Metadata: map[string]any{},
|
||||
CreatedAt: validTimestamp,
|
||||
Status: clients.EnabledStatus,
|
||||
ID: duplicateClientID,
|
||||
Domain: validClient.Domain,
|
||||
Name: validClient.Name,
|
||||
PrivateMetadata: map[string]any{"key": "different_value"},
|
||||
Metadata: map[string]any{},
|
||||
CreatedAt: validTimestamp,
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
@@ -454,10 +454,10 @@ func TestClientsRetrieveBySecret(t *testing.T) {
|
||||
Identity: clientIdentity,
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
Domain: testsutil.GenerateUUID(t),
|
||||
PublicMetadata: clients.Metadata{},
|
||||
Metadata: clients.Metadata{},
|
||||
Status: clients.EnabledStatus,
|
||||
Domain: testsutil.GenerateUUID(t),
|
||||
Metadata: clients.Metadata{},
|
||||
PrivateMetadata: clients.Metadata{},
|
||||
Status: clients.EnabledStatus,
|
||||
}
|
||||
|
||||
_, err := repo.Save(context.Background(), client)
|
||||
@@ -546,7 +546,7 @@ func TestRetrieveByID(t *testing.T) {
|
||||
Identity: clientIdentity,
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: clients.Metadata{
|
||||
PrivateMetadata: clients.Metadata{
|
||||
"key": "value",
|
||||
},
|
||||
Metadata: clients.Metadata{
|
||||
@@ -590,7 +590,7 @@ func TestRetrieveByID(t *testing.T) {
|
||||
if err == nil {
|
||||
assert.Equal(t, client.ID, cli.ID)
|
||||
assert.Equal(t, client.Name, cli.Name)
|
||||
assert.Equal(t, client.PublicMetadata, cli.PublicMetadata)
|
||||
assert.Equal(t, client.PrivateMetadata, cli.PrivateMetadata)
|
||||
assert.Equal(t, client.Metadata, cli.Metadata)
|
||||
assert.Equal(t, client.Credentials.Identity, cli.Credentials.Identity)
|
||||
assert.Equal(t, client.Credentials.Secret, cli.Credentials.Secret)
|
||||
@@ -621,12 +621,12 @@ func TestUpdate(t *testing.T) {
|
||||
desc: "update client successfully",
|
||||
update: "all",
|
||||
client: clients.Client{
|
||||
ID: validClient.ID,
|
||||
Name: namegen.Generate(),
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
UpdatedAt: validTimestamp,
|
||||
UpdatedBy: testsutil.GenerateUUID(t),
|
||||
ID: validClient.ID,
|
||||
Name: namegen.Generate(),
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
UpdatedAt: validTimestamp,
|
||||
UpdatedBy: testsutil.GenerateUUID(t),
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
@@ -642,13 +642,13 @@ func TestUpdate(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "update client public metadata",
|
||||
update: "public_metadata",
|
||||
desc: "update client private metadata",
|
||||
update: "private_metadata",
|
||||
client: clients.Client{
|
||||
ID: validClient.ID,
|
||||
PublicMetadata: map[string]any{"key1": "value1"},
|
||||
UpdatedAt: validTimestamp,
|
||||
UpdatedBy: testsutil.GenerateUUID(t),
|
||||
ID: validClient.ID,
|
||||
PrivateMetadata: map[string]any{"key1": "value1"},
|
||||
UpdatedAt: validTimestamp,
|
||||
UpdatedBy: testsutil.GenerateUUID(t),
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
@@ -667,12 +667,12 @@ func TestUpdate(t *testing.T) {
|
||||
desc: "update client with invalid ID",
|
||||
update: "all",
|
||||
client: clients.Client{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Name: namegen.Generate(),
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
UpdatedAt: validTimestamp,
|
||||
UpdatedBy: testsutil.GenerateUUID(t),
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Name: namegen.Generate(),
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
UpdatedAt: validTimestamp,
|
||||
UpdatedBy: testsutil.GenerateUUID(t),
|
||||
},
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
@@ -680,11 +680,11 @@ func TestUpdate(t *testing.T) {
|
||||
desc: "update client with empty ID",
|
||||
update: "all",
|
||||
client: clients.Client{
|
||||
Name: namegen.Generate(),
|
||||
PublicMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
UpdatedAt: validTimestamp,
|
||||
UpdatedBy: testsutil.GenerateUUID(t),
|
||||
Name: namegen.Generate(),
|
||||
PrivateMetadata: map[string]any{"key": "value"},
|
||||
Metadata: map[string]any{"key": "value"},
|
||||
UpdatedAt: validTimestamp,
|
||||
UpdatedBy: testsutil.GenerateUUID(t),
|
||||
},
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
@@ -701,12 +701,12 @@ func TestUpdate(t *testing.T) {
|
||||
switch tc.update {
|
||||
case "all":
|
||||
assert.Equal(t, tc.client.Name, client.Name, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.client.Name, client.Name))
|
||||
assert.Equal(t, tc.client.PublicMetadata, client.PublicMetadata, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.client.PublicMetadata, client.PublicMetadata))
|
||||
assert.Equal(t, tc.client.PrivateMetadata, client.PrivateMetadata, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.client.PrivateMetadata, client.PrivateMetadata))
|
||||
assert.Equal(t, tc.client.Metadata, client.Metadata, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.client.Metadata, client.Metadata))
|
||||
case "name":
|
||||
assert.Equal(t, tc.client.Name, client.Name, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.client.Name, client.Name))
|
||||
case "public_metadata":
|
||||
assert.Equal(t, tc.client.PublicMetadata, client.PublicMetadata, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.client.PublicMetadata, client.PublicMetadata))
|
||||
case "private_metadata":
|
||||
assert.Equal(t, tc.client.PrivateMetadata, client.PrivateMetadata, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.client.PrivateMetadata, client.PrivateMetadata))
|
||||
case "metadata":
|
||||
assert.Equal(t, tc.client.Metadata, client.Metadata, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.client.Metadata, client.Metadata))
|
||||
}
|
||||
@@ -997,7 +997,7 @@ func TestRetrieveByIDsWithRoles(t *testing.T) {
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
Tags: namegen.GenerateMultiple(5),
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"department": namegen.Generate(),
|
||||
},
|
||||
Status: clients.EnabledStatus,
|
||||
@@ -1120,7 +1120,7 @@ func TestRetrieveAll(t *testing.T) {
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
Tags: namegen.GenerateMultiple(5),
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"department": namegen.Generate(),
|
||||
},
|
||||
Status: clients.EnabledStatus,
|
||||
@@ -1279,11 +1279,11 @@ func TestRetrieveAll(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "with public metadata",
|
||||
desc: "with metadata",
|
||||
pm: clients.Page{
|
||||
Offset: 0,
|
||||
Limit: nClients,
|
||||
Metadata: expectedClients[0].PublicMetadata,
|
||||
Metadata: expectedClients[0].Metadata,
|
||||
Status: clients.AllStatus,
|
||||
Order: defOrder,
|
||||
Dir: ascDir,
|
||||
@@ -1563,7 +1563,7 @@ func TestRetrieveAll(t *testing.T) {
|
||||
pm: clients.Page{
|
||||
Offset: 0,
|
||||
Limit: nClients,
|
||||
Metadata: expectedClients[0].PublicMetadata,
|
||||
Metadata: expectedClients[0].Metadata,
|
||||
Name: expectedClients[0].Name,
|
||||
Tag: expectedClients[0].Tags[0],
|
||||
Identity: expectedClients[0].Credentials.Identity,
|
||||
@@ -1829,7 +1829,7 @@ func TestRetrieveUserClients(t *testing.T) {
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
Tags: namegen.GenerateMultiple(5),
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"department": namegen.Generate(),
|
||||
},
|
||||
Status: clients.EnabledStatus,
|
||||
@@ -2036,7 +2036,7 @@ func TestRetrieveUserClients(t *testing.T) {
|
||||
pm: clients.Page{
|
||||
Offset: 0,
|
||||
Limit: nClients,
|
||||
Metadata: directClients[0].PublicMetadata,
|
||||
Metadata: directClients[0].Metadata,
|
||||
Status: clients.AllStatus,
|
||||
Order: defOrder,
|
||||
Dir: ascDir,
|
||||
@@ -2230,7 +2230,7 @@ func TestRetrieveUserClients(t *testing.T) {
|
||||
pm: clients.Page{
|
||||
Offset: 0,
|
||||
Limit: nClients,
|
||||
Metadata: directClients[0].PublicMetadata,
|
||||
Metadata: directClients[0].Metadata,
|
||||
Name: directClients[0].Name,
|
||||
Tag: directClients[0].Tags[0],
|
||||
Identity: directClients[0].Credentials.Identity,
|
||||
@@ -2693,21 +2693,21 @@ func TestSearchClients(t *testing.T) {
|
||||
Identity: username,
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"department": namegen.Generate(),
|
||||
},
|
||||
Metadata: clients.Metadata{},
|
||||
Status: clients.EnabledStatus,
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Microsecond),
|
||||
PrivateMetadata: clients.Metadata{},
|
||||
Status: clients.EnabledStatus,
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Microsecond),
|
||||
}
|
||||
_, err := repo.Save(context.Background(), client)
|
||||
require.Nil(t, err, fmt.Sprintf("save client unexpected error: %s", err))
|
||||
|
||||
expectedClients = append(expectedClients, clients.Client{
|
||||
ID: client.ID,
|
||||
Name: client.Name,
|
||||
PublicMetadata: client.PublicMetadata,
|
||||
CreatedAt: client.CreatedAt,
|
||||
ID: client.ID,
|
||||
Name: client.Name,
|
||||
Metadata: client.Metadata,
|
||||
CreatedAt: client.CreatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3078,10 +3078,10 @@ func TestRetrieveByIDs(t *testing.T) {
|
||||
Identity: name + emailSuffix,
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
Tags: namegen.GenerateMultiple(5),
|
||||
PublicMetadata: map[string]any{"name": name},
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Microsecond),
|
||||
Status: clients.EnabledStatus,
|
||||
Tags: namegen.GenerateMultiple(5),
|
||||
Metadata: map[string]any{"name": name},
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Microsecond),
|
||||
Status: clients.EnabledStatus,
|
||||
}
|
||||
_, err := repo.Save(context.Background(), client)
|
||||
require.Nil(t, err, fmt.Sprintf("add new client: expected nil got %s\n", err))
|
||||
@@ -3706,13 +3706,13 @@ func TestRetrieveParentGroupClients(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
name := namegen.Generate()
|
||||
client := clients.Client{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Domain: testsutil.GenerateUUID(t),
|
||||
ParentGroup: parentID,
|
||||
Name: name,
|
||||
PublicMetadata: map[string]any{"name": name},
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Microsecond),
|
||||
Status: clients.EnabledStatus,
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Domain: testsutil.GenerateUUID(t),
|
||||
ParentGroup: parentID,
|
||||
Name: name,
|
||||
Metadata: map[string]any{"name": name},
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Microsecond),
|
||||
Status: clients.EnabledStatus,
|
||||
}
|
||||
items = append(items, client)
|
||||
}
|
||||
@@ -3774,13 +3774,13 @@ func TestUnsetParentGroupFromClients(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
name := namegen.Generate()
|
||||
client := clients.Client{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Domain: testsutil.GenerateUUID(t),
|
||||
ParentGroup: parentID,
|
||||
Name: name,
|
||||
PublicMetadata: map[string]any{"name": name},
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Microsecond),
|
||||
Status: clients.EnabledStatus,
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Domain: testsutil.GenerateUUID(t),
|
||||
ParentGroup: parentID,
|
||||
Name: name,
|
||||
Metadata: map[string]any{"name": name},
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Microsecond),
|
||||
Status: clients.EnabledStatus,
|
||||
}
|
||||
items = append(items, client)
|
||||
}
|
||||
@@ -3827,7 +3827,7 @@ func generateClient(t *testing.T, status clients.Status, repo clients.Repository
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
Tags: namegen.GenerateMultiple(5),
|
||||
PublicMetadata: clients.Metadata{
|
||||
PrivateMetadata: clients.Metadata{
|
||||
"name": namegen.Generate(),
|
||||
},
|
||||
Metadata: clients.Metadata{
|
||||
|
||||
@@ -79,10 +79,10 @@ func Migration() (*migrate.MemoryMigrationSource, error) {
|
||||
{
|
||||
Id: "clients_04",
|
||||
Up: []string{
|
||||
`ALTER TABLE clients ADD COLUMN public_metadata JSONB;`,
|
||||
`ALTER TABLE clients ADD COLUMN private_metadata JSONB;`,
|
||||
},
|
||||
Down: []string{
|
||||
`ALTER TABLE clients DROP COLUMN public_metadata;`,
|
||||
`ALTER TABLE clients DROP COLUMN private_metadata;`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
+6
-6
@@ -166,12 +166,12 @@ func (svc service) ListUserClients(ctx context.Context, session authn.Session, u
|
||||
|
||||
func (svc service) Update(ctx context.Context, session authn.Session, cli Client) (Client, error) {
|
||||
client := Client{
|
||||
ID: cli.ID,
|
||||
Name: cli.Name,
|
||||
Metadata: cli.Metadata,
|
||||
PublicMetadata: cli.PublicMetadata,
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
ID: cli.ID,
|
||||
Name: cli.Name,
|
||||
Metadata: cli.Metadata,
|
||||
PrivateMetadata: cli.PrivateMetadata,
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
client, err := svc.repo.Update(ctx, client)
|
||||
if err != nil {
|
||||
|
||||
+21
-21
@@ -33,22 +33,22 @@ var (
|
||||
validMetadata = clients.Metadata{"role": "client"}
|
||||
ID = "6e5e10b3-d4df-4758-b426-4929d55ad740"
|
||||
client = clients.Client{
|
||||
ID: ID,
|
||||
Name: "clientname",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Credentials: clients.Credentials{Identity: "clientidentity", Secret: secret},
|
||||
PublicMetadata: validMetadata,
|
||||
Metadata: validMetadata,
|
||||
Status: clients.EnabledStatus,
|
||||
ID: ID,
|
||||
Name: "clientname",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Credentials: clients.Credentials{Identity: "clientidentity", Secret: secret},
|
||||
PrivateMetadata: validMetadata,
|
||||
Metadata: validMetadata,
|
||||
Status: clients.EnabledStatus,
|
||||
}
|
||||
clientWithRoles = clients.Client{
|
||||
ID: ID,
|
||||
Name: "clientname",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Credentials: clients.Credentials{Identity: "clientidentity", Secret: secret},
|
||||
PublicMetadata: validMetadata,
|
||||
Metadata: validMetadata,
|
||||
Status: clients.EnabledStatus,
|
||||
ID: ID,
|
||||
Name: "clientname",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Credentials: clients.Credentials{Identity: "clientidentity", Secret: secret},
|
||||
PrivateMetadata: validMetadata,
|
||||
Metadata: validMetadata,
|
||||
Status: clients.EnabledStatus,
|
||||
Roles: []roles.MemberRoleActions{
|
||||
{
|
||||
RoleID: "test_role_id",
|
||||
@@ -189,14 +189,14 @@ func TestCreateClients(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "create a new enabled client with public metadata",
|
||||
desc: "create a new enabled client with private metadata",
|
||||
client: clients.Client{
|
||||
Credentials: clients.Credentials{
|
||||
Identity: "newclientwithmetadata@example.com",
|
||||
Secret: secret,
|
||||
},
|
||||
PublicMetadata: validMetadata,
|
||||
Status: clients.EnabledStatus,
|
||||
PrivateMetadata: validMetadata,
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
token: validToken,
|
||||
err: nil,
|
||||
@@ -215,13 +215,13 @@ func TestCreateClients(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "create a new disabled client with public metadata",
|
||||
desc: "create a new disabled client with private metadata",
|
||||
client: clients.Client{
|
||||
Credentials: clients.Credentials{
|
||||
Identity: "newclientwithmetadata@example.com",
|
||||
Secret: secret,
|
||||
},
|
||||
PublicMetadata: validMetadata,
|
||||
PrivateMetadata: validMetadata,
|
||||
},
|
||||
token: validToken,
|
||||
err: nil,
|
||||
@@ -258,7 +258,7 @@ func TestCreateClients(t *testing.T) {
|
||||
Identity: "newclientwithallfields@example.com",
|
||||
Secret: secret,
|
||||
},
|
||||
PublicMetadata: clients.Metadata{
|
||||
PrivateMetadata: clients.Metadata{
|
||||
"name": "newclientwithallfields",
|
||||
},
|
||||
Metadata: clients.Metadata{
|
||||
@@ -610,7 +610,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
client1 := client
|
||||
client2 := client
|
||||
client1.Name = "Updated client"
|
||||
client2.PublicMetadata = clients.Metadata{"role": "test"}
|
||||
client2.PrivateMetadata = clients.Metadata{"role": "test"}
|
||||
client2.Metadata = clients.Metadata{"role": "test"}
|
||||
|
||||
cases := []struct {
|
||||
|
||||
@@ -35,7 +35,7 @@ message User {
|
||||
string last_name = 3;
|
||||
repeated string tags = 4;
|
||||
google.protobuf.Struct metadata = 5;
|
||||
google.protobuf.Struct public_metadata = 6;
|
||||
google.protobuf.Struct private_metadata = 6;
|
||||
uint32 status = 7;
|
||||
uint32 role = 8;
|
||||
string profile_picture = 9;
|
||||
|
||||
@@ -95,9 +95,9 @@ func ToClient(data map[string]any) (clients.Client, error) {
|
||||
c.Metadata = meta
|
||||
}
|
||||
|
||||
pmeta, ok := data["public_metadata"].(map[string]any)
|
||||
pmeta, ok := data["private_metadata"].(map[string]any)
|
||||
if ok {
|
||||
c.PublicMetadata = pmeta
|
||||
c.PrivateMetadata = pmeta
|
||||
}
|
||||
|
||||
uby, ok := data["updated_by"].(string)
|
||||
|
||||
@@ -31,6 +31,9 @@ var (
|
||||
// ErrFailedOpDB indicates a failure in a database operation.
|
||||
ErrFailedOpDB = errors.New("operation on db element failed")
|
||||
|
||||
// ErrRetrieveAllUsers failed to retrieve users.
|
||||
ErrRetrieveAllUsers = errors.New("failed to retrieve all users")
|
||||
|
||||
// ErrFailedToRetrieveAllGroups failed to retrieve groups.
|
||||
ErrFailedToRetrieveAllGroups = errors.New("failed to retrieve all groups")
|
||||
|
||||
|
||||
+14
-14
@@ -27,20 +27,20 @@ const (
|
||||
|
||||
// Client represents supermq client.
|
||||
type Client struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
DomainID string `json:"domain_id,omitempty"`
|
||||
ParentGroup string `json:"parent_group_id,omitempty"`
|
||||
Credentials ClientCredentials `json:"credentials"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
PublicMetadata map[string]any `json:"public_metadata,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
UpdatedBy string `json:"updated_by,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Permissions []string `json:"permissions,omitempty"`
|
||||
Roles []roles.MemberRoleActions `json:"roles,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
DomainID string `json:"domain_id,omitempty"`
|
||||
ParentGroup string `json:"parent_group_id,omitempty"`
|
||||
Credentials ClientCredentials `json:"credentials"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
PrivateMetadata map[string]any `json:"private_metadata,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
UpdatedBy string `json:"updated_by,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Permissions []string `json:"permissions,omitempty"`
|
||||
Roles []roles.MemberRoleActions `json:"roles,omitempty"`
|
||||
}
|
||||
|
||||
type ClientCredentials struct {
|
||||
|
||||
+47
-43
@@ -51,12 +51,12 @@ func TestCreateClient(t *testing.T) {
|
||||
|
||||
client := generateTestClient(t, false)
|
||||
createClientReq := sdk.Client{
|
||||
Name: client.Name,
|
||||
Tags: client.Tags,
|
||||
Credentials: client.Credentials,
|
||||
Metadata: client.Metadata,
|
||||
PublicMetadata: client.PublicMetadata,
|
||||
Status: client.Status,
|
||||
Name: client.Name,
|
||||
Tags: client.Tags,
|
||||
Credentials: client.Credentials,
|
||||
Metadata: client.Metadata,
|
||||
PrivateMetadata: client.PrivateMetadata,
|
||||
Status: client.Status,
|
||||
}
|
||||
|
||||
conf := sdk.Config{
|
||||
@@ -127,12 +127,12 @@ func TestCreateClient(t *testing.T) {
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
createClientReq: sdk.Client{
|
||||
Name: strings.Repeat("a", 1025),
|
||||
Tags: client.Tags,
|
||||
Credentials: client.Credentials,
|
||||
PublicMetadata: client.PublicMetadata,
|
||||
Metadata: client.Metadata,
|
||||
Status: client.Status,
|
||||
Name: strings.Repeat("a", 1025),
|
||||
Tags: client.Tags,
|
||||
Credentials: client.Credentials,
|
||||
PrivateMetadata: client.PrivateMetadata,
|
||||
Metadata: client.Metadata,
|
||||
Status: client.Status,
|
||||
},
|
||||
svcReq: clients.Client{},
|
||||
svcRes: []clients.Client{},
|
||||
@@ -145,13 +145,13 @@ func TestCreateClient(t *testing.T) {
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
createClientReq: sdk.Client{
|
||||
ID: "123456789",
|
||||
Name: client.Name,
|
||||
Tags: client.Tags,
|
||||
Credentials: client.Credentials,
|
||||
PublicMetadata: client.PublicMetadata,
|
||||
Metadata: client.Metadata,
|
||||
Status: client.Status,
|
||||
ID: "123456789",
|
||||
Name: client.Name,
|
||||
Tags: client.Tags,
|
||||
Credentials: client.Credentials,
|
||||
PrivateMetadata: client.PrivateMetadata,
|
||||
Metadata: client.Metadata,
|
||||
Status: client.Status,
|
||||
},
|
||||
svcReq: clients.Client{},
|
||||
svcRes: []clients.Client{},
|
||||
@@ -165,7 +165,7 @@ func TestCreateClient(t *testing.T) {
|
||||
token: validToken,
|
||||
createClientReq: sdk.Client{
|
||||
Name: valid,
|
||||
PublicMetadata: map[string]any{
|
||||
PrivateMetadata: map[string]any{
|
||||
valid: make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -185,7 +185,7 @@ func TestCreateClient(t *testing.T) {
|
||||
Name: client.Name,
|
||||
Tags: client.Tags,
|
||||
Credentials: clients.Credentials(client.Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
PrivateMetadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
}},
|
||||
@@ -279,7 +279,7 @@ func TestCreateClients(t *testing.T) {
|
||||
desc: "create new clients with a request that can't be marshalled",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
createClientsRequest: []sdk.Client{{Name: "test", PublicMetadata: map[string]any{"test": make(chan int)}}},
|
||||
createClientsRequest: []sdk.Client{{Name: "test", PrivateMetadata: map[string]any{"test": make(chan int)}}},
|
||||
svcReq: convertClients(sdkClients...),
|
||||
svcRes: []clients.Client{},
|
||||
svcErr: nil,
|
||||
@@ -296,7 +296,7 @@ func TestCreateClients(t *testing.T) {
|
||||
Name: sdkClients[0].Name,
|
||||
Tags: sdkClients[0].Tags,
|
||||
Credentials: clients.Credentials(sdkClients[0].Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
PrivateMetadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
}},
|
||||
@@ -562,7 +562,7 @@ func TestListClients(t *testing.T) {
|
||||
Name: sdkClients[0].Name,
|
||||
Tags: sdkClients[0].Tags,
|
||||
Credentials: clients.Credentials(sdkClients[0].Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
PrivateMetadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
}},
|
||||
@@ -698,7 +698,7 @@ func TestViewClient(t *testing.T) {
|
||||
Name: sdkClient.Name,
|
||||
Tags: sdkClient.Tags,
|
||||
Credentials: clients.Credentials(sdkClient.Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
PrivateMetadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -745,13 +745,17 @@ func TestUpdateClient(t *testing.T) {
|
||||
sdkClient := generateTestClient(t, false)
|
||||
updatedClient := sdkClient
|
||||
updatedClient.Name = "newName"
|
||||
updatedClient.PublicMetadata = map[string]any{
|
||||
updatedClient.Metadata = map[string]any{
|
||||
"newKey": "newValue",
|
||||
}
|
||||
updatedClient.PrivateMetadata = map[string]any{
|
||||
"privateKey": "privateValue",
|
||||
}
|
||||
updateClientReq := sdk.Client{
|
||||
ID: sdkClient.ID,
|
||||
Name: updatedClient.Name,
|
||||
PublicMetadata: updatedClient.PublicMetadata,
|
||||
ID: sdkClient.ID,
|
||||
Name: updatedClient.Name,
|
||||
Metadata: updatedClient.Metadata,
|
||||
PrivateMetadata: updatedClient.PrivateMetadata,
|
||||
}
|
||||
|
||||
conf := sdk.Config{
|
||||
@@ -847,7 +851,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
|
||||
updateClientReq: sdk.Client{
|
||||
ID: valid,
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -867,7 +871,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
Name: updatedClient.Name,
|
||||
Tags: updatedClient.Tags,
|
||||
Credentials: clients.Credentials(updatedClient.Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -999,7 +1003,7 @@ func TestUpdateClientTags(t *testing.T) {
|
||||
token: validToken,
|
||||
updateClientReq: sdk.Client{
|
||||
ID: valid,
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1019,7 +1023,7 @@ func TestUpdateClientTags(t *testing.T) {
|
||||
Name: updatedClient.Name,
|
||||
Tags: updatedClient.Tags,
|
||||
Credentials: clients.Credentials(updatedClient.Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1151,7 +1155,7 @@ func TestUpdateClientSecret(t *testing.T) {
|
||||
Name: updatedClient.Name,
|
||||
Tags: updatedClient.Tags,
|
||||
Credentials: clients.Credentials(updatedClient.Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1254,7 +1258,7 @@ func TestEnableClient(t *testing.T) {
|
||||
Name: enabledClient.Name,
|
||||
Tags: enabledClient.Tags,
|
||||
Credentials: clients.Credentials(enabledClient.Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1357,7 +1361,7 @@ func TestDisableClient(t *testing.T) {
|
||||
Name: disabledClient.Name,
|
||||
Tags: disabledClient.Tags,
|
||||
Credentials: clients.Credentials(disabledClient.Credentials),
|
||||
PublicMetadata: clients.Metadata{
|
||||
Metadata: clients.Metadata{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -3271,12 +3275,12 @@ func generateTestClient(t *testing.T, withRoles bool) sdk.Client {
|
||||
Identity: "client@example.com",
|
||||
Secret: generateUUID(t),
|
||||
},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Metadata: validMetadata,
|
||||
PublicMetadata: validMetadata,
|
||||
Status: clients.EnabledStatus.String(),
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
Roles: rl,
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Metadata: validMetadata,
|
||||
PrivateMetadata: validMetadata,
|
||||
Status: clients.EnabledStatus.String(),
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
Roles: rl,
|
||||
}
|
||||
}
|
||||
|
||||
+33
-33
@@ -165,19 +165,19 @@ func convertUser(c sdk.User) users.User {
|
||||
return users.User{}
|
||||
}
|
||||
return users.User{
|
||||
ID: c.ID,
|
||||
FirstName: c.FirstName,
|
||||
LastName: c.LastName,
|
||||
Tags: c.Tags,
|
||||
Email: c.Email,
|
||||
Credentials: users.Credentials(c.Credentials),
|
||||
Metadata: users.Metadata(c.Metadata),
|
||||
PublicMetadata: users.Metadata(c.PublicMetadata),
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
Status: status,
|
||||
Role: role,
|
||||
ProfilePicture: c.ProfilePicture,
|
||||
ID: c.ID,
|
||||
FirstName: c.FirstName,
|
||||
LastName: c.LastName,
|
||||
Tags: c.Tags,
|
||||
Email: c.Email,
|
||||
Credentials: users.Credentials(c.Credentials),
|
||||
Metadata: users.Metadata(c.Metadata),
|
||||
PrivateMetadata: users.Metadata(c.PrivateMetadata),
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
Status: status,
|
||||
Role: role,
|
||||
ProfilePicture: c.ProfilePicture,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,19 +190,19 @@ func convertClient(c sdk.Client) clients.Client {
|
||||
return clients.Client{}
|
||||
}
|
||||
return clients.Client{
|
||||
ID: c.ID,
|
||||
Name: c.Name,
|
||||
Tags: c.Tags,
|
||||
Domain: c.DomainID,
|
||||
ParentGroup: c.ParentGroup,
|
||||
Credentials: clients.Credentials(c.Credentials),
|
||||
Metadata: clients.Metadata(c.Metadata),
|
||||
PublicMetadata: clients.Metadata(c.PublicMetadata),
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
UpdatedBy: c.UpdatedBy,
|
||||
Status: status,
|
||||
Roles: c.Roles,
|
||||
ID: c.ID,
|
||||
Name: c.Name,
|
||||
Tags: c.Tags,
|
||||
Domain: c.DomainID,
|
||||
ParentGroup: c.ParentGroup,
|
||||
Credentials: clients.Credentials(c.Credentials),
|
||||
Metadata: clients.Metadata(c.Metadata),
|
||||
PrivateMetadata: clients.Metadata(c.PrivateMetadata),
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
UpdatedBy: c.UpdatedBy,
|
||||
Status: status,
|
||||
Roles: c.Roles,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,13 +267,13 @@ func generateTestUser(t *testing.T) sdk.User {
|
||||
Username: "username",
|
||||
Secret: secret,
|
||||
},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Metadata: validMetadata,
|
||||
PublicMetadata: validMetadata,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: createdAt,
|
||||
Status: users.EnabledStatus.String(),
|
||||
Role: users.UserRole.String(),
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Metadata: validMetadata,
|
||||
PrivateMetadata: validMetadata,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: createdAt,
|
||||
Status: users.EnabledStatus.String(),
|
||||
Role: users.UserRole.String(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -29,20 +29,20 @@ const (
|
||||
|
||||
// User represents supermq user its credentials.
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
FirstName string `json:"first_name,omitempty"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Credentials Credentials `json:"credentials"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
PublicMetadata Metadata `json:"public_metadata,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Role string `json:"role,omitempty"`
|
||||
ProfilePicture string `json:"profile_picture,omitempty"`
|
||||
AuthProvider string `json:"auth_provider,omitempty"`
|
||||
ID string `json:"id"`
|
||||
FirstName string `json:"first_name,omitempty"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Credentials Credentials `json:"credentials"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
PrivateMetadata Metadata `json:"private_metadata,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Role string `json:"role,omitempty"`
|
||||
ProfilePicture string `json:"profile_picture,omitempty"`
|
||||
AuthProvider string `json:"auth_provider,omitempty"`
|
||||
}
|
||||
|
||||
func (sdk mgSDK) CreateUser(ctx context.Context, user User, token string) (User, errors.SDKError) {
|
||||
|
||||
+45
-45
@@ -56,14 +56,14 @@ func TestCreateUser(t *testing.T) {
|
||||
defer ts.Close()
|
||||
|
||||
createSdkUserReq := sdk.User{
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
Email: user.Email,
|
||||
Tags: user.Tags,
|
||||
Credentials: user.Credentials,
|
||||
Metadata: user.Metadata,
|
||||
PublicMetadata: user.PublicMetadata,
|
||||
Status: user.Status,
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
Email: user.Email,
|
||||
Tags: user.Tags,
|
||||
Credentials: user.Credentials,
|
||||
Metadata: user.Metadata,
|
||||
PrivateMetadata: user.PrivateMetadata,
|
||||
Status: user.Status,
|
||||
}
|
||||
|
||||
conf := sdk.Config{
|
||||
@@ -143,11 +143,11 @@ func TestCreateUser(t *testing.T) {
|
||||
desc: "register user with first name too long",
|
||||
token: validToken,
|
||||
createSdkUserReq: sdk.User{
|
||||
FirstName: strings.Repeat("a", 1025),
|
||||
Credentials: createSdkUserReq.Credentials,
|
||||
PublicMetadata: createSdkUserReq.PublicMetadata,
|
||||
Metadata: createSdkUserReq.Metadata,
|
||||
Tags: createSdkUserReq.Tags,
|
||||
FirstName: strings.Repeat("a", 1025),
|
||||
Credentials: createSdkUserReq.Credentials,
|
||||
PrivateMetadata: createSdkUserReq.PrivateMetadata,
|
||||
Metadata: createSdkUserReq.Metadata,
|
||||
Tags: createSdkUserReq.Tags,
|
||||
},
|
||||
svcReq: users.User{},
|
||||
svcRes: users.User{},
|
||||
@@ -166,9 +166,9 @@ func TestCreateUser(t *testing.T) {
|
||||
Username: "",
|
||||
Secret: createSdkUserReq.Credentials.Secret,
|
||||
},
|
||||
PublicMetadata: createSdkUserReq.PublicMetadata,
|
||||
Metadata: createSdkUserReq.Metadata,
|
||||
Tags: createSdkUserReq.Tags,
|
||||
PrivateMetadata: createSdkUserReq.PrivateMetadata,
|
||||
Metadata: createSdkUserReq.Metadata,
|
||||
Tags: createSdkUserReq.Tags,
|
||||
},
|
||||
svcReq: users.User{},
|
||||
svcRes: users.User{},
|
||||
@@ -187,9 +187,9 @@ func TestCreateUser(t *testing.T) {
|
||||
Username: createSdkUserReq.Credentials.Username,
|
||||
Secret: "",
|
||||
},
|
||||
PublicMetadata: createSdkUserReq.PublicMetadata,
|
||||
Metadata: createSdkUserReq.Metadata,
|
||||
Tags: createSdkUserReq.Tags,
|
||||
PrivateMetadata: createSdkUserReq.PrivateMetadata,
|
||||
Metadata: createSdkUserReq.Metadata,
|
||||
Tags: createSdkUserReq.Tags,
|
||||
},
|
||||
svcReq: users.User{},
|
||||
svcRes: users.User{},
|
||||
@@ -208,9 +208,9 @@ func TestCreateUser(t *testing.T) {
|
||||
Username: createSdkUserReq.Credentials.Username,
|
||||
Secret: "weak",
|
||||
},
|
||||
PublicMetadata: createSdkUserReq.PublicMetadata,
|
||||
Metadata: createSdkUserReq.Metadata,
|
||||
Tags: createSdkUserReq.Tags,
|
||||
PrivateMetadata: createSdkUserReq.PrivateMetadata,
|
||||
Metadata: createSdkUserReq.Metadata,
|
||||
Tags: createSdkUserReq.Tags,
|
||||
},
|
||||
svcReq: users.User{},
|
||||
svcRes: users.User{},
|
||||
@@ -229,7 +229,7 @@ func TestCreateUser(t *testing.T) {
|
||||
FirstName: createSdkUserReq.FirstName,
|
||||
LastName: createSdkUserReq.LastName,
|
||||
Email: createSdkUserReq.Email,
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -253,7 +253,7 @@ func TestCreateUser(t *testing.T) {
|
||||
Username: createSdkUserReq.Credentials.Username,
|
||||
Secret: createSdkUserReq.Credentials.Secret,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -295,9 +295,9 @@ func TestListUsers(t *testing.T) {
|
||||
Username: fmt.Sprintf("Username_%d", i),
|
||||
Secret: fmt.Sprintf("password_%d", i),
|
||||
},
|
||||
PublicMetadata: sdk.Metadata{"name": fmt.Sprintf("user_%d", i)},
|
||||
Status: users.EnabledStatus.String(),
|
||||
Role: users.UserRole.String(),
|
||||
Metadata: sdk.Metadata{"name": fmt.Sprintf("user_%d", i)},
|
||||
Status: users.EnabledStatus.String(),
|
||||
Role: users.UserRole.String(),
|
||||
}
|
||||
if i == 50 {
|
||||
cl.Status = users.DisabledStatus.String()
|
||||
@@ -551,7 +551,7 @@ func TestListUsers(t *testing.T) {
|
||||
{
|
||||
ID: id,
|
||||
FirstName: "user_99",
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -605,9 +605,9 @@ func TestSearchUsers(t *testing.T) {
|
||||
Username: fmt.Sprintf("Username_%d", i),
|
||||
Secret: fmt.Sprintf("password_%d", i),
|
||||
},
|
||||
PublicMetadata: sdk.Metadata{"name": fmt.Sprintf("user_%d", i)},
|
||||
Status: users.EnabledStatus.String(),
|
||||
Role: users.UserRole.String(),
|
||||
Metadata: sdk.Metadata{"name": fmt.Sprintf("user_%d", i)},
|
||||
Status: users.EnabledStatus.String(),
|
||||
Role: users.UserRole.String(),
|
||||
}
|
||||
if i == 50 {
|
||||
cl.Status = users.DisabledStatus.String()
|
||||
@@ -787,7 +787,7 @@ func TestViewUser(t *testing.T) {
|
||||
ID: id,
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -866,7 +866,7 @@ func TestUserProfile(t *testing.T) {
|
||||
svcRes: users.User{
|
||||
ID: id,
|
||||
FirstName: user.FirstName,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1006,7 +1006,7 @@ func TestUpdateUser(t *testing.T) {
|
||||
token: validToken,
|
||||
updateUserReq: sdk.User{
|
||||
ID: generateUUID(t),
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1030,7 +1030,7 @@ func TestUpdateUser(t *testing.T) {
|
||||
svcRes: users.User{
|
||||
ID: id,
|
||||
FirstName: updatedName,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1167,7 +1167,7 @@ func TestUpdateUserTags(t *testing.T) {
|
||||
token: validToken,
|
||||
updateUserReq: sdk.User{
|
||||
ID: generateUUID(t),
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1191,7 +1191,7 @@ func TestUpdateUserTags(t *testing.T) {
|
||||
svcRes: users.User{
|
||||
ID: id,
|
||||
Tags: updatedTags,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1339,7 +1339,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
svcRes: users.User{
|
||||
ID: id,
|
||||
FirstName: updatedEmail,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1635,7 +1635,7 @@ func TestUpdatePassword(t *testing.T) {
|
||||
svcRes: users.User{
|
||||
ID: id,
|
||||
FirstName: user.FirstName,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1769,7 +1769,7 @@ func TestUpdateUserRole(t *testing.T) {
|
||||
token: validToken,
|
||||
updateUserReq: sdk.User{
|
||||
ID: generateUUID(t),
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1793,7 +1793,7 @@ func TestUpdateUserRole(t *testing.T) {
|
||||
svcRes: users.User{
|
||||
ID: id,
|
||||
Role: users.AdminRole,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -1957,7 +1957,7 @@ func TestUpdateUsername(t *testing.T) {
|
||||
Credentials: users.Credentials{
|
||||
Username: updatedUsername,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -2097,7 +2097,7 @@ func TestUpdateProfilePicture(t *testing.T) {
|
||||
token: validToken,
|
||||
updateUserReq: sdk.User{
|
||||
ID: generateUUID(t),
|
||||
PublicMetadata: map[string]any{
|
||||
Metadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -2120,7 +2120,7 @@ func TestUpdateProfilePicture(t *testing.T) {
|
||||
},
|
||||
svcRes: users.User{
|
||||
ID: id,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -2298,7 +2298,7 @@ func TestDisableUser(t *testing.T) {
|
||||
svcRes: users.User{
|
||||
ID: id,
|
||||
Status: users.DisabledStatus,
|
||||
PublicMetadata: users.Metadata{
|
||||
Metadata: users.Metadata{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
|
||||
+24
-23
@@ -37,15 +37,15 @@ var (
|
||||
secret = "strongsecret"
|
||||
validCMetadata = users.Metadata{"role": "user"}
|
||||
user = users.User{
|
||||
ID: testsutil.GenerateUUID(&testing.T{}),
|
||||
LastName: "doe",
|
||||
FirstName: "jane",
|
||||
Tags: []string{"foo", "bar"},
|
||||
Email: "useremail@example.com",
|
||||
Credentials: users.Credentials{Username: "username", Secret: secret},
|
||||
PublicMetadata: validCMetadata,
|
||||
Metadata: validCMetadata,
|
||||
Status: users.EnabledStatus,
|
||||
ID: testsutil.GenerateUUID(&testing.T{}),
|
||||
LastName: "doe",
|
||||
FirstName: "jane",
|
||||
Tags: []string{"foo", "bar"},
|
||||
Email: "useremail@example.com",
|
||||
Credentials: users.Credentials{Username: "username", Secret: secret},
|
||||
Metadata: validCMetadata,
|
||||
PrivateMetadata: validCMetadata,
|
||||
Status: users.EnabledStatus,
|
||||
}
|
||||
validToken = "valid"
|
||||
inValidToken = "invalid"
|
||||
@@ -146,7 +146,7 @@ func TestRegister(t *testing.T) {
|
||||
Credentials: users.Credentials{
|
||||
Secret: "12345678",
|
||||
},
|
||||
PublicMetadata: map[string]any{
|
||||
PrivateMetadata: map[string]any{
|
||||
"test": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -918,14 +918,15 @@ func TestUpdate(t *testing.T) {
|
||||
{
|
||||
desc: "update as admin user with valid token",
|
||||
id: user.ID,
|
||||
data: fmt.Sprintf(`{"name":"%s","public_metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","metadata":%s, "private_metadata":%s}`, newName, toJSON(newMetadata), toJSON(newMetadata)),
|
||||
token: validToken,
|
||||
authnRes: verifiedSession,
|
||||
contentType: contentType,
|
||||
userResponse: users.User{
|
||||
ID: user.ID,
|
||||
FirstName: newName,
|
||||
PublicMetadata: newMetadata,
|
||||
ID: user.ID,
|
||||
FirstName: newName,
|
||||
Metadata: newMetadata,
|
||||
PrivateMetadata: newMetadata,
|
||||
},
|
||||
status: http.StatusOK,
|
||||
err: nil,
|
||||
@@ -933,14 +934,14 @@ func TestUpdate(t *testing.T) {
|
||||
{
|
||||
desc: "update as normal user with valid token",
|
||||
id: user.ID,
|
||||
data: fmt.Sprintf(`{"name":"%s","public_metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
token: validToken,
|
||||
authnRes: verifiedSession,
|
||||
contentType: contentType,
|
||||
userResponse: users.User{
|
||||
ID: user.ID,
|
||||
FirstName: newName,
|
||||
PublicMetadata: newMetadata,
|
||||
ID: user.ID,
|
||||
FirstName: newName,
|
||||
Metadata: newMetadata,
|
||||
},
|
||||
status: http.StatusOK,
|
||||
err: nil,
|
||||
@@ -948,7 +949,7 @@ func TestUpdate(t *testing.T) {
|
||||
{
|
||||
desc: "update user with invalid token",
|
||||
id: user.ID,
|
||||
data: fmt.Sprintf(`{"name":"%s","public_metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
token: inValidToken,
|
||||
authnRes: smqauthn.Session{UserID: validID, DomainID: validID, Verified: true},
|
||||
contentType: contentType,
|
||||
@@ -959,7 +960,7 @@ func TestUpdate(t *testing.T) {
|
||||
{
|
||||
desc: "update user with empty token",
|
||||
id: user.ID,
|
||||
data: fmt.Sprintf(`{"name":"%s","public_metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
token: "",
|
||||
authnRes: smqauthn.Session{UserID: validID, DomainID: validID, Verified: true},
|
||||
contentType: contentType,
|
||||
@@ -970,7 +971,7 @@ func TestUpdate(t *testing.T) {
|
||||
{
|
||||
desc: "update user with invalid id",
|
||||
id: inValid,
|
||||
data: fmt.Sprintf(`{"name":"%s","public_metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
token: validToken,
|
||||
authnRes: verifiedSession,
|
||||
contentType: contentType,
|
||||
@@ -980,7 +981,7 @@ func TestUpdate(t *testing.T) {
|
||||
{
|
||||
desc: "update user with invalid contentype",
|
||||
id: user.ID,
|
||||
data: fmt.Sprintf(`{"name":"%s","public_metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
token: validToken,
|
||||
authnRes: verifiedSession,
|
||||
contentType: "application/xml",
|
||||
@@ -1000,7 +1001,7 @@ func TestUpdate(t *testing.T) {
|
||||
{
|
||||
desc: "update user with empty id",
|
||||
id: " ",
|
||||
data: fmt.Sprintf(`{"name":"%s","public_metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
data: fmt.Sprintf(`{"name":"%s","metadata":%s}`, newName, toJSON(newMetadata)),
|
||||
token: validToken,
|
||||
authnRes: verifiedSession,
|
||||
contentType: contentType,
|
||||
|
||||
@@ -209,10 +209,10 @@ func updateEndpoint(svc users.Service) endpoint.Endpoint {
|
||||
}
|
||||
|
||||
usr := users.UserReq{
|
||||
FirstName: req.FirstName,
|
||||
LastName: req.LastName,
|
||||
Metadata: req.Metadata,
|
||||
PublicMetadata: req.PublicMetadata,
|
||||
FirstName: req.FirstName,
|
||||
LastName: req.LastName,
|
||||
Metadata: req.Metadata,
|
||||
PrivateMetadata: req.PrivateMetadata,
|
||||
}
|
||||
|
||||
user, err := svc.Update(ctx, session, req.id, usr)
|
||||
|
||||
+12
-12
@@ -110,21 +110,21 @@ func userFromProto(u *grpcUsersV1.User) (users.User, error) {
|
||||
if u.GetMetadata() != nil {
|
||||
metadata = users.Metadata(u.GetMetadata().AsMap())
|
||||
}
|
||||
publicMetadata := users.Metadata(nil)
|
||||
if u.GetPublicMetadata() != nil {
|
||||
publicMetadata = users.Metadata(u.GetPublicMetadata().AsMap())
|
||||
privateMetadata := users.Metadata(nil)
|
||||
if u.GetPrivateMetadata() != nil {
|
||||
privateMetadata = users.Metadata(u.GetPrivateMetadata().AsMap())
|
||||
}
|
||||
|
||||
user := users.User{
|
||||
ID: u.GetId(),
|
||||
FirstName: u.GetFirstName(),
|
||||
LastName: u.GetLastName(),
|
||||
Tags: u.GetTags(),
|
||||
Metadata: metadata,
|
||||
PublicMetadata: publicMetadata,
|
||||
Status: users.Status(u.GetStatus()),
|
||||
Role: users.Role(u.GetRole()),
|
||||
ProfilePicture: u.GetProfilePicture(),
|
||||
ID: u.GetId(),
|
||||
FirstName: u.GetFirstName(),
|
||||
LastName: u.GetLastName(),
|
||||
Tags: u.GetTags(),
|
||||
Metadata: metadata,
|
||||
PrivateMetadata: privateMetadata,
|
||||
Status: users.Status(u.GetStatus()),
|
||||
Role: users.Role(u.GetRole()),
|
||||
ProfilePicture: u.GetProfilePicture(),
|
||||
Credentials: users.Credentials{
|
||||
Username: u.GetUsername(),
|
||||
},
|
||||
|
||||
+17
-17
@@ -82,7 +82,7 @@ func toProtoUsers(us []users.User) ([]*grpcUsersV1.User, error) {
|
||||
}
|
||||
|
||||
func toProtoUser(u users.User) (*grpcUsersV1.User, error) {
|
||||
var metadata, publicMetadata *structpb.Struct
|
||||
var metadata, privateMetadata *structpb.Struct
|
||||
var err error
|
||||
if u.Metadata != nil {
|
||||
metadata, err = structpb.NewStruct(u.Metadata)
|
||||
@@ -90,28 +90,28 @@ func toProtoUser(u users.User) (*grpcUsersV1.User, error) {
|
||||
return nil, errors.Wrap(svcerr.ErrViewEntity, err)
|
||||
}
|
||||
}
|
||||
if u.PublicMetadata != nil {
|
||||
publicMetadata, err = structpb.NewStruct(u.PublicMetadata)
|
||||
if u.PrivateMetadata != nil {
|
||||
privateMetadata, err = structpb.NewStruct(u.PrivateMetadata)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(svcerr.ErrViewEntity, err)
|
||||
}
|
||||
}
|
||||
|
||||
pu := &grpcUsersV1.User{
|
||||
Id: u.ID,
|
||||
FirstName: u.FirstName,
|
||||
LastName: u.LastName,
|
||||
Tags: u.Tags,
|
||||
Metadata: metadata,
|
||||
PublicMetadata: publicMetadata,
|
||||
Status: uint32(u.Status),
|
||||
Role: uint32(u.Role),
|
||||
ProfilePicture: u.ProfilePicture,
|
||||
Username: u.Credentials.Username,
|
||||
Email: u.Email,
|
||||
UpdatedBy: u.UpdatedBy,
|
||||
AuthProvider: u.AuthProvider,
|
||||
Permissions: u.Permissions,
|
||||
Id: u.ID,
|
||||
FirstName: u.FirstName,
|
||||
LastName: u.LastName,
|
||||
Tags: u.Tags,
|
||||
Metadata: metadata,
|
||||
PrivateMetadata: privateMetadata,
|
||||
Status: uint32(u.Status),
|
||||
Role: uint32(u.Role),
|
||||
ProfilePicture: u.ProfilePicture,
|
||||
Username: u.Credentials.Username,
|
||||
Email: u.Email,
|
||||
UpdatedBy: u.UpdatedBy,
|
||||
AuthProvider: u.AuthProvider,
|
||||
Permissions: u.Permissions,
|
||||
}
|
||||
|
||||
if !u.CreatedAt.IsZero() {
|
||||
|
||||
@@ -147,11 +147,11 @@ func (req searchUsersReq) validate() error {
|
||||
}
|
||||
|
||||
type updateUserReq struct {
|
||||
id string
|
||||
FirstName *string `json:"first_name,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
Metadata *users.Metadata `json:"metadata,omitempty"`
|
||||
PublicMetadata *users.Metadata `json:"public_metadata,omitempty"`
|
||||
id string
|
||||
FirstName *string `json:"first_name,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
Metadata *users.Metadata `json:"metadata,omitempty"`
|
||||
PrivateMetadata *users.Metadata `json:"private_metadata,omitempty"`
|
||||
}
|
||||
|
||||
func (req updateUserReq) validate() error {
|
||||
|
||||
@@ -92,8 +92,8 @@ func (uce createUserEvent) Encode() (map[string]any, error) {
|
||||
if uce.Metadata != nil {
|
||||
val["metadata"] = uce.Metadata
|
||||
}
|
||||
if uce.PublicMetadata != nil {
|
||||
val["public_metadata"] = uce.PublicMetadata
|
||||
if uce.PrivateMetadata != nil {
|
||||
val["private_metadata"] = uce.PrivateMetadata
|
||||
}
|
||||
if uce.Credentials.Username != "" {
|
||||
val["username"] = uce.Credentials.Username
|
||||
@@ -174,8 +174,8 @@ func (uce updateUserEvent) Encode() (map[string]any, error) {
|
||||
if uce.Metadata != nil {
|
||||
val["metadata"] = uce.Metadata
|
||||
}
|
||||
if uce.PublicMetadata != nil {
|
||||
val["public_metadata"] = uce.PublicMetadata
|
||||
if uce.PrivateMetadata != nil {
|
||||
val["private_metadata"] = uce.PrivateMetadata
|
||||
}
|
||||
if !uce.CreatedAt.IsZero() {
|
||||
val["created_at"] = uce.CreatedAt
|
||||
@@ -301,8 +301,8 @@ func (vue viewUserEvent) Encode() (map[string]any, error) {
|
||||
if vue.Metadata != nil {
|
||||
val["metadata"] = vue.Metadata
|
||||
}
|
||||
if vue.PublicMetadata != nil {
|
||||
val["public_metadata"] = vue.PublicMetadata
|
||||
if vue.PrivateMetadata != nil {
|
||||
val["private_metadata"] = vue.PrivateMetadata
|
||||
}
|
||||
if !vue.CreatedAt.IsZero() {
|
||||
val["created_at"] = vue.CreatedAt
|
||||
@@ -347,8 +347,8 @@ func (vpe viewProfileEvent) Encode() (map[string]any, error) {
|
||||
if vpe.Metadata != nil {
|
||||
val["metadata"] = vpe.Metadata
|
||||
}
|
||||
if vpe.PublicMetadata != nil {
|
||||
val["public_metadata"] = vpe.PublicMetadata
|
||||
if vpe.PrivateMetadata != nil {
|
||||
val["private_metadata"] = vpe.PrivateMetadata
|
||||
}
|
||||
if !vpe.CreatedAt.IsZero() {
|
||||
val["created_at"] = vpe.CreatedAt
|
||||
|
||||
@@ -1157,7 +1157,7 @@ func generateTestUser(t *testing.T) users.User {
|
||||
Secret: "secret",
|
||||
},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
},
|
||||
|
||||
@@ -229,7 +229,7 @@ func (lm *loggingMiddleware) Update(ctx context.Context, session authn.Session,
|
||||
slog.String("username", u.Credentials.Username),
|
||||
slog.String("first_name", u.FirstName),
|
||||
slog.String("last_name", u.LastName),
|
||||
slog.Any("public_metadata", u.PublicMetadata),
|
||||
slog.Any("metadata", u.Metadata),
|
||||
),
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -139,10 +139,10 @@ func Migration() *migrate.MemoryMigrationSource {
|
||||
{
|
||||
Id: "clients_10",
|
||||
Up: []string{
|
||||
`ALTER TABLE users ADD COLUMN public_metadata JSONB;`,
|
||||
`ALTER TABLE users ADD COLUMN private_metadata JSONB;`,
|
||||
},
|
||||
Down: []string{
|
||||
`ALTER TABLE users DROP COLUMN public_metadata;`,
|
||||
`ALTER TABLE users DROP COLUMN private_metadata;`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
+82
-82
@@ -36,9 +36,9 @@ func NewRepository(db postgres.Database) users.Repository {
|
||||
}
|
||||
|
||||
func (repo *userRepo) Save(ctx context.Context, c users.User) (users.User, error) {
|
||||
q := `INSERT INTO users (id, tags, email, secret, metadata, public_metadata, created_at, status, role, first_name, last_name, username, profile_picture, auth_provider)
|
||||
VALUES (:id, :tags, :email, :secret, :metadata, :public_metadata, :created_at, :status, :role, :first_name, :last_name, :username, :profile_picture, :auth_provider)
|
||||
RETURNING id, tags, email, metadata, public_metadata, created_at, status, role, first_name, last_name, username, profile_picture, verified_at, auth_provider`
|
||||
q := `INSERT INTO users (id, tags, email, secret, metadata, private_metadata, created_at, status, role, first_name, last_name, username, profile_picture, auth_provider)
|
||||
VALUES (:id, :tags, :email, :secret, :metadata, :private_metadata, :created_at, :status, :role, :first_name, :last_name, :username, :profile_picture, :auth_provider)
|
||||
RETURNING id, tags, email, metadata, private_metadata, created_at, status, role, first_name, last_name, username, profile_picture, verified_at, auth_provider`
|
||||
|
||||
dbu, err := toDBUser(c)
|
||||
if err != nil {
|
||||
@@ -86,7 +86,7 @@ func (repo *userRepo) CheckSuperAdmin(ctx context.Context, adminID string) error
|
||||
}
|
||||
|
||||
func (repo *userRepo) RetrieveByID(ctx context.Context, id string) (users.User, error) {
|
||||
q := `SELECT id, tags, email, secret, metadata, public_metadata, created_at, updated_at, updated_by, status, role, first_name, last_name, username, profile_picture, verified_at, auth_provider
|
||||
q := `SELECT id, tags, email, secret, metadata, private_metadata, created_at, updated_at, updated_by, status, role, first_name, last_name, username, profile_picture, verified_at, auth_provider
|
||||
FROM users WHERE id = :id`
|
||||
|
||||
dbu := DBUser{
|
||||
@@ -124,7 +124,7 @@ func (repo *userRepo) RetrieveAll(ctx context.Context, pm users.Page) (users.Use
|
||||
|
||||
squery := applyOrdering(query, pm)
|
||||
|
||||
q := fmt.Sprintf(`SELECT u.id, u.tags, u.email, u.public_metadata, u.status, u.role, u.first_name, u.last_name, u.username,
|
||||
q := fmt.Sprintf(`SELECT u.id, u.tags, u.email, u.metadata, u.status, u.role, u.first_name, u.last_name, u.username,
|
||||
u.created_at, u.updated_at, u.profile_picture, COALESCE(u.updated_by, '') AS updated_by, u.verified_at
|
||||
FROM users u %s LIMIT :limit OFFSET :offset;`, squery)
|
||||
|
||||
@@ -137,7 +137,7 @@ func (repo *userRepo) RetrieveAll(ctx context.Context, pm users.Page) (users.Use
|
||||
if !pm.OnlyTotal {
|
||||
rows, err := repo.Repository.DB.NamedQueryContext(ctx, q, dbPage)
|
||||
if err != nil {
|
||||
return users.UsersPage{}, repo.eh.HandleError(repoerr.ErrFailedToRetrieveAllGroups, err)
|
||||
return users.UsersPage{}, repo.eh.HandleError(repoerr.ErrRetrieveAllUsers, err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
@@ -178,7 +178,7 @@ func (repo *userRepo) RetrieveAll(ctx context.Context, pm users.Page) (users.Use
|
||||
func (repo *userRepo) UpdateUsername(ctx context.Context, user users.User) (users.User, error) {
|
||||
q := `UPDATE users SET username = :username, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, tags, metadata, public_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, email, role, verified_at`
|
||||
RETURNING id, tags, metadata, private_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, email, role, verified_at`
|
||||
|
||||
return repo.update(ctx, user, q)
|
||||
}
|
||||
@@ -195,14 +195,14 @@ func (repo *userRepo) Update(ctx context.Context, id string, ur users.UserReq) (
|
||||
query = append(query, "last_name = :last_name")
|
||||
u.LastName = *ur.LastName
|
||||
}
|
||||
if ur.PublicMetadata != nil {
|
||||
query = append(query, "public_metadata = :public_metadata")
|
||||
u.PublicMetadata = *ur.PublicMetadata
|
||||
}
|
||||
if ur.Metadata != nil {
|
||||
query = append(query, "metadata = :metadata")
|
||||
u.Metadata = *ur.Metadata
|
||||
}
|
||||
if ur.PrivateMetadata != nil {
|
||||
query = append(query, "private_metadata = :private_metadata")
|
||||
u.PrivateMetadata = *ur.PrivateMetadata
|
||||
}
|
||||
if ur.Tags != nil {
|
||||
query = append(query, "tags = :tags")
|
||||
u.Tags = *ur.Tags
|
||||
@@ -227,7 +227,7 @@ func (repo *userRepo) Update(ctx context.Context, id string, ur users.UserReq) (
|
||||
|
||||
q := fmt.Sprintf(`UPDATE users SET %s
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, tags, metadata, public_metadata, status, created_at, updated_at, updated_by, last_name, first_name, username, profile_picture, email, role, verified_at`, upq)
|
||||
RETURNING id, tags, metadata, private_metadata, status, created_at, updated_at, updated_by, last_name, first_name, username, profile_picture, email, role, verified_at`, upq)
|
||||
|
||||
u.Status = users.EnabledStatus
|
||||
return repo.update(ctx, u, q)
|
||||
@@ -260,7 +260,7 @@ func (repo *userRepo) update(ctx context.Context, user users.User, query string)
|
||||
func (repo *userRepo) UpdateEmail(ctx context.Context, user users.User) (users.User, error) {
|
||||
q := `UPDATE users SET email = :email, verified_at = NULL, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, tags, email, metadata, public_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
RETURNING id, tags, email, metadata, private_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
user.Status = users.EnabledStatus
|
||||
return repo.update(ctx, user, q)
|
||||
}
|
||||
@@ -268,7 +268,7 @@ func (repo *userRepo) UpdateEmail(ctx context.Context, user users.User) (users.U
|
||||
func (repo *userRepo) UpdateRole(ctx context.Context, user users.User) (users.User, error) {
|
||||
q := `UPDATE users SET role = :role, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, tags, email, metadata, public_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
RETURNING id, tags, email, metadata, private_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
user.Status = users.EnabledStatus
|
||||
return repo.update(ctx, user, q)
|
||||
}
|
||||
@@ -276,7 +276,7 @@ func (repo *userRepo) UpdateRole(ctx context.Context, user users.User) (users.Us
|
||||
func (repo *userRepo) UpdateSecret(ctx context.Context, user users.User) (users.User, error) {
|
||||
q := `UPDATE users SET secret = :secret, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id AND status = :status
|
||||
RETURNING id, tags, email, metadata, public_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
RETURNING id, tags, email, metadata, private_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
user.Status = users.EnabledStatus
|
||||
return repo.update(ctx, user, q)
|
||||
}
|
||||
@@ -284,7 +284,7 @@ func (repo *userRepo) UpdateSecret(ctx context.Context, user users.User) (users.
|
||||
func (repo *userRepo) ChangeStatus(ctx context.Context, user users.User) (users.User, error) {
|
||||
q := `UPDATE users SET status = :status, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE id = :id
|
||||
RETURNING id, tags, email, metadata, public_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
RETURNING id, tags, email, metadata, private_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
|
||||
return repo.update(ctx, user, q)
|
||||
}
|
||||
@@ -292,7 +292,7 @@ func (repo *userRepo) ChangeStatus(ctx context.Context, user users.User) (users.
|
||||
func (repo *userRepo) UpdateVerifiedAt(ctx context.Context, user users.User) (users.User, error) {
|
||||
q := `UPDATE users SET verified_at = :verified_at
|
||||
WHERE id = :id and email = :email
|
||||
RETURNING id, tags, email, metadata, public_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
RETURNING id, tags, email, metadata, private_metadata, status, created_at, updated_at, updated_by, first_name, last_name, username, role, verified_at`
|
||||
|
||||
return repo.update(ctx, user, q)
|
||||
}
|
||||
@@ -320,7 +320,7 @@ func (repo *userRepo) SearchUsers(ctx context.Context, pm users.Page) (users.Use
|
||||
tq := query
|
||||
query = applyOrdering(query, pm)
|
||||
|
||||
q := fmt.Sprintf(`SELECT u.id, u.username, u.public_metadata, u.first_name, u.last_name, u.created_at, u.updated_at FROM users u %s LIMIT :limit OFFSET :offset;`, query)
|
||||
q := fmt.Sprintf(`SELECT u.id, u.username, u.metadata, u.first_name, u.last_name, u.created_at, u.updated_at FROM users u %s LIMIT :limit OFFSET :offset;`, query)
|
||||
|
||||
dbPage, err := ToDBUsersPage(pm)
|
||||
if err != nil {
|
||||
@@ -379,7 +379,7 @@ func (repo *userRepo) RetrieveAllByIDs(ctx context.Context, pm users.Page) (user
|
||||
}
|
||||
squery := applyOrdering(query, pm)
|
||||
|
||||
q := fmt.Sprintf(`SELECT u.id, u.username, u.tags, u.email, u.public_metadata, u.status, u.role, u.first_name, u.last_name,
|
||||
q := fmt.Sprintf(`SELECT u.id, u.username, u.tags, u.email, u.metadata, u.status, u.role, u.first_name, u.last_name,
|
||||
u.created_at, u.updated_at, COALESCE(u.updated_by, '') AS updated_by FROM users u %s LIMIT :limit OFFSET :offset;`, squery)
|
||||
dbPage, err := ToDBUsersPage(pm)
|
||||
if err != nil {
|
||||
@@ -425,7 +425,7 @@ func (repo *userRepo) RetrieveAllByIDs(ctx context.Context, pm users.Page) (user
|
||||
}
|
||||
|
||||
func (repo *userRepo) RetrieveByEmail(ctx context.Context, email string) (users.User, error) {
|
||||
q := `SELECT id, tags, email, secret, metadata, public_metadata, created_at, updated_at, updated_by, status, role, first_name, last_name, username, verified_at, auth_provider
|
||||
q := `SELECT id, tags, email, secret, metadata, private_metadata, created_at, updated_at, updated_by, status, role, first_name, last_name, username, verified_at, auth_provider
|
||||
FROM users WHERE email = :email AND status = :status`
|
||||
|
||||
dbu := DBUser{
|
||||
@@ -452,7 +452,7 @@ func (repo *userRepo) RetrieveByEmail(ctx context.Context, email string) (users.
|
||||
}
|
||||
|
||||
func (repo *userRepo) RetrieveByUsername(ctx context.Context, username string) (users.User, error) {
|
||||
q := `SELECT id, tags, email, secret, metadata, public_metadata, created_at, updated_at, updated_by, status, role, first_name, last_name, username, verified_at, auth_provider
|
||||
q := `SELECT id, tags, email, secret, metadata, private_metadata, created_at, updated_at, updated_by, status, role, first_name, last_name, username, verified_at, auth_provider
|
||||
FROM users WHERE username = :username AND status = :status`
|
||||
|
||||
dbu := DBUser{
|
||||
@@ -479,36 +479,28 @@ func (repo *userRepo) RetrieveByUsername(ctx context.Context, username string) (
|
||||
}
|
||||
|
||||
type DBUser struct {
|
||||
ID string `db:"id"`
|
||||
Domain string `db:"domain_id"`
|
||||
Secret string `db:"secret"`
|
||||
Metadata []byte `db:"metadata,omitempty"`
|
||||
PublicMetadata []byte `db:"public_metadata,omitempty"`
|
||||
Tags pgtype.TextArray `db:"tags,omitempty"` // Tags
|
||||
CreatedAt time.Time `db:"created_at,omitempty"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at,omitempty"`
|
||||
UpdatedBy *string `db:"updated_by,omitempty"`
|
||||
Groups []groups.Group `db:"groups,omitempty"`
|
||||
Status users.Status `db:"status,omitempty"`
|
||||
Role *users.Role `db:"role,omitempty"`
|
||||
Username sql.NullString `db:"username, omitempty"`
|
||||
FirstName sql.NullString `db:"first_name, omitempty"`
|
||||
LastName sql.NullString `db:"last_name, omitempty"`
|
||||
ProfilePicture sql.NullString `db:"profile_picture, omitempty"`
|
||||
Email string `db:"email,omitempty"`
|
||||
VerifiedAt sql.NullTime `db:"verified_at,omitempty"`
|
||||
AuthProvider sql.NullString `db:"auth_provider,omitempty"`
|
||||
ID string `db:"id"`
|
||||
Domain string `db:"domain_id"`
|
||||
Secret string `db:"secret"`
|
||||
Metadata []byte `db:"metadata,omitempty"`
|
||||
PrivateMetadata []byte `db:"private_metadata,omitempty"`
|
||||
Tags pgtype.TextArray `db:"tags,omitempty"` // Tags
|
||||
CreatedAt time.Time `db:"created_at,omitempty"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at,omitempty"`
|
||||
UpdatedBy *string `db:"updated_by,omitempty"`
|
||||
Groups []groups.Group `db:"groups,omitempty"`
|
||||
Status users.Status `db:"status,omitempty"`
|
||||
Role *users.Role `db:"role,omitempty"`
|
||||
Username sql.NullString `db:"username, omitempty"`
|
||||
FirstName sql.NullString `db:"first_name, omitempty"`
|
||||
LastName sql.NullString `db:"last_name, omitempty"`
|
||||
ProfilePicture sql.NullString `db:"profile_picture, omitempty"`
|
||||
Email string `db:"email,omitempty"`
|
||||
VerifiedAt sql.NullTime `db:"verified_at,omitempty"`
|
||||
AuthProvider sql.NullString `db:"auth_provider,omitempty"`
|
||||
}
|
||||
|
||||
func toDBUser(u users.User) (DBUser, error) {
|
||||
publicMetadata := []byte("{}")
|
||||
if len(u.PublicMetadata) > 0 {
|
||||
b, err := json.Marshal(u.PublicMetadata)
|
||||
if err != nil {
|
||||
return DBUser{}, errors.Wrap(repoerr.ErrMalformedEntity, err)
|
||||
}
|
||||
publicMetadata = b
|
||||
}
|
||||
metadata := []byte("{}")
|
||||
if len(u.Metadata) > 0 {
|
||||
b, err := json.Marshal(u.Metadata)
|
||||
@@ -517,6 +509,14 @@ func toDBUser(u users.User) (DBUser, error) {
|
||||
}
|
||||
metadata = b
|
||||
}
|
||||
privateMetadata := []byte("{}")
|
||||
if len(u.PrivateMetadata) > 0 {
|
||||
b, err := json.Marshal(u.PrivateMetadata)
|
||||
if err != nil {
|
||||
return DBUser{}, errors.Wrap(repoerr.ErrMalformedEntity, err)
|
||||
}
|
||||
privateMetadata = b
|
||||
}
|
||||
var tags pgtype.TextArray
|
||||
if err := tags.Set(u.Tags); err != nil {
|
||||
return DBUser{}, err
|
||||
@@ -540,35 +540,35 @@ func toDBUser(u users.User) (DBUser, error) {
|
||||
}
|
||||
|
||||
return DBUser{
|
||||
ID: u.ID,
|
||||
Tags: tags,
|
||||
Secret: u.Credentials.Secret,
|
||||
Metadata: metadata,
|
||||
PublicMetadata: publicMetadata,
|
||||
CreatedAt: u.CreatedAt,
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: updatedBy,
|
||||
Status: u.Status,
|
||||
Role: &u.Role,
|
||||
LastName: stringToNullString(u.LastName),
|
||||
FirstName: stringToNullString(u.FirstName),
|
||||
Username: stringToNullString(u.Credentials.Username),
|
||||
ProfilePicture: stringToNullString(u.ProfilePicture),
|
||||
Email: u.Email,
|
||||
VerifiedAt: verifiedAt,
|
||||
AuthProvider: authProvider,
|
||||
ID: u.ID,
|
||||
Tags: tags,
|
||||
Secret: u.Credentials.Secret,
|
||||
Metadata: metadata,
|
||||
PrivateMetadata: privateMetadata,
|
||||
CreatedAt: u.CreatedAt,
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: updatedBy,
|
||||
Status: u.Status,
|
||||
Role: &u.Role,
|
||||
LastName: stringToNullString(u.LastName),
|
||||
FirstName: stringToNullString(u.FirstName),
|
||||
Username: stringToNullString(u.Credentials.Username),
|
||||
ProfilePicture: stringToNullString(u.ProfilePicture),
|
||||
Email: u.Email,
|
||||
VerifiedAt: verifiedAt,
|
||||
AuthProvider: authProvider,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ToUser(dbu DBUser) (users.User, error) {
|
||||
var publicMetadata, metadata users.Metadata
|
||||
if dbu.PublicMetadata != nil {
|
||||
if err := json.Unmarshal([]byte(dbu.PublicMetadata), &publicMetadata); err != nil {
|
||||
var metadata, privateMetadata users.Metadata
|
||||
if dbu.Metadata != nil {
|
||||
if err := json.Unmarshal([]byte(dbu.Metadata), &metadata); err != nil {
|
||||
return users.User{}, errors.Wrap(repoerr.ErrMalformedEntity, err)
|
||||
}
|
||||
}
|
||||
if dbu.Metadata != nil {
|
||||
if err := json.Unmarshal([]byte(dbu.Metadata), &metadata); err != nil {
|
||||
if dbu.PrivateMetadata != nil {
|
||||
if err := json.Unmarshal([]byte(dbu.PrivateMetadata), &privateMetadata); err != nil {
|
||||
return users.User{}, errors.Wrap(repoerr.ErrMalformedEntity, err)
|
||||
}
|
||||
}
|
||||
@@ -602,17 +602,17 @@ func ToUser(dbu DBUser) (users.User, error) {
|
||||
Username: nullStringString(dbu.Username),
|
||||
Secret: dbu.Secret,
|
||||
},
|
||||
Email: dbu.Email,
|
||||
Metadata: metadata,
|
||||
PublicMetadata: publicMetadata,
|
||||
CreatedAt: dbu.CreatedAt.UTC(),
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: updatedBy,
|
||||
Status: dbu.Status,
|
||||
Tags: tags,
|
||||
ProfilePicture: nullStringString(dbu.ProfilePicture),
|
||||
VerifiedAt: verifiedAt,
|
||||
AuthProvider: authProvider,
|
||||
Email: dbu.Email,
|
||||
Metadata: metadata,
|
||||
PrivateMetadata: privateMetadata,
|
||||
CreatedAt: dbu.CreatedAt.UTC(),
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: updatedBy,
|
||||
Status: dbu.Status,
|
||||
Tags: tags,
|
||||
ProfilePicture: nullStringString(dbu.ProfilePicture),
|
||||
VerifiedAt: verifiedAt,
|
||||
AuthProvider: authProvider,
|
||||
}
|
||||
if dbu.Role != nil {
|
||||
user.Role = *dbu.Role
|
||||
@@ -682,7 +682,7 @@ func PageQuery(pm users.Page) (string, error) {
|
||||
query = append(query, "u.role = :role")
|
||||
}
|
||||
if len(pm.Metadata) > 0 {
|
||||
query = append(query, "public_metadata @> :metadata")
|
||||
query = append(query, "metadata @> :metadata")
|
||||
}
|
||||
|
||||
if len(pm.IDs) != 0 {
|
||||
|
||||
@@ -53,11 +53,11 @@ func TestUsersSave(t *testing.T) {
|
||||
email := first_name + "@example.com"
|
||||
|
||||
externalUser := users.User{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
FirstName: namesgen.Generate(),
|
||||
LastName: namesgen.Generate(),
|
||||
PublicMetadata: users.Metadata{},
|
||||
Metadata: users.Metadata{},
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
FirstName: namesgen.Generate(),
|
||||
LastName: namesgen.Generate(),
|
||||
PrivateMetadata: users.Metadata{},
|
||||
Metadata: users.Metadata{},
|
||||
Credentials: users.Credentials{
|
||||
Username: namesgen.Generate(),
|
||||
},
|
||||
@@ -80,7 +80,7 @@ func TestUsersSave(t *testing.T) {
|
||||
Username: username,
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -106,7 +106,7 @@ func TestUsersSave(t *testing.T) {
|
||||
Username: namesgen.Generate(),
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -127,7 +127,7 @@ func TestUsersSave(t *testing.T) {
|
||||
Username: username,
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -148,7 +148,7 @@ func TestUsersSave(t *testing.T) {
|
||||
Username: username,
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -169,7 +169,7 @@ func TestUsersSave(t *testing.T) {
|
||||
Username: invalidName,
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -189,7 +189,7 @@ func TestUsersSave(t *testing.T) {
|
||||
Credentials: users.Credentials{
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -208,7 +208,7 @@ func TestUsersSave(t *testing.T) {
|
||||
Credentials: users.Credentials{
|
||||
Username: namesgen.Generate(),
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -227,7 +227,7 @@ func TestUsersSave(t *testing.T) {
|
||||
Username: username,
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: map[string]any{
|
||||
PrivateMetadata: map[string]any{
|
||||
"key": make(chan int),
|
||||
},
|
||||
},
|
||||
@@ -276,10 +276,10 @@ func TestIsPlatformAdmin(t *testing.T) {
|
||||
Username: username,
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{},
|
||||
Metadata: users.Metadata{},
|
||||
Status: users.EnabledStatus,
|
||||
Role: users.AdminRole,
|
||||
PrivateMetadata: users.Metadata{},
|
||||
Metadata: users.Metadata{},
|
||||
Status: users.EnabledStatus,
|
||||
Role: users.AdminRole,
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
@@ -294,10 +294,10 @@ func TestIsPlatformAdmin(t *testing.T) {
|
||||
Username: namesgen.Generate(),
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{},
|
||||
Metadata: users.Metadata{},
|
||||
Status: users.EnabledStatus,
|
||||
Role: users.UserRole,
|
||||
PrivateMetadata: users.Metadata{},
|
||||
Metadata: users.Metadata{},
|
||||
Status: users.EnabledStatus,
|
||||
Role: users.UserRole,
|
||||
},
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
@@ -328,7 +328,7 @@ func TestRetrieveByID(t *testing.T) {
|
||||
Username: namesgen.Generate(),
|
||||
Secret: password,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -341,11 +341,11 @@ func TestRetrieveByID(t *testing.T) {
|
||||
require.Nil(t, err, fmt.Sprintf("failed to save users %s", user.ID))
|
||||
|
||||
externalUser := users.User{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
FirstName: namesgen.Generate(),
|
||||
LastName: namesgen.Generate(),
|
||||
PublicMetadata: users.Metadata{},
|
||||
Metadata: users.Metadata{},
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
FirstName: namesgen.Generate(),
|
||||
LastName: namesgen.Generate(),
|
||||
PrivateMetadata: users.Metadata{},
|
||||
Metadata: users.Metadata{},
|
||||
Credentials: users.Credentials{
|
||||
Username: namesgen.Generate(),
|
||||
},
|
||||
@@ -417,14 +417,14 @@ func TestRetrieveAll(t *testing.T) {
|
||||
Username: namesgen.Generate(),
|
||||
Secret: "",
|
||||
},
|
||||
PublicMetadata: users.Metadata{},
|
||||
Status: users.EnabledStatus,
|
||||
Tags: []string{"tag1"},
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Millisecond),
|
||||
UpdatedAt: baseTime.Add(time.Duration(i) * time.Millisecond),
|
||||
Metadata: users.Metadata{},
|
||||
Status: users.EnabledStatus,
|
||||
Tags: []string{"tag1"},
|
||||
CreatedAt: baseTime.Add(time.Duration(i) * time.Millisecond),
|
||||
UpdatedAt: baseTime.Add(time.Duration(i) * time.Millisecond),
|
||||
}
|
||||
if i%50 == 0 {
|
||||
user.PublicMetadata = map[string]any{
|
||||
user.Metadata = map[string]any{
|
||||
"key": "value",
|
||||
}
|
||||
user.Role = users.AdminRole
|
||||
@@ -737,7 +737,7 @@ func TestRetrieveAll(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "retrieve with public metadata",
|
||||
desc: "retrieve with metadata",
|
||||
pageMeta: users.Page{
|
||||
Metadata: map[string]any{
|
||||
"key": "value",
|
||||
@@ -978,7 +978,6 @@ func TestRetrieveAll(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
page, err := repo.RetrieveAll(context.Background(), tc.pageMeta)
|
||||
|
||||
assert.Equal(t, tc.page.Total, page.Total, fmt.Sprintf("%s: expected %d got %d\n", tc.desc, tc.page.Total, page.Total))
|
||||
assert.Equal(t, tc.page.Offset, page.Offset, fmt.Sprintf("%s: expected %d got %d\n", tc.desc, tc.page.Offset, page.Offset))
|
||||
assert.Equal(t, tc.page.Limit, page.Limit, fmt.Sprintf("%s: expected %d got %d\n", tc.desc, tc.page.Limit, page.Limit))
|
||||
@@ -1011,8 +1010,8 @@ func TestSearch(t *testing.T) {
|
||||
Credentials: users.Credentials{
|
||||
Username: user.Credentials.Username,
|
||||
},
|
||||
PublicMetadata: user.PublicMetadata,
|
||||
CreatedAt: user.CreatedAt,
|
||||
Metadata: user.Metadata,
|
||||
CreatedAt: user.CreatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1521,23 +1520,23 @@ func TestUpdate(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "update public metadata for enabled user",
|
||||
update: "public_metadata",
|
||||
desc: "update private metadata for enabled user",
|
||||
update: "private_metadata",
|
||||
userID: user1.ID,
|
||||
userReq: users.UserReq{
|
||||
PublicMetadata: &updatedMetadata,
|
||||
PrivateMetadata: &updatedMetadata,
|
||||
},
|
||||
userRes: users.User{
|
||||
PublicMetadata: updatedMetadata,
|
||||
PrivateMetadata: updatedMetadata,
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "update malformed public metadata for enabled user",
|
||||
update: "public_metadata",
|
||||
desc: "update malformed private metadata for enabled user",
|
||||
update: "private_metadata",
|
||||
userID: user1.ID,
|
||||
userReq: users.UserReq{
|
||||
PublicMetadata: &malformedMetadata,
|
||||
PrivateMetadata: &malformedMetadata,
|
||||
},
|
||||
err: repoerr.ErrMalformedEntity,
|
||||
},
|
||||
@@ -1558,7 +1557,7 @@ func TestUpdate(t *testing.T) {
|
||||
update: "metadata",
|
||||
userID: user2.ID,
|
||||
userReq: users.UserReq{
|
||||
PublicMetadata: &updatedMetadata,
|
||||
Metadata: &updatedMetadata,
|
||||
},
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
@@ -1594,11 +1593,11 @@ func TestUpdate(t *testing.T) {
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
{
|
||||
desc: "update public metadata for invalid user",
|
||||
update: "public_metadata",
|
||||
desc: "update private metadata for invalid user",
|
||||
update: "private_metadata",
|
||||
userID: testsutil.GenerateUUID(t),
|
||||
userReq: users.UserReq{
|
||||
PublicMetadata: &updatedMetadata,
|
||||
PrivateMetadata: &updatedMetadata,
|
||||
},
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
@@ -1741,8 +1740,8 @@ func TestUpdate(t *testing.T) {
|
||||
assert.True(t, errors.Contains(err, c.err), fmt.Sprintf("expected %s to contain %s\n", err, c.err))
|
||||
if err == nil {
|
||||
switch c.update {
|
||||
case "public_metadata":
|
||||
assert.Equal(t, c.userRes.PublicMetadata, expected.PublicMetadata)
|
||||
case "private_metadata":
|
||||
assert.Equal(t, c.userRes.PrivateMetadata, expected.PrivateMetadata)
|
||||
case "metadata":
|
||||
assert.Equal(t, c.userRes.Metadata, expected.Metadata)
|
||||
case "first_name":
|
||||
@@ -2020,7 +2019,7 @@ func TestRetrieveByIDs(t *testing.T) {
|
||||
baseTime := time.Now().UTC().Truncate(time.Millisecond)
|
||||
for i := 0; i < num; i++ {
|
||||
user := generateUserWithTime(t, users.EnabledStatus, repo, baseTime.Add(time.Duration(i)*time.Millisecond))
|
||||
user.Metadata = nil
|
||||
user.PrivateMetadata = nil
|
||||
items = append(items, user)
|
||||
}
|
||||
|
||||
@@ -2183,7 +2182,7 @@ func TestRetrieveByIDs(t *testing.T) {
|
||||
page: users.Page{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Metadata: items[0].PublicMetadata,
|
||||
Metadata: items[0].Metadata,
|
||||
IDs: getIDs(items[0:20]),
|
||||
},
|
||||
response: users.UsersPage{
|
||||
@@ -2276,7 +2275,8 @@ func TestRetrieveByEmail(t *testing.T) {
|
||||
assert.Equal(t, user.ID, usr.ID)
|
||||
assert.Equal(t, user.FirstName, usr.FirstName)
|
||||
assert.Equal(t, user.LastName, usr.LastName)
|
||||
assert.Equal(t, user.PublicMetadata, usr.PublicMetadata)
|
||||
assert.Equal(t, user.Metadata, usr.Metadata)
|
||||
assert.Equal(t, user.PrivateMetadata, usr.PrivateMetadata)
|
||||
assert.Equal(t, user.Email, usr.Email)
|
||||
assert.Equal(t, user.Credentials.Username, usr.Credentials.Username)
|
||||
assert.Equal(t, user.Status, usr.Status)
|
||||
@@ -2327,7 +2327,7 @@ func TestRetrieveByUsername(t *testing.T) {
|
||||
assert.Equal(t, user.ID, usr.ID)
|
||||
assert.Equal(t, user.FirstName, usr.FirstName)
|
||||
assert.Equal(t, user.LastName, usr.LastName)
|
||||
assert.Equal(t, user.PublicMetadata, usr.PublicMetadata)
|
||||
assert.Equal(t, user.PrivateMetadata, usr.PrivateMetadata)
|
||||
assert.Equal(t, user.Email, usr.Email)
|
||||
assert.Equal(t, user.Credentials.Username, usr.Credentials.Username)
|
||||
assert.Equal(t, user.Status, usr.Status)
|
||||
@@ -2370,7 +2370,7 @@ func generateUserWithTime(t *testing.T, status users.Status, repo users.Reposito
|
||||
Secret: testsutil.GenerateUUID(t),
|
||||
},
|
||||
Tags: namesgen.GenerateMultiple(5),
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"organization": namesgen.Generate(),
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
|
||||
+5
-5
@@ -238,11 +238,11 @@ func (svc service) View(ctx context.Context, session authn.Session, id string) (
|
||||
if session.UserID != id {
|
||||
if err := svc.checkSuperAdmin(ctx, session); err != nil {
|
||||
return User{
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
ID: user.ID,
|
||||
PublicMetadata: user.PublicMetadata,
|
||||
Credentials: Credentials{Username: user.Credentials.Username},
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
ID: user.ID,
|
||||
Metadata: user.Metadata,
|
||||
Credentials: Credentials{Username: user.Credentials.Username},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -34,15 +34,15 @@ var (
|
||||
validCMetadata = users.Metadata{"role": "user"}
|
||||
userID = "d8dd12ef-aa2a-43fe-8ef2-2e4fe514360f"
|
||||
user = users.User{
|
||||
ID: userID,
|
||||
FirstName: "firstname",
|
||||
LastName: "lastname",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Credentials: users.Credentials{Username: "username", Secret: secret},
|
||||
Email: "useremail@email.com",
|
||||
Metadata: validCMetadata,
|
||||
PublicMetadata: validCMetadata,
|
||||
Status: users.EnabledStatus,
|
||||
ID: userID,
|
||||
FirstName: "firstname",
|
||||
LastName: "lastname",
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Credentials: users.Credentials{Username: "username", Secret: secret},
|
||||
Email: "useremail@email.com",
|
||||
Metadata: validCMetadata,
|
||||
PrivateMetadata: validCMetadata,
|
||||
Status: users.EnabledStatus,
|
||||
}
|
||||
basicUser = users.User{
|
||||
Credentials: users.Credentials{
|
||||
@@ -128,7 +128,7 @@ func TestRegister(t *testing.T) {
|
||||
Credentials: users.Credentials{
|
||||
Secret: secret,
|
||||
},
|
||||
PublicMetadata: users.Metadata{
|
||||
PrivateMetadata: users.Metadata{
|
||||
"name": "newuserwithallfields",
|
||||
},
|
||||
Metadata: users.Metadata{
|
||||
@@ -523,7 +523,7 @@ func TestUpdateUser(t *testing.T) {
|
||||
user1.FirstName = updateFirstName
|
||||
updatedMetadata := users.Metadata{"role": "test"}
|
||||
invalidMetadata := users.Metadata{"role": make(chan int)}
|
||||
user2.PublicMetadata = updatedMetadata
|
||||
user2.PrivateMetadata = updatedMetadata
|
||||
user2.Metadata = updatedMetadata
|
||||
adminID := testsutil.GenerateUUID(t)
|
||||
|
||||
@@ -553,10 +553,10 @@ func TestUpdateUser(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "update public metadata successfully as normal user",
|
||||
desc: "update private metadata successfully as normal user",
|
||||
userID: user2.ID,
|
||||
userReq: users.UserReq{
|
||||
PublicMetadata: &updatedMetadata,
|
||||
PrivateMetadata: &updatedMetadata,
|
||||
},
|
||||
session: authn.Session{UserID: user2.ID},
|
||||
updateResponse: user2,
|
||||
@@ -564,10 +564,10 @@ func TestUpdateUser(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "update public metadata with repo error",
|
||||
desc: "update private metadata with repo error",
|
||||
userID: user2.ID,
|
||||
userReq: users.UserReq{
|
||||
PublicMetadata: &invalidMetadata,
|
||||
PrivateMetadata: &invalidMetadata,
|
||||
},
|
||||
session: authn.Session{UserID: user2.ID},
|
||||
updateResponse: users.User{},
|
||||
@@ -626,10 +626,10 @@ func TestUpdateUser(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "update user public metadata as admin successfully",
|
||||
desc: "update user private metadata as admin successfully",
|
||||
userID: user2.ID,
|
||||
userReq: users.UserReq{
|
||||
PublicMetadata: &updatedMetadata,
|
||||
PrivateMetadata: &updatedMetadata,
|
||||
},
|
||||
session: authn.Session{UserID: adminID, SuperAdmin: true},
|
||||
updateResponse: user2,
|
||||
@@ -690,21 +690,21 @@ func TestUpdateUser(t *testing.T) {
|
||||
err: svcerr.ErrExternalAuthProviderCouldNotUpdate,
|
||||
},
|
||||
{
|
||||
desc: "update user metadata with external auth provider should succeed",
|
||||
desc: "update user privatemetadata with external auth provider should succeed",
|
||||
userID: user2.ID,
|
||||
userReq: users.UserReq{
|
||||
PublicMetadata: &updatedMetadata,
|
||||
PrivateMetadata: &updatedMetadata,
|
||||
},
|
||||
session: authn.Session{UserID: user2.ID},
|
||||
retrieveByIDResp: users.User{
|
||||
ID: user2.ID,
|
||||
AuthProvider: "google",
|
||||
PublicMetadata: updatedMetadata,
|
||||
ID: user2.ID,
|
||||
AuthProvider: "google",
|
||||
PrivateMetadata: updatedMetadata,
|
||||
},
|
||||
updateResponse: users.User{
|
||||
ID: user2.ID,
|
||||
AuthProvider: "google",
|
||||
PublicMetadata: updatedMetadata,
|
||||
ID: user2.ID,
|
||||
AuthProvider: "google",
|
||||
PrivateMetadata: updatedMetadata,
|
||||
},
|
||||
token: validToken,
|
||||
err: nil,
|
||||
|
||||
+25
-25
@@ -15,23 +15,23 @@ import (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
FirstName string `json:"first_name,omitempty"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
PublicMetadata Metadata `json:"public_metadata,omitempty"`
|
||||
Status Status `json:"status"` // 0 for enabled, 1 for disabled
|
||||
Role Role `json:"role"` // 0 for normal user, 1 for admin
|
||||
ProfilePicture string `json:"profile_picture,omitempty"` // profile picture URL
|
||||
Credentials Credentials `json:"credentials,omitempty"`
|
||||
Permissions []string `json:"permissions,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
UpdatedBy string `json:"updated_by,omitempty"`
|
||||
VerifiedAt time.Time `json:"verified_at,omitempty"`
|
||||
AuthProvider string `json:"auth_provider,omitempty"`
|
||||
ID string `json:"id"`
|
||||
FirstName string `json:"first_name,omitempty"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
PrivateMetadata Metadata `json:"private_metadata,omitempty"`
|
||||
Status Status `json:"status"` // 0 for enabled, 1 for disabled
|
||||
Role Role `json:"role"` // 0 for normal user, 1 for admin
|
||||
ProfilePicture string `json:"profile_picture,omitempty"` // profile picture URL
|
||||
Credentials Credentials `json:"credentials,omitempty"`
|
||||
Permissions []string `json:"permissions,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
UpdatedBy string `json:"updated_by,omitempty"`
|
||||
VerifiedAt time.Time `json:"verified_at,omitempty"`
|
||||
AuthProvider string `json:"auth_provider,omitempty"`
|
||||
}
|
||||
|
||||
type Credentials struct {
|
||||
@@ -48,14 +48,14 @@ type UsersPage struct {
|
||||
type Metadata map[string]any
|
||||
|
||||
type UserReq struct {
|
||||
FirstName *string `json:"first_name,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
Metadata *Metadata `json:"metadata,omitempty"`
|
||||
PublicMetadata *Metadata `json:"public_metadata,omitempty"`
|
||||
Tags *[]string `json:"tags,omitempty"`
|
||||
ProfilePicture *string `json:"profile_picture,omitempty"`
|
||||
UpdatedBy *string `json:"updated_by,omitempty"`
|
||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||
FirstName *string `json:"first_name,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
Metadata *Metadata `json:"metadata,omitempty"`
|
||||
PrivateMetadata *Metadata `json:"private_metadata,omitempty"`
|
||||
Tags *[]string `json:"tags,omitempty"`
|
||||
ProfilePicture *string `json:"profile_picture,omitempty"`
|
||||
UpdatedBy *string `json:"updated_by,omitempty"`
|
||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
// MembersPage contains page related metadata as well as list of members that
|
||||
|
||||
Reference in New Issue
Block a user