v1.0.0
This commit is contained in:
@@ -3,27 +3,42 @@ package rg
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for grant access to resource group
|
||||
type AccessGrantRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
User string `url:"user"`
|
||||
Right string `url:"right"`
|
||||
// Resource group ID
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId"`
|
||||
|
||||
// User or group name to grant access
|
||||
// Required: true
|
||||
User string `url:"user"`
|
||||
|
||||
// Access rights to set,
|
||||
// Should be one of:
|
||||
// - "R"
|
||||
// - "RCX"
|
||||
// - "ARCXDU"
|
||||
// Required: true
|
||||
Right string `url:"right"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (rgrq AccessGrantRequest) Validate() error {
|
||||
func (rgrq AccessGrantRequest) validate() error {
|
||||
if rgrq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID must be set")
|
||||
}
|
||||
|
||||
if rgrq.User == "" {
|
||||
return errors.New("validation-error: field User must be set")
|
||||
}
|
||||
|
||||
validate := validators.StringInSlice(rgrq.Right, []string{"R", "RCX", "ARCXDU"})
|
||||
if !validate {
|
||||
return errors.New("field Right can only be one of 'R', 'RCX' or 'ARCXDU'")
|
||||
@@ -32,8 +47,9 @@ func (rgrq AccessGrantRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessGrant grants user or group access to the resource group as specified
|
||||
func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user