/
entity.go
48 lines (36 loc) · 1.01 KB
/
entity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package authenticator
import (
"encoding/json"
authenticator_pb "github.com/BrobridgeOrg/gravity-api/service/auth"
)
type Entity struct {
AppID string `json:"appID"`
AppName string `json:"appName"`
AccessKey string `json:"accessKey"`
Properties map[string]interface{} `json:"props"`
}
func NewEntity() *Entity {
return &Entity{
Properties: make(map[string]interface{}),
}
}
func ParseEntityProto(pbEntity *authenticator_pb.Entity) (*Entity, error) {
entity := NewEntity()
entity.AppID = pbEntity.AppID
entity.AppName = pbEntity.AppName
entity.AccessKey = pbEntity.Key
err := json.Unmarshal(pbEntity.Properties, &entity.Properties)
if err != nil {
return nil, err
}
return entity, nil
}
func ConvertEntityToProto(entity *Entity) *authenticator_pb.Entity {
props, _ := json.Marshal(entity.Properties)
return &authenticator_pb.Entity{
AppID: entity.AppID,
AppName: entity.AppName,
Key: entity.AccessKey,
Properties: props,
}
}