Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit f4f0b79

Browse files
committed
fix #26: use protected storage; issue #10: update grpc layer; issue #28: update swagger; issue #12: add new commands
1 parent 24df18c commit f4f0b79

12 files changed

+689
-235
lines changed

cmd/ctl.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ const (
1818

1919
var (
2020
// License TODO issue#docs
21-
License = &cobra.Command{Use: "license", Short: "Guard License"}
22-
extendLicense = &cobra.Command{Use: "extend", Short: "Extend user license", RunE: communicate}
23-
readLicense = &cobra.Command{Use: "read", Short: "Read user license", RunE: communicate}
21+
License = &cobra.Command{Use: "license", Short: "Guard License"}
22+
createLicense = &cobra.Command{Use: "create", Short: "Create user license", RunE: communicate}
23+
readLicense = &cobra.Command{Use: "read", Short: "Read user license", RunE: communicate}
24+
updateLicense = &cobra.Command{Use: "update", Short: "Update user license", RunE: communicate}
25+
deleteLicense = &cobra.Command{Use: "delete", Short: "Delete user license", RunE: communicate}
26+
27+
// ---
28+
2429
registerLicense = &cobra.Command{Use: "register", Short: "Register user license", RunE: communicate}
2530
)
2631

@@ -53,5 +58,5 @@ func init() {
5358
return nil
5459
},
5560
)
56-
License.AddCommand(extendLicense, readLicense, registerLicense)
61+
License.AddCommand(createLicense, readLicense, updateLicense, deleteLicense, registerLicense)
5762
}

cmd/grpc_helper.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ var entities factory
2424

