Skip to content
Snippets Groups Projects
Commit 77c39795 authored by Florent Gluck's avatar Florent Gluck
Browse files

Completed ticket #123

parent 86f61e2f
Branches
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import (
"strings"
"encoding/csv"
"nexus-common/caps"
"nexus-common/params"
u "nexus-client/utils"
g "nexus-client/globals"
)
......@@ -42,14 +43,6 @@ func (cmd *Add)PrintUsage() {
u.PrintlnErr(usage)
}
type cmdArgs struct {
Email string
FirstName string
LastName string
Pwd string
Caps caps.Capabilities
}
func (cmd *Add)Run(args []string) int {
statusCode := 0
......@@ -57,7 +50,7 @@ func (cmd *Add)Run(args []string) int {
if argc >= 4 {
// Detected syntax: email firstname lastname pwd [caps]
cargs := &cmdArgs {
cargs := &params.UserWithPwd {
Email: args[0],
FirstName: args[1],
LastName: args[2],
......@@ -113,7 +106,7 @@ func (cmd *Add)Run(args []string) int {
continue
}
cargs := &cmdArgs {
cargs := &params.UserWithPwd {
Email: email,
FirstName: columns[1],
LastName: columns[2],
......@@ -143,7 +136,7 @@ func (cmd *Add)Run(args []string) int {
return statusCode
}
func (cmd *Add)runRequest(args *cmdArgs) error {
func (cmd *Add)runRequest(args *params.UserWithPwd) error {
client := g.GetInstance().Client
host := g.GetInstance().Host
......
......@@ -5,6 +5,14 @@ import (
"nexus-common/caps"
)
type UserWithPwd struct {
Email string `json:"email" validate:"required,email"`
FirstName string `json:"firstname" validate:"required,min=2,max=32"`
LastName string `json:"lastname" validate:"required,min=2,max=32"`
Pwd string `json:"pwd" validate:"required,min=8"`
Caps caps.Capabilities `json:"caps" validate:"required"`
}
type UserWithoutPwd struct {
Email string `json:"email" validate:"required,email"`
FirstName string `json:"firstname" validate:"required,min=2,max=32"`
......
......@@ -2,16 +2,11 @@ package users
import (
"nexus-common/caps"
"nexus-common/params"
"github.com/go-playground/validator/v10"
)
type User struct {
Email string `json:"email" validate:"required,email"`
FirstName string `json:"firstname" validate:"required,min=2,max=32"`
LastName string `json:"lastname" validate:"required,min=2,max=32"`
Pwd string `json:"pwd" validate:"required,min=8"`
Caps caps.Capabilities `json:"caps" validate:"required"`
}
type User params.UserWithPwd
var dummyUser = User{}
......@@ -21,7 +16,7 @@ func NewEmptyUser() *User {
}
// Checks that the User structure's fields are valid.
func (user *User) Validate() error {
func (user *User)Validate() error {
// Checks the capabilities are valid
if err := caps.ValidateUserCaps(user.Caps); err != nil {
return err
......@@ -31,12 +26,12 @@ func (user *User) Validate() error {
}
// Returns true if user has the specified capability.
func (user *User) HasCapability(capability string) bool {
func (user *User)HasCapability(capability string) bool {
_, exists := user.Caps[capability]
return exists
}
func (user *User) GetVMAccessCapabilities() []string {
func (user *User)GetVMAccessCapabilities() []string {
capabilities := []string{}
for cap, _ := range caps.VMAccessCaps {
_, exists := user.Caps[cap]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment