Matthew R Kasun před 2 roky
rodič
revize
7be2ff810d

+ 2 - 1
cli/cmd/ext_client/update.go

@@ -37,7 +37,7 @@ var extClientUpdateCmd = &cobra.Command{
 				log.Fatal(err)
 			}
 		} else {
-			extClient.ClientID = clientID
+			extClient.ClientID = extClientID
 			extClient.PublicKey = updatedPublicKey
 			extClient.DNS = updatedDNS
 		}
@@ -46,6 +46,7 @@ var extClientUpdateCmd = &cobra.Command{
 }
 
 func init() {
+	extClientUpdateCmd.Flags().StringVar(&extClientID, "id", "", "updated ID of the external client")
 	extClientUpdateCmd.Flags().StringVar(&extClientUpdateFile, "file", "", "Filepath of updated external client definition in JSON")
 	extClientUpdateCmd.Flags().StringVar(&updatedPublicKey, "public_key", "", "updated public key of the external client")
 	extClientUpdateCmd.Flags().StringVar(&updatedDNS, "dns", "", "updated DNS of the external client")

+ 2 - 2
controllers/ext_client.go

@@ -441,8 +441,8 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) {
 		logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
 		return
 	}
-	if !validName(update.ClientID) {
-		logic.ReturnErrorResponse(w, r, logic.FormatError(errInvalidExtClientID, "badrequest"))
+	if err := validateExtClient(&oldExtClient, &update); err != nil {
+		logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
 		return
 	}
 	data, err := database.FetchRecord(database.EXT_CLIENT_TABLE_NAME, key)

+ 1 - 1
controllers/regex.go

@@ -7,7 +7,7 @@ import (
 
 var (
 	errInvalidExtClientPubKey  = errors.New("incorrect ext client public key")
-	errInvalidExtClientID      = errors.New("ext client ID must be alphanumderic and/or dashes")
+	errInvalidExtClientID      = errors.New("ext client ID must be alphanumderic and/or dashes and less that 15 chars")
 	errInvalidExtClientExtraIP = errors.New("ext client extra ip must be a valid cidr")
 	errInvalidExtClientDNS     = errors.New("ext client dns must be a valid ip address")
 )

+ 2 - 2
models/extclient.go

@@ -20,9 +20,9 @@ type ExtClient struct {
 
 // CustomExtClient - struct for CustomExtClient params
 type CustomExtClient struct {
-	ClientID        string   `json:"clientid"`
+	ClientID        string   `json:"clientid,omitempty"`
 	PublicKey       string   `json:"publickey,omitempty"`
 	DNS             string   `json:"dns,omitempty"`
 	ExtraAllowedIPs []string `json:"extraallowedips,omitempty"`
-	Enabled         bool     `json:"enabled"`
+	Enabled         bool     `json:"enabled,omitempty"`
 }