2525
func init() {
2626
entities = factory{
27-
readLicense: {"License": func() pb.Proxy { return pb.ReadLicenseRequestProxy{} }},
28-
extendLicense: {"License": func() pb.Proxy { return pb.ExtendLicenseRequestProxy{} }},
27+
createLicense: {"License": func() pb.Proxy { return pb.CreateLicenseRequestProxy{} }},
28+
readLicense: {"License": func() pb.Proxy { return pb.ReadLicenseRequestProxy{} }},
29+
updateLicense: {"License": func() pb.Proxy { return pb.UpdateLicenseRequestProxy{} }},
30+
deleteLicense: {"License": func() pb.Proxy { return pb.DeleteLicenseRequestProxy{} }},
31+
32+
// ---
33+
2934
registerLicense: {"License": func() pb.Proxy { return pb.RegisterLicenseRequestProxy{} }},
3035
}
3136
}
@@ -116,10 +121,14 @@ func call(cnf config.GRPCConfig, entity pb.Proxy) (interface{}, error) {
116121
middleware.AuthHeader,
117122
strings.Concat(middleware.AuthScheme, " ", string(cnf.Token)))
118123
switch request := entity.Convert().(type) {
124+
case *pb.CreateLicenseRequest:
125+
return client.Create(ctx, request)
119126
case *pb.ReadLicenseRequest:
120127
return client.Read(ctx, request)
121-
case *pb.ExtendLicenseRequest:
122-
return client.Extend(ctx, request)
128+
case *pb.UpdateLicenseRequest:
129+
return client.Update(ctx, request)
130+
case *pb.DeleteLicenseRequest:
131+
return client.Delete(ctx, request)
123132
case *pb.RegisterLicenseRequest:
124133
return client.Register(ctx, request)
125134
default:

env/client/guard.swagger.json

+58-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"swagger": "2.0",
33
"info": {
4-
"title": "Access Guard as a Service",
4+
"title": "Access Control as a Service",
55
"version": "dev",
66
"contact": {
77
"name": "Guard project of Hugs Platform",
@@ -20,14 +20,14 @@
2020
"application/json"
2121
],
2222
"paths": {
23-
"/api/v1/license/extend": {
24-
"put": {
25-
"operationId": "Extend",
23+
"/api/v1/license": {
24+
"post": {
25+
"operationId": "Create",
2626
"responses": {
2727
"200": {
2828
"description": "",
2929
"schema": {
30-
"$ref": "#/definitions/grpcExtendLicenseResponse"
30+
"$ref": "#/definitions/grpcCreateLicenseResponse"
3131
}
3232
}
3333
},
@@ -52,7 +52,7 @@
5252
]
5353
}
5454
},
55-
"/api/v1/license/{id}": {
55+
"/api/v1/license/{number}": {
5656
"get": {
5757
"operationId": "Read",
5858
"responses": {
@@ -65,7 +65,51 @@
6565
},
6666
"parameters": [
6767
{
68-
"name": "id",
68+
"name": "number",
69+
"in": "path",
70+
"required": true,
71+
"type": "string"
72+
}
73+
],
74+
"tags": [
75+
"License"
76+
]
77+
},
78+
"delete": {
79+
"operationId": "Delete",
80+
"responses": {
81+
"200": {
82+
"description": "",
83+
"schema": {
84+
"$ref": "#/definitions/grpcDeleteLicenseResponse"
85+
}
86+
}
87+
},
88+
"parameters": [
89+
{
90+
"name": "number",
91+
"in": "path",
92+
"required": true,
93+
"type": "string"
94+
}
95+
],
96+
"tags": [
97+
"License"
98+
]
99+
},
100+
"put": {
101+
"operationId": "Update",
102+
"responses": {
103+
"200": {
104+
"description": "",
105+
"schema": {
106+
"$ref": "#/definitions/grpcUpdateLicenseResponse"
107+
}
108+
}
109+
},
110+
"parameters": [
111+
{
112+
"name": "number",
69113
"in": "path",
70114
"required": true,
71115
"type": "string"
@@ -78,14 +122,20 @@
78122
}
79123
},
80124
"definitions": {
81-
"grpcExtendLicenseResponse": {
125+
"grpcCreateLicenseResponse": {
126+
"type": "object"
127+
},
128+
"grpcDeleteLicenseResponse": {
82129
"type": "object"
83130
},
84131
"grpcReadLicenseResponse": {
85132
"type": "object"
86133
},
87134
"grpcRegisterLicenseResponse": {
88135
"type": "object"
136+
},
137+
"grpcUpdateLicenseResponse": {
138+
"type": "object"
89139
}
90140
}
91141
}

pkg/storage/protected.go

+2-33
Original file line numberDiff line numberDiff line change
@@ -111,38 +111,7 @@ func (storage *Storage) DeleteLicense(ctx context.Context, id domain.Token, data
111111

112112
// ---
113113

114-
// ExtendLicense TODO issue#docs
115-
func (storage *Storage) ExtendLicense(ctx context.Context, id domain.Token, data query.UpdateLicense) (repository.License, error) {
116-
var license repository.License
117-
118-
conn, closer, err := storage.connection(ctx)
119-
if err != nil {
120-
return license, err
121-
}
122-
defer closer()
123-
124-
_, err = storage.exec.UserManager(ctx, conn).AccessToken(id)
125-
if err != nil {
126-
return license, err
127-
}
128-
129-
return license, nil
130-
}
131-
132114
// RegisterLicense TODO issue#docs
133-
func (storage *Storage) RegisterLicense(ctx context.Context, id domain.Token, data query.CreateLicense) (repository.License, error) {
134-
var license repository.License
135-
136-
conn, closer, err := storage.connection(ctx)
137-
if err != nil {
138-
return license, err
139-
}
140-
defer closer()
141-
142-
_, err = storage.exec.UserManager(ctx, conn).AccessToken(id)
143-
if err != nil {
144-
return license, err
145-
}
146-
147-
return license, nil
115+
func (storage *Storage) RegisterLicense(ctx context.Context, id domain.Token, data query.RegisterLicense) (repository.License, error) {
116+
return storage.CreateLicense(ctx, id, query.CreateLicense{Number: &data.Number, Contract: data.Contract})
148117
}

pkg/storage/query/license.go

+8
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ type UpdateLicense struct {
2323
Number domain.ID
2424
Contract domain.Contract
2525
}
26+
27+
// ---
28+
29+
// RegisterLicense TODO issue#docs
30+
type RegisterLicense struct {
31+
Number domain.ID
32+
Contract domain.Contract
33+
}

pkg/transport/grpc/contract.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ import (
1111

1212
// ProtectedStorage TODO issue#docs
1313
type ProtectedStorage interface {
14-
// ExtendLicense TODO issue#docs
15-
ExtendLicense(context.Context, domain.Token, query.ExtendLicense) (repository.License, error)
14+
// CreateLicense TODO issue#docs
15+
CreateLicense(context.Context, domain.Token, query.CreateLicense) (repository.License, error)
1616
// ReadLicense TODO issue#docs
1717
ReadLicense(context.Context, domain.Token, query.ReadLicense) (repository.License, error)
18+
// UpdateLicense TODO issue#docs
19+
UpdateLicense(context.Context, domain.Token, query.UpdateLicense) (repository.License, error)
20+
// DeleteLicense TODO issue#docs
21+
DeleteLicense(context.Context, domain.Token, query.DeleteLicense) (repository.License, error)
22+
23+
// ---
24+
1825
// RegisterLicense TODO issue#docs
1926
RegisterLicense(context.Context, domain.Token, query.RegisterLicense) (repository.License, error)
2027
}

0 commit comments

Comments
 (0)