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

Commit

Permalink
fix #26: use protected storage; issue #10: update grpc layer; issue #28
Browse files Browse the repository at this point in the history
…: update swagger; issue #12: add new commands
  • Loading branch information
kamilsk committed Sep 27, 2018
1 parent 24df18c commit f4f0b79
Show file tree
Hide file tree
Showing 12 changed files with 689 additions and 235 deletions.
13 changes: 9 additions & 4 deletions cmd/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ const (

var (
// License TODO issue#docs
License = &cobra.Command{Use: "license", Short: "Guard License"}
extendLicense = &cobra.Command{Use: "extend", Short: "Extend user license", RunE: communicate}
readLicense = &cobra.Command{Use: "read", Short: "Read user license", RunE: communicate}
License = &cobra.Command{Use: "license", Short: "Guard License"}
createLicense = &cobra.Command{Use: "create", Short: "Create user license", RunE: communicate}
readLicense = &cobra.Command{Use: "read", Short: "Read user license", RunE: communicate}
updateLicense = &cobra.Command{Use: "update", Short: "Update user license", RunE: communicate}
deleteLicense = &cobra.Command{Use: "delete", Short: "Delete user license", RunE: communicate}

// ---

registerLicense = &cobra.Command{Use: "register", Short: "Register user license", RunE: communicate}
)

Expand Down Expand Up @@ -53,5 +58,5 @@ func init() {
return nil
},
)
License.AddCommand(extendLicense, readLicense, registerLicense)
License.AddCommand(createLicense, readLicense, updateLicense, deleteLicense, registerLicense)
}
17 changes: 13 additions & 4 deletions cmd/grpc_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ var entities factory

