Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Resource name should not be among the reserveed GD2 keywords
Browse files Browse the repository at this point in the history
Signed-off-by: rishubhjain <rishubhjain47@gmail.com>
  • Loading branch information
rishubhjain committed Dec 14, 2018
1 parent cd8527b commit f1d991b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
18 changes: 8 additions & 10 deletions glustercli/cmd/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,9 @@ var volumeGetCmd = &cobra.Command{
Short: helpVolumeGetCmd,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Volume Name", "Name", "Modified", "Value", "Default Value", "Option Level"})
table.SetAlignment(tablewriter.ALIGN_LEFT)

volname := args[0]
optname := args[1]
table := tablewriter.NewWriter(os.Stdout)

var volList []string
if volname == "all" {
Expand All @@ -259,29 +255,31 @@ var volumeGetCmd = &cobra.Command{
}
for _, volume := range volList {

fmt.Println("Volume :", volume)
opts, err := client.VolumeGet(volume, optname)
if err != nil {
log.WithError(err).Error("error getting volume options")
failure("Error getting volume options", err, 1)
}
table = tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Modified", "Value", "Default Value", "Option Level"})
table.SetAlignment(tablewriter.ALIGN_LEFT)

for _, opt := range opts {
//if modified flag is set, discard unmodified options
if flagGetMdf && !opt.Modified {
continue
}
if flagGetBsc && opt.OptionLevel == "Basic" {
table.Append([]string{volume, opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel})
table.Append([]string{opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel})
}
if flagGetAdv && opt.OptionLevel == "Advanced" {
table.Append([]string{volume, opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel})
table.Append([]string{opt.OptName, formatBoolYesNo(opt.Modified), opt.Value, opt.DefaultValue, opt.OptionLevel})

}
}
table.Append([]string{"-", "-", "-", "-", "-", "-"})
table.Render()
}
table.Render()

},
}

Expand Down
6 changes: 6 additions & 0 deletions glusterd2/commands/volumes/volume-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package volumecommands

import (
"errors"
"fmt"
"net/http"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -42,6 +43,11 @@ func validateVolCreateReq(req *api.VolCreateReq) error {
return gderrors.ErrInvalidVolName
}

if gutils.IsReservedKeyword(req.Name) {
errMsg := fmt.Sprintf("invalid name, volume name cannot be among GD2 reserved keywords:%v", gutils.ReservedKeywords)
return errors.New(errMsg)
}

if req.Transport != "" && req.Transport != "tcp" && req.Transport != "rdma" {
return errors.New("invalid transport. Supported values: tcp or rdma")
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ const (
TiB = 1024 * GiB
)

var (
ReservedKeywords = []string{"all", "volume", "status", "list"}
)

// IsReservedKeyword returns true if the resource name is one of the
// GD2 Reserved Keyword
func IsReservedKeyword(resourceName string) bool {
return StringInSlice(resourceName, ReservedKeywords)
}

// IsLocalAddress checks whether a given host/IP is local
// Does lookup only after string matching IP addresses
func IsLocalAddress(address string) (bool, error) {
Expand Down

0 comments on commit f1d991b

Please sign in to comment.