func init() {
entities = factory{
readLicense: {"License": func() pb.Proxy { return pb.ReadLicenseRequestProxy{} }},
extendLicense: {"License": func() pb.Proxy { return pb.ExtendLicenseRequestProxy{} }},
createLicense: {"License": func() pb.Proxy { return pb.CreateLicenseRequestProxy{} }},
readLicense: {"License": func() pb.Proxy { return pb.ReadLicenseRequestProxy{} }},
updateLicense: {"License": func() pb.Proxy { return pb.UpdateLicenseRequestProxy{} }},
deleteLicense: {"License": func() pb.Proxy { return pb.DeleteLicenseRequestProxy{} }},

// ---

registerLicense: {"License": func() pb.Proxy { return pb.RegisterLicenseRequestProxy{} }},
}
}
Expand Down Expand Up @@ -116,10 +121,14 @@ func call(cnf config.GRPCConfig, entity pb.Proxy) (interface{}, error) {
middleware.AuthHeader,
strings.Concat(middleware.AuthScheme, " ", string(cnf.Token)))
switch request := entity.Convert().(type) {
case *pb.CreateLicenseRequest:
return client.Create(ctx, request)
case *pb.ReadLicenseRequest:
return client.Read(ctx, request)
case *pb.ExtendLicenseRequest:
return client.Extend(ctx, request)
case *pb.UpdateLicenseRequest:
return client.Update(ctx, request)
case *pb.DeleteLicenseRequest:
return client.Delete(ctx, request)
case *pb.RegisterLicenseRequest:
return client.Register(ctx, request)
default:
Expand Down
66 changes: 58 additions & 8 deletions env/client/guard.swagger.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"swagger": "2.0",
"info": {
"title": "Access Guard as a Service",
"title": "Access Control as a Service",
"version": "dev",
"contact": {
"name": "Guard project of Hugs Platform",
Expand All @@ -20,14 +20,14 @@
"application/json"
],
"paths": {
"/api/v1/license/extend": {
"put": {
"operationId": "Extend",
"/api/v1/license": {
"post": {
"operationId": "Create",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/grpcExtendLicenseResponse"
"$ref": "#/definitions/grpcCreateLicenseResponse"
}
}
},
Expand All @@ -52,7 +52,7 @@
]
}
},
"/api/v1/license/{id}": {
"/api/v1/license/{number}": {
"get": {
"operationId": "Read",
"responses": {
Expand All @@ -65,7 +65,51 @@
},
"parameters": [
{
"name": "id",
"name": "number",
"in": "path",
"required": true,
"type": "string"
}
],
"tags": [
"License"
]
},
"delete": {
"operationId": "Delete",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/grpcDeleteLicenseResponse"
}
}
},
"parameters": [
{
"name": "number",
"in": "path",
"required": true,
"type": "string"
}
],
"tags": [
"License"
]
},
"put": {
"operationId": "Update",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/grpcUpdateLicenseResponse"
}
}
},
"parameters": [
{
"name": "number",
"in": "path",
"required": true,
"type": "string"
Expand All @@ -78,14 +122,20 @@
}
},
"definitions": {
"grpcExtendLicenseResponse": {
"grpcCreateLicenseResponse": {
"type": "object"
},
"grpcDeleteLicenseResponse": {
"type": "object"
},
"grpcReadLicenseResponse": {
"type": "object"
},
"grpcRegisterLicenseResponse": {
"type": "object"
},
"grpcUpdateLicenseResponse": {
"type": "object"
}
}
}
35 changes: 2 additions & 33 deletions pkg/storage/protected.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,38 +111,7 @@ func (storage *Storage) DeleteLicense(ctx context.Context, id domain.Token, data

// ---

// ExtendLicense TODO issue#docs
func (storage *Storage) ExtendLicense(ctx context.Context, id domain.Token, data query.UpdateLicense) (repository.License, error) {
var license repository.License

conn, closer, err := storage.connection(ctx)
if err != nil {
return license, err
}
defer closer()

_, err = storage.exec.UserManager(ctx, conn).AccessToken(id)
if err != nil {
return license, err
}

return license, nil
}

// RegisterLicense TODO issue#docs
func (storage *Storage) RegisterLicense(ctx context.Context, id domain.Token, data query.CreateLicense) (repository.License, error) {
var license repository.License

conn, closer, err := storage.connection(ctx)
if err != nil {
return license, err
}
defer closer()

_, err = storage.exec.UserManager(ctx, conn).AccessToken(id)
if err != nil {
return license, err
}

return license, nil
func (storage *Storage) RegisterLicense(ctx context.Context, id domain.Token, data query.RegisterLicense) (repository.License, error) {
return storage.CreateLicense(ctx, id, query.CreateLicense{Number: &data.Number, Contract: data.Contract})
}
8 changes: 8 additions & 0 deletions pkg/storage/query/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ type UpdateLicense struct {
Number domain.ID
Contract domain.Contract
}

// ---

// RegisterLicense TODO issue#docs
type RegisterLicense struct {
Number domain.ID
Contract domain.Contract
}
11 changes: 9 additions & 2 deletions pkg/transport/grpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ import (

// ProtectedStorage TODO issue#docs
type ProtectedStorage interface {
// ExtendLicense TODO issue#docs
ExtendLicense(context.Context, domain.Token, query.ExtendLicense) (repository.License, error)
// CreateLicense TODO issue#docs
CreateLicense(context.Context, domain.Token, query.CreateLicense) (repository.License, error)
// ReadLicense TODO issue#docs
ReadLicense(context.Context, domain.Token, query.ReadLicense) (repository.License, error)
// UpdateLicense TODO issue#docs
UpdateLicense(context.Context, domain.Token, query.UpdateLicense) (repository.License, error)
// DeleteLicense TODO issue#docs
DeleteLicense(context.Context, domain.Token, query.DeleteLicense) (repository.License, error)

// ---

// RegisterLicense TODO issue#docs
RegisterLicense(context.Context, domain.Token, query.RegisterLicense) (repository.License, error)
}
Loading

0 comments on commit f4f0b79

Please sign in to comment.