diff --git a/acls.go b/acls.go index 5e39ed3..0451a4a 100644 --- a/acls.go +++ b/acls.go @@ -27,8 +27,8 @@ type ACL *api.ACL // GetVolumeACL returns the ACL for a volume. func (c *Client) GetVolumeACL( ctx context.Context, - volumeName string) (ACL, error) { - + volumeName string, +) (ACL, error) { return api.ACLInspect(ctx, c.API, volumeName) } @@ -36,17 +36,17 @@ func (c *Client) GetVolumeACL( // was used to connect to the API. func (c *Client) SetVolumeOwnerToCurrentUser( ctx context.Context, - volumeName string) error { - + volumeName string, +) error { return c.SetVolumeOwner(ctx, volumeName, c.API.User()) } // SetVolumeOwner sets the owner for a volume. func (c *Client) SetVolumeOwner( ctx context.Context, - volumeName, userName string) error { - - mode := api.FileMode(0777) + volumeName, userName string, +) error { + mode := api.FileMode(0o777) return api.ACLUpdate( ctx, @@ -68,8 +68,8 @@ func (c *Client) SetVolumeOwner( // SetVolumeMode sets the permissions to the specified mode (chmod) func (c *Client) SetVolumeMode( ctx context.Context, - volumeName string, mode int) error { - + volumeName string, mode int, +) error { filemode := api.FileMode(mode) return api.ACLUpdate( diff --git a/acls_test.go b/acls_test.go index 51d55cf..8fe3265 100755 --- a/acls_test.go +++ b/acls_test.go @@ -16,8 +16,8 @@ limitations under the License. package goisilon import ( - "testing" "fmt" + "testing" "github.com/stretchr/testify/assert" diff --git a/api/api.go b/api/api.go index 7cad5e4..c7dfc5a 100755 --- a/api/api.go +++ b/api/api.go @@ -60,7 +60,6 @@ var ( // Client is an API client. type Client interface { - // Do sends an HTTP request to the OneFS API. Do( ctx context.Context, @@ -214,8 +213,8 @@ func New( ctx context.Context, hostname, username, password, groupname string, verboseLogging uint, authType uint8, - opts *ClientOptions) (Client, error) { - + opts *ClientOptions, +) (Client, error) { if hostname == "" || username == "" || password == "" { return nil, errNewClient } @@ -318,8 +317,8 @@ func (c *client) Get( ctx context.Context, path, id string, params OrderedValues, headers map[string]string, - resp interface{}) error { - + resp interface{}, +) error { return c.executeWithRetryAuthenticate( ctx, http.MethodGet, path, id, params, headers, nil, resp) } @@ -328,8 +327,8 @@ func (c *client) Post( ctx context.Context, path, id string, params OrderedValues, headers map[string]string, - body, resp interface{}) error { - + body, resp interface{}, +) error { return c.executeWithRetryAuthenticate( ctx, http.MethodPost, path, id, params, headers, body, resp) } @@ -338,8 +337,8 @@ func (c *client) Put( ctx context.Context, path, id string, params OrderedValues, headers map[string]string, - body, resp interface{}) error { - + body, resp interface{}, +) error { return c.executeWithRetryAuthenticate( ctx, http.MethodPut, path, id, params, headers, body, resp) } @@ -348,8 +347,8 @@ func (c *client) Delete( ctx context.Context, path, id string, params OrderedValues, headers map[string]string, - resp interface{}) error { - + resp interface{}, +) error { return c.executeWithRetryAuthenticate( ctx, http.MethodDelete, path, id, params, headers, nil, resp) } @@ -358,8 +357,8 @@ func (c *client) Do( ctx context.Context, method, path, id string, params OrderedValues, - body, resp interface{}) error { - + body, resp interface{}, +) error { return c.executeWithRetryAuthenticate(ctx, method, path, id, params, nil, body, resp) } @@ -375,8 +374,8 @@ func (c *client) DoWithHeaders( ctx context.Context, method, uri, id string, params OrderedValues, headers map[string]string, - body, resp interface{}) error { - + body, resp interface{}, +) error { res, _, err := c.DoAndGetResponseBody( ctx, method, uri, id, params, headers, body) if err != nil { @@ -412,8 +411,8 @@ func (c *client) DoAndGetResponseBody( ctx context.Context, method, uri, id string, params OrderedValues, headers map[string]string, - body interface{}) (*http.Response, bool, error) { - + body interface{}, +) (*http.Response, bool, error) { var ( err error req *http.Request @@ -617,7 +616,7 @@ func parseJSONError(r *http.Response) error { func (c *client) authenticate(ctx context.Context, username string, password string, endpoint string) error { headers := make(map[string]string, 1) headers[headerKeyContentType] = headerValContentTypeJSON - var data = &setupConnection{Services: []string{"platform", "namespace"}, Username: username, Password: password} + data := &setupConnection{Services: []string{"platform", "namespace"}, Username: username, Password: password} resp, _, err := c.DoAndGetResponseBody(ctx, http.MethodPost, "/session/1/session", "", nil, headers, data) if err != nil { return errors.New(fmt.Sprintf("Authentication error: %v", err)) @@ -699,8 +698,7 @@ func (c *client) executeWithRetryAuthenticate(ctx context.Context, method, uri s } func FetchValueIndexForKey(l string, match string, sep string) (int, int, int) { - - var startIndex, endIndex = -1, -1 + startIndex, endIndex := -1, -1 if strings.Contains(l, match) { startIndex = strings.Index(l, match) if startIndex != -1 && sep != "" { diff --git a/api/api_logging.go b/api/api_logging.go index 189f868..2cd09a2 100644 --- a/api/api_logging.go +++ b/api/api_logging.go @@ -21,11 +21,12 @@ import ( "context" "encoding/base64" "fmt" - log "github.com/akutz/gournal" "io" "net/http" "net/http/httputil" "strings" + + log "github.com/akutz/gournal" ) func isBinOctetBody(h http.Header) bool { @@ -40,10 +41,10 @@ func logRequest(ctx context.Context, w io.Writer, req *http.Request, verbose Ver switch verbose { case Verbose_Low: - //minimal logging, i.e. print request line only + // minimal logging, i.e. print request line only fmt.Fprintf(w, " %s %s %s\r\n", req.Method, req.URL.RequestURI(), req.Proto) default: - //full logging, i.e. print full request message content + // full logging, i.e. print full request message content buf, _ := httputil.DumpRequest(req, !isBinOctetBody(req.Header)) decodedBuf := encryptPassword(buf) WriteIndented(w, decodedBuf) @@ -63,17 +64,17 @@ func logResponse(ctx context.Context, res *http.Response, verbose VerboseType) { switch verbose { case Verbose_Low: - //minimal logging, i.e. pirnt status line only + // minimal logging, i.e. pirnt status line only fmt.Fprintf(w, " %s %s\r\n", res.Proto, res.Status) case Verbose_Medium: - //print status line + headers + // print status line + headers buf, _ = httputil.DumpResponse(res, false) default: - //print full response message content + // print full response message content buf, _ = httputil.DumpResponse(res, !isBinOctetBody(res.Header)) } - //when DumpResponse gets err, buf will be nil. No message content will be printed + // when DumpResponse gets err, buf will be nil. No message content will be printed WriteIndented(w, buf) log.Debug(ctx, w.String()) diff --git a/api/api_ordered_values.go b/api/api_ordered_values.go index 96a1736..e3d85e6 100644 --- a/api/api_ordered_values.go +++ b/api/api_ordered_values.go @@ -293,7 +293,6 @@ var hexChars = []byte{ } func escapeTo(w io.Writer, s []byte) error { - var ( hexCount = 0 spaceCount = 0 diff --git a/api/api_ordered_values_test.go b/api/api_ordered_values_test.go index fa84048..9ba1f0e 100644 --- a/api/api_ordered_values_test.go +++ b/api/api_ordered_values_test.go @@ -223,9 +223,9 @@ func TestParseQuery(t *testing.T) { func TestStructToOrderedValues(t *testing.T) { type TestStruct struct { - TestString *string `json:"test_string,omitempty"` - TestInt *int `json:"test_int,omitempty"` - TestBool *bool `json:"test_bool,omitempty"` + TestString *string `json:"test_string,omitempty"` + TestInt *int `json:"test_int,omitempty"` + TestBool *bool `json:"test_bool,omitempty"` IgnoredField string } testString := "A" diff --git a/api/common/utils/poll.go b/api/common/utils/poll.go index b66c0d5..a2dcc37 100644 --- a/api/common/utils/poll.go +++ b/api/common/utils/poll.go @@ -25,8 +25,10 @@ import ( var ErrWaitTimeout = errors.New("timed out waiting for the condition") -type WaitWithContextFunc func(ctx context.Context) <-chan struct{} -type ConditionWithContextFunc func(context.Context) (done bool, err error) +type ( + WaitWithContextFunc func(ctx context.Context) <-chan struct{} + ConditionWithContextFunc func(context.Context) (done bool, err error) +) func PollImmediateWithContext(ctx context.Context, interval, timeout time.Duration, condition ConditionWithContextFunc) error { return poll(ctx, true, poller(interval, timeout), condition) diff --git a/api/common/utils/utils.go b/api/common/utils/utils.go index 54f4da9..8482dbf 100644 --- a/api/common/utils/utils.go +++ b/api/common/utils/utils.go @@ -17,7 +17,6 @@ package utils // IsStringInSlice checks if a string is an element of a string slice func IsStringInSlice(str string, list []string) bool { - for _, b := range list { if b == str { return true @@ -29,7 +28,6 @@ func IsStringInSlice(str string, list []string) bool { // IsStringInSlices checks if a string is an element of a any of the string slices func IsStringInSlices(str string, list ...[]string) bool { - for _, strs := range list { if IsStringInSlice(str, strs) { return true @@ -41,7 +39,6 @@ func IsStringInSlices(str string, list ...[]string) bool { // RemoveStringFromSlice returns a slice that is a copy of the input "list" slice with the input "str" string removed func RemoveStringFromSlice(str string, list []string) []string { - result := make([]string, 0) for _, v := range list { @@ -55,11 +52,9 @@ func RemoveStringFromSlice(str string, list []string) []string { // RemoveStringsFromSlice generates a slice that is a copy of the input "list" slice with elements from the input "strs" slice removed func RemoveStringsFromSlice(filters []string, list []string) []string { - result := make([]string, 0) for _, str := range list { - if !IsStringInSlice(str, filters) { result = append(result, str) } diff --git a/api/common/utils/utils_test.go b/api/common/utils/utils_test.go index 3a8ba3f..493e91f 100644 --- a/api/common/utils/utils_test.go +++ b/api/common/utils/utils_test.go @@ -27,8 +27,7 @@ func TestMain(m *testing.M) { } func TestIsStringInSlice(t *testing.T) { - - var list = []string{"hello", "world", "jason"} + list := []string{"hello", "world", "jason"} assert.True(t, IsStringInSlice("world", list)) assert.False(t, IsStringInSlice("mary", list)) @@ -36,10 +35,9 @@ func TestIsStringInSlice(t *testing.T) { } func TestRemoveStringFromSlice(t *testing.T) { + list := []string{"hello", "world", "jason"} - var list = []string{"hello", "world", "jason"} - - var result = RemoveStringFromSlice("hello", list) + result := RemoveStringFromSlice("hello", list) assert.Equal(t, 3, len(list)) assert.Equal(t, 2, len(result)) @@ -50,12 +48,11 @@ func TestRemoveStringFromSlice(t *testing.T) { } func TestRemoveStringsFromSlice(t *testing.T) { + list := []string{"hello", "world", "jason"} - var list = []string{"hello", "world", "jason"} - - var filterList = []string{"hello", "there", "chap", "world"} + filterList := []string{"hello", "there", "chap", "world"} - var result = RemoveStringsFromSlice(filterList, list) + result := RemoveStringsFromSlice(filterList, list) assert.Equal(t, 1, len(result)) } diff --git a/api/json/json_decode.go b/api/json/json_decode.go index dfeb684..8278e06 100644 --- a/api/json/json_decode.go +++ b/api/json/json_decode.go @@ -548,8 +548,10 @@ func (d *decodeState) array(v reflect.Value) { } } -var nullLiteral = []byte("null") -var textUnmarshalerType = reflect.TypeOf(new(encoding.TextUnmarshaler)).Elem() +var ( + nullLiteral = []byte("null") + textUnmarshalerType = reflect.TypeOf(new(encoding.TextUnmarshaler)).Elem() +) // object consumes an object from d.data[d.off-1:], decoding into the value v. // the first byte ('{') of the object has been read already. @@ -784,7 +786,7 @@ var numberType = reflect.TypeOf(Number("")) func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool) { // Check for unmarshaler. if len(item) == 0 { - //Empty string given + // Empty string given d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) return } @@ -966,7 +968,7 @@ func (d *decodeState) valueInterface() interface{} { // arrayInterface is like array but returns []interface{}. func (d *decodeState) arrayInterface() []interface{} { - var v = make([]interface{}, 0) + v := make([]interface{}, 0) for { // Look ahead for ] - can only happen on first iteration. op := d.scanWhile(scanSkipSpace) diff --git a/api/json/json_stream.go b/api/json/json_stream.go index bebda6e..7892c65 100644 --- a/api/json/json_stream.go +++ b/api/json/json_stream.go @@ -260,8 +260,10 @@ func (m *RawMessage) UnmarshalJSON(data []byte) error { return nil } -var _ Marshaler = (*RawMessage)(nil) -var _ Unmarshaler = (*RawMessage)(nil) +var ( + _ Marshaler = (*RawMessage)(nil) + _ Unmarshaler = (*RawMessage)(nil) +) // A Token holds a value of one of these types: // diff --git a/api/v1/api_v1.go b/api/v1/api_v1.go index 158a27a..91199ac 100644 --- a/api/v1/api_v1.go +++ b/api/v1/api_v1.go @@ -39,9 +39,7 @@ const ( groupMemberPath = "platform/1/auth/groups/%s/members" ) -var ( - debug, _ = strconv.ParseBool(os.Getenv("GOISILON_DEBUG")) -) +var debug, _ = strconv.ParseBool(os.Getenv("GOISILON_DEBUG")) func realNamespacePath(client api.Client) string { return path.Join(namespacePath, client.VolumesPath()) @@ -52,7 +50,7 @@ func realexportsPath(client api.Client) string { } func realVolumeSnapshotPath(client api.Client, name, zonePath, accessZone string) string { - //Isi path is different from zone path + // Isi path is different from zone path volumeSnapshotPath := strings.Join([]string{zonePath, snapshotParentDir}, "/") if strings.Compare(zonePath, client.VolumesPath()) != 0 { parts := strings.SplitN(realNamespacePath(client), "/ifs", 2) @@ -60,7 +58,6 @@ func realVolumeSnapshotPath(client api.Client, name, zonePath, accessZone string } else { return path.Join(volumeSnapshotPath, name) } - } // GetAbsoluteSnapshotPath get the absolute path of a snapshot @@ -83,7 +80,7 @@ func GetRealVolumeSnapshotPathWithIsiPath(isiPath, zonePath, name, accessZone st parts := strings.SplitN(GetRealNamespacePathWithIsiPath(isiPath), "/ifs", 2) return path.Join(parts[0], volumeSnapshotPath, name, parts[1]) } else { - //if Isi path is different then zone path get remaining isiPath + // if Isi path is different then zone path get remaining isiPath _, remainIsiPath, found := strings.Cut(isiPath, zonePath) if found { return path.Join(namespacePath, zonePath, snapshotParentDir, name, remainIsiPath) @@ -96,7 +93,6 @@ func GetRealVolumeSnapshotPathWithIsiPath(isiPath, zonePath, name, accessZone st // getAuthMemberId reutrns actual auth id, which can be 'UID:0', 'USER:name', 'GID:0', 'GROUP:wheel', // memberType can be user/group. func getAuthMemberId(memberType string, memberName *string, memberId *int32) (authMemberId string, err error) { - memberType = strings.ToLower(memberType) if memberType != fileGroupTypeUser && memberType != fileGroupTypeGroup { return "", fmt.Errorf("member type is wrong, only support %s and %s", fileGroupTypeUser, fileGroupTypeGroup) diff --git a/api/v1/api_v1_exports.go b/api/v1/api_v1_exports.go index f6dbc04..60c2885 100644 --- a/api/v1/api_v1_exports.go +++ b/api/v1/api_v1_exports.go @@ -29,7 +29,8 @@ import ( func Export( ctx context.Context, client api.Client, - path string) (err error) { + path string, +) (err error) { // PAPI call: POST https://1.2.3.4:8080/platform/1/protocols/nfs/exports/ // Content-Type: application/json // {paths: ["/path/to/volume"]} @@ -38,7 +39,7 @@ func Export( return errors.New("no path set") } - var data = &ExportPathList{Paths: []string{path}} + data := &ExportPathList{Paths: []string{path}} data.MapAll.User = client.User() if group := client.Group(); group != "" { data.MapAll.Groups = append(data.MapAll.Groups, group) @@ -58,12 +59,13 @@ func Export( func SetExportClients( ctx context.Context, client api.Client, - Id int, clients []string) (err error) { + Id int, clients []string, +) (err error) { // PAPI call: PUT https://1.2.3.4:8080/platform/1/protocols/nfs/exports/Id // Content-Type: application/json // {clients: ["client_ip_address"]} - var data = &ExportClientList{Clients: clients} + data := &ExportClientList{Clients: clients} var resp *postIsiExportResp err = client.Put(ctx, exportsPath, strconv.Itoa(Id), nil, nil, data, &resp) @@ -75,7 +77,8 @@ func SetExportClients( func Unexport( ctx context.Context, client api.Client, - Id int) (err error) { + Id int, +) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/protocols/nfs/exports/23 if Id == 0 { @@ -93,8 +96,8 @@ func Unexport( // GetIsiExports queries a list of all exports on the cluster func GetIsiExports( ctx context.Context, - client api.Client) (resp *getIsiExportsResp, err error) { - + client api.Client, +) (resp *getIsiExportsResp, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/protocols/nfs/exports err = client.Get(ctx, exportsPath, "", nil, nil, &resp) diff --git a/api/v1/api_v1_quotas.go b/api/v1/api_v1_quotas.go index 81c045d..cea343e 100644 --- a/api/v1/api_v1_quotas.go +++ b/api/v1/api_v1_quotas.go @@ -26,13 +26,13 @@ import ( func GetIsiQuota( ctx context.Context, client api.Client, - path string) (quota *IsiQuota, err error) { - + path string, +) (quota *IsiQuota, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/quota/quotas?path=/path/to/volume // This will list the quota by path on the cluster var quotaResp isiQuotaListResp - var pathWithQueryParam = quotaPath + "?path=" + path + pathWithQueryParam := quotaPath + "?path=" + path err = client.Get(ctx, pathWithQueryParam, "", nil, nil, "aResp) if err != nil { return nil, err @@ -49,8 +49,8 @@ func GetIsiQuota( // GetAllIsiQuota queries all quotas on the cluster func GetAllIsiQuota( ctx context.Context, - client api.Client) (quotas []*IsiQuota, err error) { - + client api.Client, +) (quotas []*IsiQuota, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/quota/quotas var quotaResp *IsiQuotaListRespResume @@ -79,8 +79,8 @@ func GetAllIsiQuota( // GetIsiQuotaWithResume queries the next page quotas based on resume token func GetIsiQuotaWithResume( ctx context.Context, - client api.Client, resume string) (quotas *IsiQuotaListRespResume, err error) { - + client api.Client, resume string, +) (quotas *IsiQuotaListRespResume, err error) { var quotaResp IsiQuotaListRespResume err = client.Get(ctx, quotaPath, "", api.OrderedValues{ @@ -97,8 +97,8 @@ func GetIsiQuotaWithResume( func GetIsiQuotaByID( ctx context.Context, client api.Client, - ID string) (quota *IsiQuota, err error) { - + ID string, +) (quota *IsiQuota, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/quota/quotas/igSJAAEAAAAAAAAAAAAAQH0RAAAAAAAA // This will list the quota by id on the cluster @@ -122,8 +122,8 @@ func GetIsiQuotaByID( func CreateIsiQuota( ctx context.Context, client api.Client, - path string, container bool, size, softLimit, advisoryLimit, softGracePrd int64) (string, error) { - + path string, container bool, size, softLimit, advisoryLimit, softGracePrd int64, +) (string, error) { // PAPI call: POST https://1.2.3.4:8080/platform/1/quota/quotas // { "enforced" : true, // "include_snapshots" : false, @@ -136,8 +136,8 @@ func CreateIsiQuota( // "soft" : null // } // } - //body={'path': '/ifs/data/quotatest', 'thresholds': {'soft_grace': 86400L, 'soft': 1048576L}, 'include_snapshots': False, 'force': False, 'type': 'directory'} - //softGrace := 86400U + // body={'path': '/ifs/data/quotatest', 'thresholds': {'soft_grace': 86400L, 'soft': 1048576L}, 'include_snapshots': False, 'force': False, 'type': 'directory'} + // softGrace := 86400U thresholds := isiThresholdsReq{Advisory: advisoryLimit, Hard: size, Soft: softLimit, SoftGrace: softGracePrd} if advisoryLimit == 0 { thresholds.Advisory = nil @@ -168,8 +168,8 @@ func CreateIsiQuota( func SetIsiQuotaHardThreshold( ctx context.Context, client api.Client, - path string, size, softLimit, advisoryLimit,softGracePrd int64) (string, error) { - + path string, size, softLimit, advisoryLimit, softGracePrd int64, +) (string, error) { return CreateIsiQuota(ctx, client, path, false, size, softLimit, advisoryLimit, softGracePrd) } @@ -177,8 +177,8 @@ func SetIsiQuotaHardThreshold( func UpdateIsiQuotaHardThreshold( ctx context.Context, client api.Client, - path string, size, softLimit, advisoryLimit, softGracePrd int64) (err error) { - + path string, size, softLimit, advisoryLimit, softGracePrd int64, +) (err error) { // PAPI call: PUT https://1.2.3.4:8080/platform/1/quota/quotas/Id // { "enforced" : true, // "thresholds_include_overhead" : false, @@ -198,7 +198,7 @@ func UpdateIsiQuotaHardThreshold( thresholds.SoftGrace = nil } - var data = &IsiUpdateQuotaReq{ + data := &IsiUpdateQuotaReq{ Enforced: true, ThresholdsIncludeOverhead: false, Thresholds: thresholds, @@ -218,8 +218,8 @@ func UpdateIsiQuotaHardThreshold( func UpdateIsiQuotaHardThresholdByID( ctx context.Context, client api.Client, - ID string, size, softLimit, advisoryLimit, softGracePrd int64) (err error) { - + ID string, size, softLimit, advisoryLimit, softGracePrd int64, +) (err error) { // PAPI call: PUT https://1.2.3.4:8080/platform/1/quota/quotas/Id // { "enforced" : true, // "thresholds_include_overhead" : false, @@ -238,7 +238,7 @@ func UpdateIsiQuotaHardThresholdByID( if softGracePrd == 0 { thresholds.SoftGrace = nil } - var data = &IsiUpdateQuotaReq{ + data := &IsiUpdateQuotaReq{ Enforced: true, ThresholdsIncludeOverhead: false, Thresholds: thresholds, @@ -249,15 +249,17 @@ func UpdateIsiQuotaHardThresholdByID( return err } -var byteArrPath = []byte("path") -var byteArrID = []byte("id") +var ( + byteArrPath = []byte("path") + byteArrID = []byte("id") +) // DeleteIsiQuota removes the quota for a directory func DeleteIsiQuota( ctx context.Context, client api.Client, - path string) (err error) { - + path string, +) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/quota/quotas?path=/path/to/volume // This will remove a the quota on a volume @@ -274,8 +276,8 @@ func DeleteIsiQuota( func DeleteIsiQuotaByID( ctx context.Context, client api.Client, - id string) (err error) { - + id string, +) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/quota/quotas/AABpAQEAAAAAAAAAAAAAQA0AAAAAAAAA // This will remove a the quota on a volume by the quota id @@ -292,8 +294,8 @@ func DeleteIsiQuotaByID( func DeleteIsiQuotaByIDWithZone( ctx context.Context, client api.Client, - id, zone string) (err error) { - + id, zone string, +) (err error) { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/quota/quotas/AABpAQEAAAAAAAAAAAAAQA0AAAAAAAAA // This will remove a the quota on a volume by the quota id diff --git a/api/v1/api_v1_roles.go b/api/v1/api_v1_roles.go index 2497089..7e37530 100644 --- a/api/v1/api_v1_roles.go +++ b/api/v1/api_v1_roles.go @@ -25,7 +25,6 @@ import ( // GetIsiRole queries the role by role-id. func GetIsiRole(ctx context.Context, client api.Client, roleId string) (role *IsiRole, err error) { - // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/roles/ var roleResp *isiRoleListResp @@ -43,7 +42,6 @@ func GetIsiRole(ctx context.Context, client api.Client, roleId string) (role *Is // GetIsiRoleList queries all roles on the cluster, filter by limit or resolveNames. func GetIsiRoleList(ctx context.Context, client api.Client, queryResolveNames *bool, queryLimit *int32) (roles []*IsiRole, err error) { - // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/roles?resolve_names=&limit= values := api.OrderedValues{} if queryResolveNames != nil { @@ -75,14 +73,12 @@ func GetIsiRoleList(ctx context.Context, client api.Client, queryResolveNames *b // getIsiRoleListWithResume queries the next page roles based on resume token. func getIsiRoleListWithResume(ctx context.Context, client api.Client, resume string) (roles *IsiRoleListRespResume, err error) { - err = client.Get(ctx, rolePath, "", api.OrderedValues{{[]byte("resume"), []byte(resume)}}, nil, &roles) return } // AddIsiRoleMember adds a member to the role, member can be user/group. func AddIsiRoleMember(ctx context.Context, client api.Client, roleID string, member IsiAuthMemberItem) error { - // PAPI call: POST https://1.2.3.4:8080/platform/1/roles/{role-id}/members // { // "type":"user", @@ -110,7 +106,6 @@ func AddIsiRoleMember(ctx context.Context, client api.Client, roleID string, mem // RemoveIsiRoleMember remove a member from the role, member can be user/group. func RemoveIsiRoleMember(ctx context.Context, client api.Client, roleID string, member IsiAuthMemberItem) error { - // PAPI call: DELETE https://1.2.3.4:8080/platform/1/roles/{role-id}/members/ authMemberId, err := getAuthMemberId(member.Type, member.Name, member.Id) diff --git a/api/v1/api_v1_snapshots.go b/api/v1/api_v1_snapshots.go index 1f11129..44e0ef8 100644 --- a/api/v1/api_v1_snapshots.go +++ b/api/v1/api_v1_snapshots.go @@ -19,14 +19,16 @@ import ( "context" "errors" "fmt" - "github.com/dell/goisilon/api" "path" + + "github.com/dell/goisilon/api" ) // GetIsiSnapshots queries a list of all snapshots on the cluster func GetIsiSnapshots( ctx context.Context, - client api.Client) (resp *getIsiSnapshotsResp, err error) { + client api.Client, +) (resp *getIsiSnapshotsResp, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/snapshot/snapshots err = client.Get(ctx, snapshotsPath, "", nil, nil, &resp) if err != nil { @@ -39,7 +41,8 @@ func GetIsiSnapshots( func GetIsiSnapshot( ctx context.Context, client api.Client, - id int64) (*IsiSnapshot, error) { + id int64, +) (*IsiSnapshot, error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/snapshot/snapshots/123 snapshotURL := fmt.Sprintf("%s/%d", snapshotsPath, id) var resp *getIsiSnapshotsResp @@ -58,7 +61,8 @@ func GetIsiSnapshot( func GetIsiSnapshotByIdentity( ctx context.Context, client api.Client, - identity string) (*IsiSnapshot, error) { + identity string, +) (*IsiSnapshot, error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/snapshot/snapshots/id|name snapshotURL := fmt.Sprintf("%s/%s", snapshotsPath, identity) var resp *getIsiSnapshotsResp @@ -76,7 +80,8 @@ func GetIsiSnapshotByIdentity( func CreateIsiSnapshot( ctx context.Context, client api.Client, - path, name string) (resp *IsiSnapshot, err error) { + path, name string, +) (resp *IsiSnapshot, err error) { // PAPI call: POST https://1.2.3.4:8080/platform/1/snapshot/snapshots // Content-Type: application/json // {path: "/path/to/volume" @@ -102,7 +107,8 @@ func CreateIsiSnapshot( func CopyIsiSnapshot( ctx context.Context, client api.Client, - sourceSnapshotName, sourceVolume, destinationName string, zonePath, accessZone string) (resp *IsiVolume, err error) { + sourceSnapshotName, sourceVolume, destinationName string, zonePath, accessZone string, +) (resp *IsiVolume, err error) { // PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/destination_volume_name?merge=True // x-isi-ifs-copy-source: /path/to/snapshot/volumes/source_volume_name @@ -122,7 +128,8 @@ func CopyIsiSnapshot( func CopyIsiSnapshotWithIsiPath( ctx context.Context, client api.Client, - isiPath, snapshotSourceVolumeIsiPath, sourceSnapshotName, sourceVolume, destinationName string, accessZone string) (resp *IsiCopySnapshotResp, err error) { + isiPath, snapshotSourceVolumeIsiPath, sourceSnapshotName, sourceVolume, destinationName string, accessZone string, +) (resp *IsiCopySnapshotResp, err error) { // PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/destination_volume_name?merge=True // x-isi-ifs-copy-source: /path/to/snapshot/volumes/source_volume_name // x-isi-ifs-mode-mask: preserve @@ -147,7 +154,8 @@ func CopyIsiSnapshotWithIsiPath( func RemoveIsiSnapshot( ctx context.Context, client api.Client, - id int64) error { + id int64, +) error { // PAPI call: DELETE https://1.2.3.4:8080/platform/1/snapshot/snapshots/123 snapshotURL := fmt.Sprintf("%s/%d", snapshotsPath, id) err := client.Delete(ctx, snapshotURL, "", nil, nil, nil) @@ -159,8 +167,8 @@ func RemoveIsiSnapshot( func GetIsiSnapshotFolderWithSize( ctx context.Context, client api.Client, - isiPath, name, volume string, accessZone string) (resp *getIsiVolumeSizeResp, err error) { - + isiPath, name, volume string, accessZone string, +) (resp *getIsiVolumeSizeResp, err error) { // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/snapshot?detail=size&max-depth=-1 zone, err := GetZoneByName(ctx, client, accessZone) if err != nil { diff --git a/api/v1/api_v1_user_groups.go b/api/v1/api_v1_user_groups.go index bc07471..020b2b6 100644 --- a/api/v1/api_v1_user_groups.go +++ b/api/v1/api_v1_user_groups.go @@ -25,7 +25,6 @@ import ( // GetIsiGroup queries the group by group-id. func GetIsiGroup(ctx context.Context, client api.Client, groupName *string, gid *int32) (group *IsiGroup, err error) { - // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/groups/ authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) @@ -51,8 +50,8 @@ func GetIsiGroup(ctx context.Context, client api.Client, groupName *string, gid func GetIsiGroupList(ctx context.Context, client api.Client, queryNamePrefix, queryDomain, queryZone, queryProvider *string, queryCached, queryResolveNames, queryMemberOf *bool, - queryLimit *int32) (groups []*IsiGroup, err error) { - + queryLimit *int32, +) (groups []*IsiGroup, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/groups?limit=&domain=&cached=&resolve_names=&query_member_of=&zone=&provider=&filter= values := api.OrderedValues{} if queryCached != nil { @@ -101,14 +100,12 @@ func GetIsiGroupList(ctx context.Context, client api.Client, // getIsiGroupListWithResume queries the next page groups based on resume token. func getIsiGroupListWithResume(ctx context.Context, client api.Client, resume string) (groups *IsiGroupListRespResume, err error) { - err = client.Get(ctx, groupPath, "", api.OrderedValues{{[]byte("resume"), []byte(resume)}}, nil, &groups) return } // GetIsiGroupMembers retrieves the members of a group. func GetIsiGroupMembers(ctx context.Context, client api.Client, groupName *string, gid *int32) (members []*IsiAccessItemFileGroup, err error) { - // PAPI call: GET https://1.2.3.4:8080/platform/1/groups/{group-id}/members authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) @@ -137,14 +134,12 @@ func GetIsiGroupMembers(ctx context.Context, client api.Client, groupName *strin // getIsiGroupMemberListWithResume queries the next page group members based on resume token. func getIsiGroupMemberListWithResume(ctx context.Context, client api.Client, groupId, resume string) (members *IsiGroupMemberListRespResume, err error) { - err = client.Get(ctx, fmt.Sprintf(groupMemberPath, groupId), "", api.OrderedValues{{[]byte("resume"), []byte(resume)}}, nil, &members) return } // AddIsiGroupMember adds a member to the group, member can be a user/group. func AddIsiGroupMember(ctx context.Context, client api.Client, groupName *string, gid *int32, member IsiAuthMemberItem) error { - // PAPI call: POST https://1.2.3.4:8080/platform/1/groups/{group-id}/members // { // "type":"user", @@ -175,7 +170,6 @@ func AddIsiGroupMember(ctx context.Context, client api.Client, groupName *string // RemoveIsiGroupMember remove a member from the group, member can be user/group. func RemoveIsiGroupMember(ctx context.Context, client api.Client, groupName *string, gid *int32, member IsiAuthMemberItem) error { - // PAPI call: DELETE https://1.2.3.4:8080/platform/1/groups/{group-id}/members/ authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) @@ -194,8 +188,8 @@ func RemoveIsiGroupMember(ctx context.Context, client api.Client, groupName *str // CreateIsiGroup creates a new group. func CreateIsiGroup(ctx context.Context, client api.Client, name string, gid *int32, members []IsiAuthMemberItem, - queryForce *bool, queryZone, queryProvider *string) (string, error) { - + queryForce *bool, queryZone, queryProvider *string, +) (string, error) { // PAPI call: POST https://1.2.3.4:8080/platform/1/auth/groups?force=&zone=&provider= // { // "gid": "int", @@ -260,8 +254,8 @@ func CreateIsiGroup(ctx context.Context, client api.Client, // UpdateIsiGroupGID updates the group's gid. func UpdateIsiGroupGID(ctx context.Context, client api.Client, groupName *string, gid *int32, newGid int32, - queryZone, queryProvider *string) (err error) { - + queryZone, queryProvider *string, +) (err error) { // PAPI call: PUT https://1.2.3.4:8080/platform/1/auth/groups/?force=true&zone=&provider= // { // "gid": int @@ -288,7 +282,6 @@ func UpdateIsiGroupGID(ctx context.Context, client api.Client, groupName *string // DeleteIsiGroup removes the group by group-id. func DeleteIsiGroup(ctx context.Context, client api.Client, groupName *string, gid *int32) (err error) { - // PAPI call: DELETE https://1.2.3.4:8080/platform/1/auth/groups/ authGroupId, err := getAuthMemberId(fileGroupTypeGroup, groupName, gid) if err != nil { diff --git a/api/v1/api_v1_users.go b/api/v1/api_v1_users.go index f6aee36..2d4bd58 100644 --- a/api/v1/api_v1_users.go +++ b/api/v1/api_v1_users.go @@ -24,7 +24,6 @@ import ( // GetIsiUser queries the user by user user-id. func GetIsiUser(ctx context.Context, client api.Client, userName *string, uid *int32) (user *IsiUser, err error) { - // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/users/ authUserId, err := getAuthMemberId(fileGroupTypeUser, userName, uid) @@ -50,8 +49,8 @@ func GetIsiUser(ctx context.Context, client api.Client, userName *string, uid *i func GetIsiUserList(ctx context.Context, client api.Client, queryNamePrefix, queryDomain, queryZone, queryProvider *string, queryCached, queryResolveNames, queryMemberOf *bool, - queryLimit *int32) (users []*IsiUser, err error) { - + queryLimit *int32, +) (users []*IsiUser, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/1/auth/users?limit=&cached=&resolve_names=&query_member_of=&zone=&provider= values := api.OrderedValues{} if queryCached != nil { @@ -99,7 +98,6 @@ func GetIsiUserList(ctx context.Context, client api.Client, // getIsiUserListWithResume queries the next page users based on resume token. func getIsiUserListWithResume(ctx context.Context, client api.Client, resume string) (users *IsiUserListRespResume, err error) { - err = client.Get(ctx, userPath, "", api.OrderedValues{{[]byte("resume"), []byte(resume)}}, nil, &users) return } @@ -108,8 +106,8 @@ func getIsiUserListWithResume(ctx context.Context, client api.Client, resume str func CreateIsiUser(ctx context.Context, client api.Client, name string, queryForce *bool, queryZone, queryProvider *string, email, homeDirectory, password, primaryGroupName, fullName, shell *string, - uid, primaryGroupId, expiry *int32, enabled, passwordExpires, promptPasswordChange, unlock *bool) (string, error) { - + uid, primaryGroupId, expiry *int32, enabled, passwordExpires, promptPasswordChange, unlock *bool, +) (string, error) { // PAPI call: POST https://1.2.3.4:8080/platform/1/auth/users?force=&zone=&provider= // { // "email": "str", @@ -183,8 +181,8 @@ func CreateIsiUser(ctx context.Context, client api.Client, name string, func UpdateIsiUser(ctx context.Context, client api.Client, userName *string, uid *int32, queryForce *bool, queryZone, queryProvider *string, email, homeDirectory, password, primaryGroupName, fullName, shell *string, - newUid, primaryGroupId, expiry *int32, enabled, passwordExpires, promptPasswordChange, unlock *bool) (err error) { - + newUid, primaryGroupId, expiry *int32, enabled, passwordExpires, promptPasswordChange, unlock *bool, +) (err error) { // PAPI call: PUT https://1.2.3.4:8080/platform/1/auth/users/?force=&zone=&provider= // { // "email": "str", @@ -254,7 +252,6 @@ func UpdateIsiUser(ctx context.Context, client api.Client, userName *string, uid // DeleteIsiUser removes the user by user-id. func DeleteIsiUser(ctx context.Context, client api.Client, userName *string, uid *int32) (err error) { - // PAPI call: DELETE https://1.2.3.4:8080/platform/1/auth/users/ authUserId, err := getAuthMemberId(fileGroupTypeUser, userName, uid) diff --git a/api/v1/api_v1_volumes.go b/api/v1/api_v1_volumes.go index 25d1e1e..3aa6ace 100644 --- a/api/v1/api_v1_volumes.go +++ b/api/v1/api_v1_volumes.go @@ -1,362 +1,368 @@ -/* -Copyright (c) 2019 Dell Inc, or its subsidiaries. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package v1 - -import ( - "context" - "github.com/dell/goisilon/api" - "path" -) - -// const defaultACL = "public_read_write" -const defaultACL = "0777" - -var ( - aclQS = api.OrderedValues{{[]byte("acl")}} - metadataQS = api.OrderedValues{{[]byte("metadata")}} - recursiveTrueQS = api.OrderedValues{ - {[]byte("recursive"), []byte("true")}, - } - sizeQS = api.OrderedValues{ - {[]byte("detail"), []byte("size")}, - {[]byte("max-depth"), []byte("-1")}, - } - mergeQS = api.OrderedValues{ - {[]byte("merge"), []byte("True")}, - } -) - -// GetIsiVolumes queries a list of all volumes on the cluster -func GetIsiVolumes( - ctx context.Context, - client api.Client) (resp *getIsiVolumesResp, err error) { - - // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volumes/ - err = client.Get(ctx, realNamespacePath(client), "", nil, nil, &resp) - return resp, err -} - -// CreateIsiVolume makes a new volume on the cluster -func CreateIsiVolume( - ctx context.Context, - client api.Client, - name string) (resp *getIsiVolumesResp, err error) { - - return CreateIsiVolumeWithACL(ctx, client, name, defaultACL) -} - -// CreateIsiVolumeWithIsiPath makes a new volume with isiPath on the cluster -func CreateIsiVolumeWithIsiPath( - ctx context.Context, - client api.Client, - isiPath, name, isiVolumePathPermissions string) (resp *getIsiVolumesResp, err error) { - return CreateIsiVolumeWithACLAndIsiPath(ctx, client, isiPath, name, isiVolumePathPermissions) -} - -// CreateIsiVolumeWithIsiPathMetaData makes a new volume with isiPath on the cluster -func CreateIsiVolumeWithIsiPathMetaData( - ctx context.Context, - client api.Client, - isiPath, name, isiVolumePathPermissions string, metadata map[string]string) (resp *getIsiVolumesResp, err error) { - return CreateIsiVolumeWithACLAndIsiPathMetaData(ctx, client, isiPath, name, isiVolumePathPermissions, metadata) -} - -// CreateIsiVolumeWithACL makes a new volume on the cluster with the specified permissions -func CreateIsiVolumeWithACL( - ctx context.Context, - client api.Client, - name, ACL string) (resp *getIsiVolumesResp, err error) { - - // PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/volume_name - // x-isi-ifs-target-type: container - // x-isi-ifs-access-control: ACL - // - // PUT https://1.2.3.4:8080/namespace/path/to/volumes/volume_name?acl - // {authoritative: "acl", - // action: "update", - // owner: {name: "username", type: "user"}, - // group: {name: "groupname", type: "group"} - // } - - createVolumeHeaders := map[string]string{ - "x-isi-ifs-target-type": "container", - "x-isi-ifs-access-control": ACL, - } - - // create the volume - err = client.Put( - ctx, - realNamespacePath(client), - name, - nil, - createVolumeHeaders, - nil, - &resp) - - // The following code is completely pointless and also counterproductive - - // The folder is already owned by client.User() because that is the user - // that we authenticated to the API with. It's useless additional work that - // also fails if the parent doesn't have an ACL granting us std_write_owner - /* - if err != nil { - return resp, err - } - var data = &AclRequest{ - "acl", - "update", - &Ownership{client.User(), "user"}, - nil, - } - - if group := client.Group(); group != "" { - data.Group = &Ownership{group, "group"} - } - - // set the ownership of the volume - err = client.Put( - ctx, - realNamespacePath(client), - name, - aclQS, - nil, - data, - &resp) - */ - - return resp, err -} - -// CreateIsiVolumeWithACLAndIsiPath makes a new volume on the cluster with the specified permissions and isiPath -func CreateIsiVolumeWithACLAndIsiPath( - ctx context.Context, - client api.Client, - isiPath, name, ACL string) (resp *getIsiVolumesResp, err error) { - - createVolumeHeaders := map[string]string{ - "x-isi-ifs-target-type": "container", - "x-isi-ifs-access-control": ACL, - } - // create the volume - err = client.Put( - ctx, - GetRealNamespacePathWithIsiPath(isiPath), - name, - nil, - createVolumeHeaders, - nil, - &resp) - return resp, err -} - -// CreateIsiVolumeWithACLAndIsiPathMetadata makes a new volume on the cluster with the specified permissions and isiPath -func CreateIsiVolumeWithACLAndIsiPathMetaData( - ctx context.Context, - client api.Client, - isiPath, name, ACL string, metadata map[string]string) (resp *getIsiVolumesResp, err error) { - var createVolumeHeaders = make(map[string]string) - - createVolumeHeaders["x-isi-ifs-target-type"] = "container" - createVolumeHeaders["x-isi-ifs-access-control"] = ACL - - if len(metadata) != 0 { - for key, value := range metadata { - createVolumeHeaders[key] = value - } - } - - // create the volume - err = client.Put( - ctx, - GetRealNamespacePathWithIsiPath(isiPath), - name, - nil, - createVolumeHeaders, - nil, - &resp) - return resp, err -} - -// GetIsiVolume queries the attributes of a volume on the cluster -func GetIsiVolume( - ctx context.Context, - client api.Client, - name string) (resp *getIsiVolumeAttributesResp, err error) { - - // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/?metadata - err = client.Get( - ctx, - realNamespacePath(client), - name, - metadataQS, - nil, - &resp) - return resp, err -} - -// GetIsiVolumeWithIsiPath queries the attributes of a volume with isiPath on the cluster -func GetIsiVolumeWithIsiPath( - ctx context.Context, - client api.Client, - isiPath, name string) (resp *getIsiVolumeAttributesResp, err error) { - - // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/?metadata - err = client.Get( - ctx, - GetRealNamespacePathWithIsiPath(isiPath), - name, - metadataQS, - nil, - &resp) - return resp, err -} - -// GetIsiVolumeWithoutMetadata is used to check whether a volume exists thus the url does not append the metadata parameter. -func GetIsiVolumeWithoutMetadata( - ctx context.Context, - client api.Client, - name string) (err error) { - - // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/ - err = client.Get( - ctx, - realNamespacePath(client), - name, - nil, - nil, - &getIsiVolumeResp{}) - - return err -} - -// GetIsiVolumeWithoutMetadataWithIsiPath is used to check whether a volume exists with isiPath thus the url does not append the metadata parameter. -func GetIsiVolumeWithoutMetadataWithIsiPath( - ctx context.Context, - client api.Client, - isiPath, name string) (err error) { - - // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/ - err = client.Get( - ctx, - GetRealNamespacePathWithIsiPath(isiPath), - name, - nil, - nil, - &getIsiVolumeResp{}) - - return err -} - -// DeleteIsiVolume removes a volume from the cluster -func DeleteIsiVolume( - ctx context.Context, - client api.Client, - name string) (resp *getIsiVolumesResp, err error) { - - err = client.Delete( - ctx, - realNamespacePath(client), - name, - recursiveTrueQS, - nil, - &resp) - return resp, err -} - -// DeleteIsiVolumeWithIsiPath removes a volume from the cluster with isiPath -func DeleteIsiVolumeWithIsiPath( - ctx context.Context, - client api.Client, - isiPath, name string) (resp *getIsiVolumesResp, err error) { - - err = client.Delete( - ctx, - GetRealNamespacePathWithIsiPath(isiPath), - name, - recursiveTrueQS, - nil, - &resp) - return resp, err -} - -// CopyIsiVolume creates a new volume on the cluster based on an existing volume -func CopyIsiVolume( - ctx context.Context, - client api.Client, - sourceName, destinationName string) (resp *getIsiVolumesResp, err error) { - // PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/destination_volume_name?merge=True - // x-isi-ifs-copy-source: /path/to/volumes/source_volume_name - - // copy the volume - err = client.Put( - ctx, - realNamespacePath(client), - destinationName, - mergeQS, - map[string]string{ - "x-isi-ifs-copy-source": path.Join( - "/", - realNamespacePath(client), - sourceName), - }, - nil, - &resp) - return resp, err -} - -// CopyIsiVolumeWithIsiPath creates a new volume with isiPath on the cluster based on an existing volume -func CopyIsiVolumeWithIsiPath( - ctx context.Context, - client api.Client, - isiPath, sourceName, destinationName string) (resp *getIsiVolumesResp, err error) { - // PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/destination_volume_name?merge=True - // x-isi-ifs-copy-source: /path/to/volumes/source_volume_name - // x-isi-ifs-mode-mask: preserve - - // copy the volume - err = client.Put( - ctx, - GetRealNamespacePathWithIsiPath(isiPath), - destinationName, - mergeQS, - map[string]string{ - "x-isi-ifs-copy-source": path.Join( - "/", - GetRealNamespacePathWithIsiPath(isiPath), - sourceName), - "x-isi-ifs-mode-mask": "preserve", - }, - nil, - &resp) - return resp, err -} - -// GetIsiVolumeWithSize lists size of all the children files and subfolders in a directory -func GetIsiVolumeWithSize( - ctx context.Context, - client api.Client, - isiPath, name string) (resp *getIsiVolumeSizeResp, err error) { - - // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume?detail=size&max-depth=-1 - err = client.Get( - ctx, - GetRealNamespacePathWithIsiPath(isiPath), - name, - sizeQS, - nil, - &resp) - - return resp, err -} +/* +Copyright (c) 2019 Dell Inc, or its subsidiaries. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package v1 + +import ( + "context" + "path" + + "github.com/dell/goisilon/api" +) + +// const defaultACL = "public_read_write" +const defaultACL = "0777" + +var ( + aclQS = api.OrderedValues{{[]byte("acl")}} + metadataQS = api.OrderedValues{{[]byte("metadata")}} + recursiveTrueQS = api.OrderedValues{ + {[]byte("recursive"), []byte("true")}, + } + sizeQS = api.OrderedValues{ + {[]byte("detail"), []byte("size")}, + {[]byte("max-depth"), []byte("-1")}, + } + mergeQS = api.OrderedValues{ + {[]byte("merge"), []byte("True")}, + } +) + +// GetIsiVolumes queries a list of all volumes on the cluster +func GetIsiVolumes( + ctx context.Context, + client api.Client, +) (resp *getIsiVolumesResp, err error) { + // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volumes/ + err = client.Get(ctx, realNamespacePath(client), "", nil, nil, &resp) + return resp, err +} + +// CreateIsiVolume makes a new volume on the cluster +func CreateIsiVolume( + ctx context.Context, + client api.Client, + name string, +) (resp *getIsiVolumesResp, err error) { + return CreateIsiVolumeWithACL(ctx, client, name, defaultACL) +} + +// CreateIsiVolumeWithIsiPath makes a new volume with isiPath on the cluster +func CreateIsiVolumeWithIsiPath( + ctx context.Context, + client api.Client, + isiPath, name, isiVolumePathPermissions string, +) (resp *getIsiVolumesResp, err error) { + return CreateIsiVolumeWithACLAndIsiPath(ctx, client, isiPath, name, isiVolumePathPermissions) +} + +// CreateIsiVolumeWithIsiPathMetaData makes a new volume with isiPath on the cluster +func CreateIsiVolumeWithIsiPathMetaData( + ctx context.Context, + client api.Client, + isiPath, name, isiVolumePathPermissions string, metadata map[string]string, +) (resp *getIsiVolumesResp, err error) { + return CreateIsiVolumeWithACLAndIsiPathMetaData(ctx, client, isiPath, name, isiVolumePathPermissions, metadata) +} + +// CreateIsiVolumeWithACL makes a new volume on the cluster with the specified permissions +func CreateIsiVolumeWithACL( + ctx context.Context, + client api.Client, + name, ACL string, +) (resp *getIsiVolumesResp, err error) { + // PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/volume_name + // x-isi-ifs-target-type: container + // x-isi-ifs-access-control: ACL + // + // PUT https://1.2.3.4:8080/namespace/path/to/volumes/volume_name?acl + // {authoritative: "acl", + // action: "update", + // owner: {name: "username", type: "user"}, + // group: {name: "groupname", type: "group"} + // } + + createVolumeHeaders := map[string]string{ + "x-isi-ifs-target-type": "container", + "x-isi-ifs-access-control": ACL, + } + + // create the volume + err = client.Put( + ctx, + realNamespacePath(client), + name, + nil, + createVolumeHeaders, + nil, + &resp) + + // The following code is completely pointless and also counterproductive - + // The folder is already owned by client.User() because that is the user + // that we authenticated to the API with. It's useless additional work that + // also fails if the parent doesn't have an ACL granting us std_write_owner + /* + if err != nil { + return resp, err + } + var data = &AclRequest{ + "acl", + "update", + &Ownership{client.User(), "user"}, + nil, + } + + if group := client.Group(); group != "" { + data.Group = &Ownership{group, "group"} + } + + // set the ownership of the volume + err = client.Put( + ctx, + realNamespacePath(client), + name, + aclQS, + nil, + data, + &resp) + */ + + return resp, err +} + +// CreateIsiVolumeWithACLAndIsiPath makes a new volume on the cluster with the specified permissions and isiPath +func CreateIsiVolumeWithACLAndIsiPath( + ctx context.Context, + client api.Client, + isiPath, name, ACL string, +) (resp *getIsiVolumesResp, err error) { + createVolumeHeaders := map[string]string{ + "x-isi-ifs-target-type": "container", + "x-isi-ifs-access-control": ACL, + } + // create the volume + err = client.Put( + ctx, + GetRealNamespacePathWithIsiPath(isiPath), + name, + nil, + createVolumeHeaders, + nil, + &resp) + return resp, err +} + +// CreateIsiVolumeWithACLAndIsiPathMetadata makes a new volume on the cluster with the specified permissions and isiPath +func CreateIsiVolumeWithACLAndIsiPathMetaData( + ctx context.Context, + client api.Client, + isiPath, name, ACL string, metadata map[string]string, +) (resp *getIsiVolumesResp, err error) { + createVolumeHeaders := make(map[string]string) + + createVolumeHeaders["x-isi-ifs-target-type"] = "container" + createVolumeHeaders["x-isi-ifs-access-control"] = ACL + + if len(metadata) != 0 { + for key, value := range metadata { + createVolumeHeaders[key] = value + } + } + + // create the volume + err = client.Put( + ctx, + GetRealNamespacePathWithIsiPath(isiPath), + name, + nil, + createVolumeHeaders, + nil, + &resp) + return resp, err +} + +// GetIsiVolume queries the attributes of a volume on the cluster +func GetIsiVolume( + ctx context.Context, + client api.Client, + name string, +) (resp *getIsiVolumeAttributesResp, err error) { + // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/?metadata + err = client.Get( + ctx, + realNamespacePath(client), + name, + metadataQS, + nil, + &resp) + return resp, err +} + +// GetIsiVolumeWithIsiPath queries the attributes of a volume with isiPath on the cluster +func GetIsiVolumeWithIsiPath( + ctx context.Context, + client api.Client, + isiPath, name string, +) (resp *getIsiVolumeAttributesResp, err error) { + // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/?metadata + err = client.Get( + ctx, + GetRealNamespacePathWithIsiPath(isiPath), + name, + metadataQS, + nil, + &resp) + return resp, err +} + +// GetIsiVolumeWithoutMetadata is used to check whether a volume exists thus the url does not append the metadata parameter. +func GetIsiVolumeWithoutMetadata( + ctx context.Context, + client api.Client, + name string, +) (err error) { + // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/ + err = client.Get( + ctx, + realNamespacePath(client), + name, + nil, + nil, + &getIsiVolumeResp{}) + + return err +} + +// GetIsiVolumeWithoutMetadataWithIsiPath is used to check whether a volume exists with isiPath thus the url does not append the metadata parameter. +func GetIsiVolumeWithoutMetadataWithIsiPath( + ctx context.Context, + client api.Client, + isiPath, name string, +) (err error) { + // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/ + err = client.Get( + ctx, + GetRealNamespacePathWithIsiPath(isiPath), + name, + nil, + nil, + &getIsiVolumeResp{}) + + return err +} + +// DeleteIsiVolume removes a volume from the cluster +func DeleteIsiVolume( + ctx context.Context, + client api.Client, + name string, +) (resp *getIsiVolumesResp, err error) { + err = client.Delete( + ctx, + realNamespacePath(client), + name, + recursiveTrueQS, + nil, + &resp) + return resp, err +} + +// DeleteIsiVolumeWithIsiPath removes a volume from the cluster with isiPath +func DeleteIsiVolumeWithIsiPath( + ctx context.Context, + client api.Client, + isiPath, name string, +) (resp *getIsiVolumesResp, err error) { + err = client.Delete( + ctx, + GetRealNamespacePathWithIsiPath(isiPath), + name, + recursiveTrueQS, + nil, + &resp) + return resp, err +} + +// CopyIsiVolume creates a new volume on the cluster based on an existing volume +func CopyIsiVolume( + ctx context.Context, + client api.Client, + sourceName, destinationName string, +) (resp *getIsiVolumesResp, err error) { + // PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/destination_volume_name?merge=True + // x-isi-ifs-copy-source: /path/to/volumes/source_volume_name + + // copy the volume + err = client.Put( + ctx, + realNamespacePath(client), + destinationName, + mergeQS, + map[string]string{ + "x-isi-ifs-copy-source": path.Join( + "/", + realNamespacePath(client), + sourceName), + }, + nil, + &resp) + return resp, err +} + +// CopyIsiVolumeWithIsiPath creates a new volume with isiPath on the cluster based on an existing volume +func CopyIsiVolumeWithIsiPath( + ctx context.Context, + client api.Client, + isiPath, sourceName, destinationName string, +) (resp *getIsiVolumesResp, err error) { + // PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/destination_volume_name?merge=True + // x-isi-ifs-copy-source: /path/to/volumes/source_volume_name + // x-isi-ifs-mode-mask: preserve + + // copy the volume + err = client.Put( + ctx, + GetRealNamespacePathWithIsiPath(isiPath), + destinationName, + mergeQS, + map[string]string{ + "x-isi-ifs-copy-source": path.Join( + "/", + GetRealNamespacePathWithIsiPath(isiPath), + sourceName), + "x-isi-ifs-mode-mask": "preserve", + }, + nil, + &resp) + return resp, err +} + +// GetIsiVolumeWithSize lists size of all the children files and subfolders in a directory +func GetIsiVolumeWithSize( + ctx context.Context, + client api.Client, + isiPath, name string, +) (resp *getIsiVolumeSizeResp, err error) { + // PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume?detail=size&max-depth=-1 + err = client.Get( + ctx, + GetRealNamespacePathWithIsiPath(isiPath), + name, + sizeQS, + nil, + &resp) + + return resp, err +} diff --git a/api/v1/api_v1_zones.go b/api/v1/api_v1_zones.go index 104fdf9..52a70c7 100644 --- a/api/v1/api_v1_zones.go +++ b/api/v1/api_v1_zones.go @@ -24,7 +24,8 @@ import ( // GetZoneByName returns a specific access zone which matches the name parsed in func GetZoneByName(ctx context.Context, client api.Client, - name string) (*IsiZone, error) { + name string, +) (*IsiZone, error) { var resp getIsiZonesResp // PAPI call: GET https://1.2.3.4:8080/platform/1/zones/zone err := client.Get(ctx, zonesPath, name, nil, nil, &resp) diff --git a/api/v11/api_v11_replication.go b/api/v11/api_v11_replication.go index c7a1673..5205cfa 100644 --- a/api/v11/api_v11_replication.go +++ b/api/v11/api_v11_replication.go @@ -75,9 +75,11 @@ const ( const resolveErrorToIgnore = "The policy was not conflicted, so no change was made" -var policyNameArg = []byte("policy_name") -var sortArg = []byte("sort") -var reportsPerPolicyArg = []byte("reports_per_policy") +var ( + policyNameArg = []byte("policy_name") + sortArg = []byte("sort") + reportsPerPolicyArg = []byte("reports_per_policy") +) // Policy contains the CloudIQ policy info. type Policy struct { diff --git a/api/v12/api_v12_smb_shares.go b/api/v12/api_v12_smb_shares.go index 56ba9a5..59911da 100644 --- a/api/v12/api_v12_smb_shares.go +++ b/api/v12/api_v12_smb_shares.go @@ -17,6 +17,7 @@ package v12 import ( "context" + "github.com/dell/goisilon/api" "github.com/dell/goisilon/openapi" ) @@ -39,8 +40,8 @@ type ListV12SmbSharesParams struct { func ListSmbShares( ctx context.Context, params ListV12SmbSharesParams, - client api.Client) (*openapi.V12SmbShares, error) { - + client api.Client, +) (*openapi.V12SmbShares, error) { var resp openapi.V12SmbShares if err := client.Get( ctx, @@ -49,7 +50,6 @@ func ListSmbShares( api.StructToOrderedValues(params), nil, &resp); err != nil { - return nil, err } @@ -68,8 +68,8 @@ type GetV12SmbShareParams struct { func GetSmbShare( ctx context.Context, params GetV12SmbShareParams, - client api.Client) (*openapi.V12SmbSharesExtended, error) { - + client api.Client, +) (*openapi.V12SmbSharesExtended, error) { var resp openapi.V12SmbSharesExtended if err := client.Get( ctx, @@ -78,7 +78,6 @@ func GetSmbShare( api.StructToOrderedValues(params), nil, &resp); err != nil { - return nil, err } @@ -95,8 +94,8 @@ type CreateV12SmbShareRequest struct { func CreateSmbShare( ctx context.Context, r CreateV12SmbShareRequest, - client api.Client) (*openapi.Createv12SmbShareResponse, error) { - + client api.Client, +) (*openapi.Createv12SmbShareResponse, error) { var resp openapi.Createv12SmbShareResponse if err := client.Post( ctx, @@ -105,7 +104,6 @@ func CreateSmbShare( nil, nil, r.V12SmbShare, &resp); err != nil { - return nil, err } @@ -123,7 +121,8 @@ type UpdateV12SmbShareRequest struct { func UpdateSmbShare( ctx context.Context, r UpdateV12SmbShareRequest, - client api.Client) error { + client api.Client, +) error { err := client.Put( ctx, sharesPath, @@ -144,7 +143,8 @@ type DeleteV12SmbShareRequest struct { // DeleteSmbShare Delete one export. func DeleteSmbShare( ctx context.Context, r DeleteV12SmbShareRequest, - client api.Client) error { + client api.Client, +) error { err := client.Delete( ctx, sharesPath, diff --git a/api/v14/api_v14_cluster.go b/api/v14/api_v14_cluster.go index 6d51309..6643757 100644 --- a/api/v14/api_v14_cluster.go +++ b/api/v14/api_v14_cluster.go @@ -2,14 +2,15 @@ package v14 import ( "context" + "github.com/dell/goisilon/api" ) // GetIsiClusterAcs queries ACS status of OneFS cluster func GetIsiClusterAcs( ctx context.Context, - client api.Client) (clusterAcs *IsiClusterAcs, err error) { - + client api.Client, +) (clusterAcs *IsiClusterAcs, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/14/cluster/acs // This will return ACS status. var clusterAcsResp IsiClusterAcs diff --git a/api/v2/api_v2_acls.go b/api/v2/api_v2_acls.go index 752ca79..e82507a 100644 --- a/api/v2/api_v2_acls.go +++ b/api/v2/api_v2_acls.go @@ -16,6 +16,7 @@ limitations under the License. package v2 import ( + "context" "encoding/json" "errors" "fmt" @@ -23,7 +24,6 @@ import ( "strconv" "strings" - "context" "github.com/dell/goisilon/api" ) @@ -222,8 +222,8 @@ var aclQueryString = api.OrderedValues{{[]byte("acl")}} func ACLInspect( ctx context.Context, client api.Client, - path string) (*ACL, error) { - + path string, +) (*ACL, error) { var resp ACL if err := client.Get( @@ -233,7 +233,6 @@ func ACLInspect( aclQueryString, nil, &resp); err != nil { - return nil, err } @@ -245,8 +244,8 @@ func ACLUpdate( ctx context.Context, client api.Client, path string, - acl *ACL) error { - + acl *ACL, +) error { if err := client.Put( ctx, realNamespacePath(client), @@ -255,7 +254,6 @@ func ACLUpdate( nil, acl, nil); err != nil { - return err } diff --git a/api/v2/api_v2_exports.go b/api/v2/api_v2_exports.go index 3523ad8..75cd940 100644 --- a/api/v2/api_v2_exports.go +++ b/api/v2/api_v2_exports.go @@ -74,8 +74,8 @@ func (l *ExportList) UnmarshalJSON(text []byte) error { // ExportsList GETs all exports. func ExportsList( ctx context.Context, - client api.Client) ([]*Export, error) { - + client api.Client, +) ([]*Export, error) { var resp ExportList if err := client.Get( @@ -85,7 +85,6 @@ func ExportsList( nil, nil, &resp); err != nil { - return nil, err } @@ -95,8 +94,8 @@ func ExportsList( // ExportsListWithZone GETs all exports in the specified zone. func ExportsListWithZone( ctx context.Context, - client api.Client, zone string) ([]*Export, error) { - + client api.Client, zone string, +) ([]*Export, error) { var resp ExportList if err := client.Get( @@ -108,7 +107,6 @@ func ExportsListWithZone( }, nil, &resp); err != nil { - return nil, err } @@ -119,8 +117,8 @@ func ExportsListWithZone( func ExportInspect( ctx context.Context, client api.Client, - id int) (*Export, error) { - + id int, +) (*Export, error) { var resp ExportList if err := client.Get( @@ -130,7 +128,6 @@ func ExportInspect( nil, nil, &resp); err != nil { - return nil, err } @@ -145,8 +142,8 @@ func ExportInspect( func ExportCreate( ctx context.Context, client api.Client, - export *Export) (int, error) { - + export *Export, +) (int, error) { if export.Paths != nil && len(*export.Paths) == 0 { return 0, errors.New("no path set") } @@ -161,7 +158,6 @@ func ExportCreate( nil, export, &resp); err != nil { - return 0, err } @@ -172,8 +168,8 @@ func ExportCreate( func ExportCreateWithZone( ctx context.Context, client api.Client, - export *Export, zone string) (int, error) { - + export *Export, zone string, +) (int, error) { if export.Paths != nil && len(*export.Paths) == 0 { return 0, errors.New("no path set") } @@ -193,7 +189,6 @@ func ExportCreateWithZone( nil, export, &resp); err != nil { - return 0, err } @@ -204,8 +199,8 @@ func ExportCreateWithZone( func ExportUpdate( ctx context.Context, client api.Client, - export *Export) error { - + export *Export, +) error { return client.Put( ctx, exportsPath, @@ -221,8 +216,8 @@ func ExportUpdateWithZone( ctx context.Context, client api.Client, export *Export, - zone string, ignoreUnresolvableHosts bool) error { - + zone string, ignoreUnresolvableHosts bool, +) error { args := api.OrderedValues{ {[]byte("zone"), []byte(zone)}, } @@ -248,8 +243,8 @@ func ExportUpdateWithZone( func ExportDelete( ctx context.Context, client api.Client, - id int) error { - + id int, +) error { return client.Delete( ctx, exportsPath, @@ -263,8 +258,8 @@ func ExportDelete( func ExportDeleteWithZone( ctx context.Context, client api.Client, - id int, zone string) error { - + id int, zone string, +) error { args := api.OrderedValues{ {[]byte("zone"), []byte(zone)}, } @@ -283,8 +278,8 @@ func SetExportClients( ctx context.Context, client api.Client, id int, - addrs ...string) error { - + addrs ...string, +) error { return ExportUpdate(ctx, client, &Export{ID: id, Clients: &addrs}) } @@ -293,8 +288,8 @@ func SetExportRootClients( ctx context.Context, client api.Client, id int, - addrs ...string) error { - + addrs ...string, +) error { return ExportUpdate(ctx, client, &Export{ID: id, RootClients: &addrs}) } @@ -302,8 +297,8 @@ func SetExportRootClients( func Unexport( ctx context.Context, client api.Client, - id int) error { - + id int, +) error { return ExportDelete(ctx, client, id) } @@ -311,15 +306,16 @@ func Unexport( func UnexportWithZone( ctx context.Context, client api.Client, - id int, zone string) error { - + id int, zone string, +) error { return ExportDeleteWithZone(ctx, client, id, zone) } // ExportsListWithResume GETs the next page of exports based on the resume token from the previous call. func ExportsListWithResume( ctx context.Context, - client api.Client, resume string) (*Exports, error) { + client api.Client, resume string, +) (*Exports, error) { var resp Exports if err := client.Get( @@ -331,7 +327,6 @@ func ExportsListWithResume( }, nil, &resp); err != nil { - return nil, err } @@ -341,7 +336,8 @@ func ExportsListWithResume( // ExportsListWithLimit GETs a number of exports in the default sequence and the number is the parameter limit. func ExportsListWithLimit( ctx context.Context, - client api.Client, limit string) (*Exports, error) { + client api.Client, limit string, +) (*Exports, error) { var resp Exports if err := client.Get( @@ -353,7 +349,6 @@ func ExportsListWithLimit( }, nil, &resp); err != nil { - return nil, err } @@ -363,7 +358,8 @@ func ExportsListWithLimit( // ExportsListWithParams GETs exports based on the parmapeters. func ExportsListWithParams( ctx context.Context, - client api.Client, params api.OrderedValues) (*Exports, error) { + client api.Client, params api.OrderedValues, +) (*Exports, error) { var resp Exports if err := client.Get( @@ -373,7 +369,6 @@ func ExportsListWithParams( params, nil, &resp); err != nil { - return nil, err } @@ -384,7 +379,8 @@ func ExportsListWithParams( func GetExportWithPath( ctx context.Context, client api.Client, - path string) (*Export, error) { + path string, +) (*Export, error) { var resp ExportList if err := client.Get( ctx, @@ -395,7 +391,6 @@ func GetExportWithPath( }, nil, &resp); err != nil { - return nil, err } if len(resp) == 0 { @@ -409,7 +404,8 @@ func GetExportWithPath( func GetExportWithPathAndZone( ctx context.Context, client api.Client, - path, zone string) (*Export, error) { + path, zone string, +) (*Export, error) { var resp ExportList if zone == "" { zone = "System" @@ -424,7 +420,6 @@ func GetExportWithPathAndZone( }, nil, &resp); err != nil { - return nil, err } if len(resp) == 0 { @@ -439,7 +434,8 @@ func GetExportByIDWithZone( ctx context.Context, client api.Client, id int, - zone string) (*Export, error) { + zone string, +) (*Export, error) { var resp ExportList if err := client.Get( ctx, diff --git a/api/v2/api_v2_exports_test.go b/api/v2/api_v2_exports_test.go index 8f2d04b..8bffaac 100644 --- a/api/v2/api_v2_exports_test.go +++ b/api/v2/api_v2_exports_test.go @@ -38,6 +38,7 @@ func TestExportEncodeJSON(t *testing.T) { } t.Log(s) } + func TestExportDecodeJSON(t *testing.T) { j := `{"id":3,"clients":[]}` var ex Export @@ -73,11 +74,9 @@ func TestPersonaIDTypeMarshal(t *testing.T) { t.Fatal(err) } assert.Equal(t, PersonaIDTypeUser, pidt) - } func TestPersonaIDMarshal(t *testing.T) { - pid := &PersonaID{ ID: "akutz", Type: PersonaIDTypeUser, diff --git a/api/v2/api_v2_fs.go b/api/v2/api_v2_fs.go index 5e41906..e17791a 100644 --- a/api/v2/api_v2_fs.go +++ b/api/v2/api_v2_fs.go @@ -16,6 +16,7 @@ limitations under the License. package v2 import ( + "context" "encoding/json" "fmt" "io" @@ -23,7 +24,6 @@ import ( "strings" "sync" - "context" "github.com/dell/goisilon/api" ) @@ -145,8 +145,8 @@ func ContainerChildrenGetQuery( containerPath string, limit, maxDepth int, objectType, sortDir string, - sort, detail []string) (<-chan *ContainerChild, <-chan error) { - + sort, detail []string, +) (<-chan *ContainerChild, <-chan error) { var ( ec = make(chan error) cc = make(chan *ContainerChild) @@ -212,8 +212,8 @@ func ContainerChildrenGetQuery( func ContainerChildrenGetAll( ctx context.Context, client api.Client, - containerPath string) ([]*ContainerChild, error) { - + containerPath string, +) ([]*ContainerChild, error) { var children []*ContainerChild cc, ec := ContainerChildrenGetQuery( @@ -246,8 +246,8 @@ func ContainerChildrenGetAll( func ContainerChildrenMapAll( ctx context.Context, client api.Client, - containerPath string) (map[string]*ContainerChild, error) { - + containerPath string, +) (map[string]*ContainerChild, error) { resp, err := ContainerChildrenGetAll(ctx, client, containerPath) if err != nil { return nil, err @@ -269,8 +269,8 @@ func ContainerChildrenPostQuery( client api.Client, containerPath string, limit, maxDepth int, - query *ContainerQuery) ([]*ContainerChild, error) { - + query *ContainerQuery, +) ([]*ContainerChild, error) { var resp ContainerChildList if err := client.Post( @@ -285,7 +285,6 @@ func ContainerChildrenPostQuery( nil, query, &resp); err != nil { - return nil, err } @@ -311,8 +310,8 @@ func ContainerCreateDir( client api.Client, containerPath, dirName string, fileMode FileMode, - overwrite, recursive bool) error { - + overwrite, recursive bool, +) error { var params api.OrderedValues if overwrite && recursive { params = contCreateTTQueryString @@ -352,8 +351,8 @@ func ContainerCreateFile( fileSize int, fileMode FileMode, fileHndl io.ReadCloser, - overwrite bool) error { - + overwrite bool, +) error { var params api.OrderedValues if !overwrite { params = overwriteFalseQueryString @@ -378,8 +377,8 @@ func ContainerChildDelete( ctx context.Context, client api.Client, childPath string, - recursive bool) error { - + recursive bool, +) error { var params api.OrderedValues if recursive { params = recursiveTrueQueryString diff --git a/api/v2/api_v2_types.go b/api/v2/api_v2_types.go index 80e9dc2..011b983 100644 --- a/api/v2/api_v2_types.go +++ b/api/v2/api_v2_types.go @@ -42,7 +42,6 @@ func isNilPersona(p *Persona) bool { // UnmarshalJSON unmarshals a UserMapping from JSON. func (um *UserMapping) UnmarshalJSON(data []byte) error { - if isEmptyJSON(&data) { return nil } @@ -104,7 +103,6 @@ func (p *Persona) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals a Persona from JSON. func (p *Persona) UnmarshalJSON(data []byte) error { - if isEmptyJSON(&data) { return nil } @@ -150,7 +148,6 @@ func (p *PersonaID) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals a PersonaID from JSON. func (p *PersonaID) UnmarshalJSON(data []byte) error { - if isEmptyJSON(&data) { return nil } diff --git a/api/v3/api_v3_cluster.go b/api/v3/api_v3_cluster.go index dc95b1f..61bf5c8 100644 --- a/api/v3/api_v3_cluster.go +++ b/api/v3/api_v3_cluster.go @@ -32,8 +32,8 @@ const ( func GetIsiStats( ctx context.Context, client api.Client, - keys []string) (resp *IsiStatsResp, err error) { - + keys []string, +) (resp *IsiStatsResp, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/3/statistics/current?keys=ifs.bytes.avail keysStr := strings.Join(keys, ",") @@ -54,8 +54,8 @@ func GetIsiStats( func GetIsiFloatStats( ctx context.Context, client api.Client, - keys []string) (resp *IsiFloatStatsResp, err error) { - + keys []string, +) (resp *IsiFloatStatsResp, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/3/statistics/current?keys=ifs.bytes.avail keysStr := strings.Join(keys, ",") @@ -74,7 +74,8 @@ func GetIsiFloatStats( // IsIOInProgress returns the list of clients currently performing IO on the particular array func IsIOInProgress(ctx context.Context, - client api.Client) (resp *ExportClientList, err error) { + client api.Client, +) (resp *ExportClientList, err error) { err = client.Get( ctx, string(platfromStatsPath), "summary/client", api.OrderedValues{ {[]byte("numeric"), []byte("true")}, // numeric=true returns the response faster since it does not performs reverse lookup and returns IP addresses @@ -87,8 +88,8 @@ func IsIOInProgress(ctx context.Context, // GetIsiClusterConfig queries the config information of OneFS cluster func GetIsiClusterConfig( ctx context.Context, - client api.Client) (clusterConfig *IsiClusterConfig, err error) { - + client api.Client, +) (clusterConfig *IsiClusterConfig, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/3/cluster/config // This will return configuration information of the cluster var clusterConfigResp IsiClusterConfig @@ -103,8 +104,8 @@ func GetIsiClusterConfig( // GetIsiClusterIdentity queries the config information of OneFS cluster func GetIsiClusterIdentity( ctx context.Context, - client api.Client) (clusterConfig *IsiClusterIdentity, err error) { - + client api.Client, +) (clusterConfig *IsiClusterIdentity, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/3/cluster/identity // This will return the login information. var clusterIdentityResp IsiClusterIdentity @@ -119,8 +120,8 @@ func GetIsiClusterIdentity( // GetIsiClusterNodes list the nodes on this cluster func GetIsiClusterNodes( ctx context.Context, - client api.Client) (clusterNodes *IsiClusterNodes, err error) { - + client api.Client, +) (clusterNodes *IsiClusterNodes, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/3/cluster/nodes // This will return list of the node information var clusterNodesResp IsiClusterNodes @@ -136,8 +137,8 @@ func GetIsiClusterNodes( func GetIsiClusterNode( ctx context.Context, client api.Client, - nodeID int) (clusterNodes *IsiClusterNodes, err error) { - + nodeID int, +) (clusterNodes *IsiClusterNodes, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/3/cluster/nodes/{v3ClusterNodeId} // This will return list of the node information with only one node var clusterNodesResp IsiClusterNodes diff --git a/api/v4/api_v4_nfs_exports.go b/api/v4/api_v4_nfs_exports.go index 59d7e26..fedff7f 100644 --- a/api/v4/api_v4_nfs_exports.go +++ b/api/v4/api_v4_nfs_exports.go @@ -17,6 +17,7 @@ package v4 import ( "context" + "github.com/dell/goisilon/api" "github.com/dell/goisilon/openapi" ) @@ -39,8 +40,8 @@ type ListV4NfsExportsParams struct { func ListNfsExports( ctx context.Context, params ListV4NfsExportsParams, - client api.Client) (*openapi.V2NfsExports, error) { - + client api.Client, +) (*openapi.V2NfsExports, error) { var resp openapi.V2NfsExports if err := client.Get( ctx, @@ -49,7 +50,6 @@ func ListNfsExports( api.StructToOrderedValues(params), nil, &resp); err != nil { - return nil, err } @@ -66,8 +66,8 @@ type GetV2NfsExportRequest struct { func GetNfsExport( ctx context.Context, params GetV2NfsExportRequest, - client api.Client) (*openapi.V2NfsExportsExtended, error) { - + client api.Client, +) (*openapi.V2NfsExportsExtended, error) { var resp openapi.V2NfsExportsExtended if err := client.Get( ctx, @@ -76,7 +76,6 @@ func GetNfsExport( api.StructToOrderedValues(params), nil, &resp); err != nil { - return nil, err } @@ -96,7 +95,8 @@ type CreateV4NfsExportRequest struct { // CreateNfsExport Create one export. func CreateNfsExport( ctx context.Context, r CreateV4NfsExportRequest, - client api.Client) (*openapi.Createv3EventEventResponse, error) { + client api.Client, +) (*openapi.Createv3EventEventResponse, error) { var resp openapi.Createv3EventEventResponse if err := client.Post( ctx, @@ -105,7 +105,6 @@ func CreateNfsExport( api.StructToOrderedValues(r), nil, r.V4NfsExport, &resp); err != nil { - return nil, err } @@ -126,7 +125,8 @@ type UpdateV4NfsExportRequest struct { // UpdateNfsExport Update one export. func UpdateNfsExport( ctx context.Context, r UpdateV4NfsExportRequest, - client api.Client) error { + client api.Client, +) error { err := client.Put( ctx, exportsPath, @@ -146,7 +146,8 @@ type DeleteV4NfsExportRequest struct { // DeleteNfsExport Delete one export. func DeleteNfsExport( ctx context.Context, r DeleteV4NfsExportRequest, - client api.Client) error { + client api.Client, +) error { err := client.Delete( ctx, exportsPath, diff --git a/api/v5/api_v5_quotas.go b/api/v5/api_v5_quotas.go index 323806a..ac0ec03 100644 --- a/api/v5/api_v5_quotas.go +++ b/api/v5/api_v5_quotas.go @@ -29,11 +29,13 @@ const ( ) // SmartQuotas license statuses -var unlicensed = QuotaLicenseStatus{"Unlicensed"} -var licensed = QuotaLicenseStatus{"Licensed"} -var expired = QuotaLicenseStatus{"Expired"} -var evaluation = QuotaLicenseStatus{"Evaluation"} -var evaluationExpired = QuotaLicenseStatus{"Evaluation Expired"} +var ( + unlicensed = QuotaLicenseStatus{"Unlicensed"} + licensed = QuotaLicenseStatus{"Licensed"} + expired = QuotaLicenseStatus{"Expired"} + evaluation = QuotaLicenseStatus{"Evaluation"} + evaluationExpired = QuotaLicenseStatus{"Evaluation Expired"} +) var validQuotaLicenseStatus = [5]QuotaLicenseStatus{unlicensed, licensed, expired, evaluation, evaluationExpired} @@ -49,8 +51,8 @@ type QuotaLicense struct { // GetIsiQuotaLicense retrieves the SmartQuotas license info func GetIsiQuotaLicense( ctx context.Context, - client api.Client) (lic *QuotaLicense, err error) { - + client api.Client, +) (lic *QuotaLicense, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/5/quota/license // This will return the SmartQuotas license info @@ -65,8 +67,8 @@ func GetIsiQuotaLicense( func getIsiQuotaLicenseStatus( ctx context.Context, - client api.Client) (status string, err error) { - + client api.Client, +) (status string, err error) { lic, e := GetIsiQuotaLicense(ctx, client) if e != nil { @@ -88,10 +90,9 @@ func getIsiQuotaLicenseStatus( // IsQuotaLicenseActivated checks if SmartQuotas has been activated (either licensed or in evaluation) func IsQuotaLicenseActivated(ctx context.Context, - client api.Client) (bool, error) { - + client api.Client, +) (bool, error) { status, err := getIsiQuotaLicenseStatus(ctx, client) - if err != nil { log.Error(ctx, "error encountered when retrieving SmartQuotas license info, cannot determine whether SmartQuotas is activated. error : '%v'", err) @@ -104,7 +105,6 @@ func IsQuotaLicenseActivated(ctx context.Context, } func isQuotaLicenseStatusValid(status string) bool { - isStatusValid := false for _, stat := range validQuotaLicenseStatus { @@ -122,6 +122,5 @@ type QuotaLicenseStatus struct { } func (s *QuotaLicenseStatus) toString() string { - return s.value } diff --git a/api/v7/api_v7_cluster.go b/api/v7/api_v7_cluster.go index 6495b03..9d00e49 100644 --- a/api/v7/api_v7_cluster.go +++ b/api/v7/api_v7_cluster.go @@ -2,14 +2,15 @@ package v7 import ( "context" + "github.com/dell/goisilon/api" ) // GetIsiClusterInternalNetworks queries internal networks settings func GetIsiClusterInternalNetworks( ctx context.Context, - client api.Client) (clusterInternalNetworks *IsiClusterInternalNetworks, err error) { - + client api.Client, +) (clusterInternalNetworks *IsiClusterInternalNetworks, err error) { // PAPI call: GET https://1.2.3.4:8080/platform/7/cluster/internal-networks // This will return the internal networks settings var clusterInternalNetworksResp IsiClusterInternalNetworks diff --git a/client.go b/client.go index bec77bc..e31dd4f 100644 --- a/client.go +++ b/client.go @@ -26,7 +26,6 @@ import ( // Client is an Isilon client. type Client struct { - // API is the underlying OneFS API client. API api.Client } @@ -65,8 +64,8 @@ func NewClientWithArgs( ctx context.Context, endpoint string, insecure bool, verboseLogging uint, - user, group, pass, volumesPath string, volumesPathPermissions string, ignoreUnresolvableHosts bool, authType uint8) (*Client, error) { - + user, group, pass, volumesPath string, volumesPathPermissions string, ignoreUnresolvableHosts bool, authType uint8, +) (*Client, error) { timeout, _ := time.ParseDuration(os.Getenv("GOISILON_TIMEOUT")) client, err := api.New( @@ -78,7 +77,6 @@ func NewClientWithArgs( IgnoreUnresolvableHosts: ignoreUnresolvableHosts, Timeout: timeout, }) - if err != nil { return nil, err } diff --git a/cluster.go b/cluster.go index c327be1..b4c4ffd 100644 --- a/cluster.go +++ b/cluster.go @@ -24,22 +24,26 @@ import ( ) // Stats is Isilon statistics data structure . -type Stats *apiv3.IsiStatsResp -type FloatStats *apiv3.IsiFloatStatsResp -type Clients *apiv3.ExportClientList +type ( + Stats *apiv3.IsiStatsResp + FloatStats *apiv3.IsiFloatStatsResp + Clients *apiv3.ExportClientList +) // ClusterConfig represents the configuration of cluster in k8s (namespace API). -type ClusterConfig *apiv3.IsiClusterConfig -type ClusterIdentity *apiv3.IsiClusterIdentity -type ClusterNodes *apiv3.IsiClusterNodes -type ClusterAcs *apiv14.IsiClusterAcs -type ClusterInternalNetworks *apiv7.IsiClusterInternalNetworks +type ( + ClusterConfig *apiv3.IsiClusterConfig + ClusterIdentity *apiv3.IsiClusterIdentity + ClusterNodes *apiv3.IsiClusterNodes + ClusterAcs *apiv14.IsiClusterAcs + ClusterInternalNetworks *apiv7.IsiClusterInternalNetworks +) // GetStatistics returns statistics from Isilon. Keys indicate type of statistics expected func (c *Client) GetStatistics( ctx context.Context, - keys []string) (Stats, error) { - + keys []string, +) (Stats, error) { stats, err := apiv3.GetIsiStats(ctx, c.API, keys) if err != nil { return nil, err @@ -51,8 +55,8 @@ func (c *Client) GetStatistics( // GetFloatStatistics returns float statistics from Isilon. Keys indicate type of statistics expected func (c *Client) GetFloatStatistics( ctx context.Context, - keys []string) (FloatStats, error) { - + keys []string, +) (FloatStats, error) { stats, err := apiv3.GetIsiFloatStats(ctx, c.API, keys) if err != nil { return nil, err @@ -63,8 +67,8 @@ func (c *Client) GetFloatStatistics( // IsIOinProgress checks whether a volume on a node has IO in progress func (c *Client) IsIOInProgress( - ctx context.Context) (Clients, error) { - + ctx context.Context, +) (Clients, error) { // query the volume without using the metadata parameter, use whether an error (typically, JSONError instance with "404 Not Found" status code) is returned to indicate whether the volume already exists. clientList, err := apiv3.IsIOInProgress(ctx, c.API) if err != nil { diff --git a/cluster_test.go b/cluster_test.go index 877186c..755bf97 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -49,7 +49,6 @@ func TestGetLocalSerial(t *testing.T) { panic(err) } println(localSerial) - } func TestGetClusterConfig(t *testing.T) { @@ -86,7 +85,7 @@ func TestGetClusterNodes(t *testing.T) { } func TestGetClusterNode(t *testing.T) { - var nodeID = 1 + nodeID := 1 nodes, err := client.GetClusterNode(defaultCtx, nodeID) assertNoError(t, err) assertNotNil(t, nodes) diff --git a/exports.go b/exports.go index 9fbdd37..b971f76 100644 --- a/exports.go +++ b/exports.go @@ -18,6 +18,7 @@ package goisilon import ( "context" "errors" + apiv4 "github.com/dell/goisilon/api/v4" "github.com/dell/goisilon/openapi" @@ -51,8 +52,8 @@ func (c *Client) GetExportByID(ctx context.Context, id int) (Export, error) { // GetExportByName returns the first export with a path for the provided // volume name. func (c *Client) GetExportByName( - ctx context.Context, name string) (Export, error) { - + ctx context.Context, name string, +) (Export, error) { exports, err := apiv2.ExportsList(ctx, c.API) if err != nil { return nil, err @@ -71,8 +72,8 @@ func (c *Client) GetExportByName( // GetExportByNameWithZone returns the first export with a path for the provided // volume name in the given zone. func (c *Client) GetExportByNameWithZone( - ctx context.Context, name, zone string) (Export, error) { - + ctx context.Context, name, zone string, +) (Export, error) { exports, err := apiv2.ExportsListWithZone(ctx, c.API, zone) if err != nil { return nil, err @@ -90,7 +91,6 @@ func (c *Client) GetExportByNameWithZone( // Export the volume with a given name on the cluster func (c *Client) Export(ctx context.Context, name string) (int, error) { - ok, id, err := c.IsExported(ctx, name) if err != nil { return 0, err @@ -108,7 +108,6 @@ func (c *Client) Export(ctx context.Context, name string) (int, error) { // ExportWithZone exports the volume with a given name and zone on the cluster func (c *Client) ExportWithZone(ctx context.Context, name, zone, description string) (int, error) { - // Removed the call to c.IsExportedWithZone(ctx, name, zone) to check if the path has already been exported: // 1. the POST /platform/2/protocols/nfs/exports API will return 500 error if the path is already exported, so there won't be false positive // 2. c.IsExportedWithZone(ctx, name, zone) iterates through the full list of exports, which could be expensive in a scaled environment, the potential pagination on the result set could also add to the complexity @@ -133,8 +132,8 @@ func (c *Client) ExportWithZoneAndPath(ctx context.Context, path, zone, descript // GetRootMapping returns the root mapping for an Export. func (c *Client) GetRootMapping( - ctx context.Context, name string) (UserMapping, error) { - + ctx context.Context, name string, +) (UserMapping, error) { ex, err := c.GetExportByName(ctx, name) if err != nil { return nil, err @@ -147,8 +146,8 @@ func (c *Client) GetRootMapping( // GetRootMappingByID returns the root mapping for an Export. func (c *Client) GetRootMappingByID( - ctx context.Context, id int) (UserMapping, error) { - + ctx context.Context, id int, +) (UserMapping, error) { ex, err := c.GetExportByID(ctx, id) if err != nil { return nil, err @@ -161,8 +160,8 @@ func (c *Client) GetRootMappingByID( // EnableRootMapping enables the root mapping for an Export. func (c *Client) EnableRootMapping( - ctx context.Context, name, user string) error { - + ctx context.Context, name, user string, +) error { ex, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -185,8 +184,8 @@ func (c *Client) EnableRootMapping( // EnableRootMappingByID enables the root mapping for an Export. func (c *Client) EnableRootMappingByID( - ctx context.Context, id int, user string) error { - + ctx context.Context, id int, user string, +) error { ex, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -209,8 +208,8 @@ func (c *Client) EnableRootMappingByID( // DisableRootMapping disables the root mapping for an Export. func (c *Client) DisableRootMapping( - ctx context.Context, name string) error { - + ctx context.Context, name string, +) error { ex, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -233,8 +232,8 @@ func (c *Client) DisableRootMapping( // DisableRootMappingByID disables the root mapping for an Export. func (c *Client) DisableRootMappingByID( - ctx context.Context, id int) error { - + ctx context.Context, id int, +) error { ex, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -257,8 +256,8 @@ func (c *Client) DisableRootMappingByID( // GetNonRootMapping returns the map_non_root mapping for an Export. func (c *Client) GetNonRootMapping( - ctx context.Context, name string) (UserMapping, error) { - + ctx context.Context, name string, +) (UserMapping, error) { ex, err := c.GetExportByName(ctx, name) if err != nil { return nil, err @@ -271,8 +270,8 @@ func (c *Client) GetNonRootMapping( // GetNonRootMappingByID returns the map_non_root mapping for an Export. func (c *Client) GetNonRootMappingByID( - ctx context.Context, id int) (UserMapping, error) { - + ctx context.Context, id int, +) (UserMapping, error) { ex, err := c.GetExportByID(ctx, id) if err != nil { return nil, err @@ -285,8 +284,8 @@ func (c *Client) GetNonRootMappingByID( // EnableNonRootMapping enables the map_non_root mapping for an Export. func (c *Client) EnableNonRootMapping( - ctx context.Context, name, user string) error { - + ctx context.Context, name, user string, +) error { ex, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -309,8 +308,8 @@ func (c *Client) EnableNonRootMapping( // EnableNonRootMappingByID enables the map_non_root mapping for an Export. func (c *Client) EnableNonRootMappingByID( - ctx context.Context, id int, user string) error { - + ctx context.Context, id int, user string, +) error { ex, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -333,8 +332,8 @@ func (c *Client) EnableNonRootMappingByID( // DisableNonRootMapping disables the map_non_root mapping for an Export. func (c *Client) DisableNonRootMapping( - ctx context.Context, name string) error { - + ctx context.Context, name string, +) error { ex, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -357,8 +356,8 @@ func (c *Client) DisableNonRootMapping( // DisableNonRootMappingByID disables the map_non_root mapping for an Export. func (c *Client) DisableNonRootMappingByID( - ctx context.Context, id int) error { - + ctx context.Context, id int, +) error { ex, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -381,8 +380,8 @@ func (c *Client) DisableNonRootMappingByID( // GetFailureMapping returns the map_failure mapping for an Export. func (c *Client) GetFailureMapping( - ctx context.Context, name string) (UserMapping, error) { - + ctx context.Context, name string, +) (UserMapping, error) { ex, err := c.GetExportByName(ctx, name) if err != nil { return nil, err @@ -395,8 +394,8 @@ func (c *Client) GetFailureMapping( // GetFailureMappingByID returns the map_failure mapping for an Export. func (c *Client) GetFailureMappingByID( - ctx context.Context, id int) (UserMapping, error) { - + ctx context.Context, id int, +) (UserMapping, error) { ex, err := c.GetExportByID(ctx, id) if err != nil { return nil, err @@ -409,8 +408,8 @@ func (c *Client) GetFailureMappingByID( // EnableFailureMapping enables the map_failure mapping for an Export. func (c *Client) EnableFailureMapping( - ctx context.Context, name, user string) error { - + ctx context.Context, name, user string, +) error { ex, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -433,8 +432,8 @@ func (c *Client) EnableFailureMapping( // EnableFailureMappingByID enables the map_failure mapping for an Export. func (c *Client) EnableFailureMappingByID( - ctx context.Context, id int, user string) error { - + ctx context.Context, id int, user string, +) error { ex, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -457,8 +456,8 @@ func (c *Client) EnableFailureMappingByID( // DisableFailureMapping disables the map_failure mapping for an Export. func (c *Client) DisableFailureMapping( - ctx context.Context, name string) error { - + ctx context.Context, name string, +) error { ex, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -481,8 +480,8 @@ func (c *Client) DisableFailureMapping( // DisableFailureMappingByID disables the map_failure mapping for an Export. func (c *Client) DisableFailureMappingByID( - ctx context.Context, id int) error { - + ctx context.Context, id int, +) error { ex, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -508,8 +507,8 @@ func setUserMapping( user string, enabled bool, getMapping func(Export) UserMapping, - setMapping func(Export, UserMapping)) { - + setMapping func(Export, UserMapping), +) { m := getMapping(ex) if m == nil { m = &apiv2.UserMapping{ @@ -549,8 +548,8 @@ func setUserMapping( // GetExportClients returns an Export's clients property. func (c *Client) GetExportClients( - ctx context.Context, name string) ([]string, error) { - + ctx context.Context, name string, +) ([]string, error) { ex, err := c.GetExportByName(ctx, name) if err != nil { return nil, err @@ -566,8 +565,8 @@ func (c *Client) GetExportClients( // GetExportClientsByID returns an Export's clients property. func (c *Client) GetExportClientsByID( - ctx context.Context, id int) ([]string, error) { - + ctx context.Context, id int, +) ([]string, error) { ex, err := c.GetExportByID(ctx, id) if err != nil { return nil, err @@ -583,8 +582,8 @@ func (c *Client) GetExportClientsByID( // AddExportClients adds to the Export's clients property. func (c *Client) AddExportClients( - ctx context.Context, name string, clients ...string) error { - + ctx context.Context, name string, clients ...string, +) error { ex, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -604,8 +603,8 @@ func (c *Client) AddExportClients( // AddExportClientsByExportID adds to the Export's clients property. func (c *Client) AddExportClientsByExportID( - ctx context.Context, id int, clients ...string) error { - + ctx context.Context, id int, clients ...string, +) error { ex, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -625,10 +624,9 @@ func (c *Client) AddExportClientsByExportID( // AddExportClientsByID adds to the Export's clients property. func (c *Client) AddExportClientsByID( - ctx context.Context, id int, clients []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, clients []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByID(ctx, id) - if err != nil { return err } @@ -638,10 +636,9 @@ func (c *Client) AddExportClientsByID( // AddExportReadOnlyClientsByID adds to the Export's read-only clients property. func (c *Client) AddExportReadOnlyClientsByID( - ctx context.Context, id int, clients []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, clients []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByID(ctx, id) - if err != nil { return err } @@ -651,10 +648,9 @@ func (c *Client) AddExportReadOnlyClientsByID( // AddExportReadWriteClientsByID adds to the Export's read-write clients property. func (c *Client) AddExportReadWriteClientsByID( - ctx context.Context, id int, clients []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, clients []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByID(ctx, id) - if err != nil { return err } @@ -664,8 +660,8 @@ func (c *Client) AddExportReadWriteClientsByID( // AddExportClientsByExportIDWithZone adds to the Export's clients with access zone property. func (c *Client) AddExportClientsByExportIDWithZone( - ctx context.Context, id int, zone string, ignoreUnresolvableHosts bool, clients ...string) error { - + ctx context.Context, id int, zone string, ignoreUnresolvableHosts bool, clients ...string, +) error { export, err := c.GetExportByIDWithZone(ctx, id, zone) if err != nil { return err @@ -685,8 +681,8 @@ func (c *Client) AddExportClientsByExportIDWithZone( // AddExportClientsByIDWithZone adds to the Export's clients property. func (c *Client) AddExportClientsByIDWithZone( - ctx context.Context, id int, zone string, clients []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, zone string, clients []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByIDWithZone(ctx, id, zone) if err != nil { return err @@ -696,8 +692,8 @@ func (c *Client) AddExportClientsByIDWithZone( // AddExportRootClientsByIDWithZone adds to the Export's clients property. func (c *Client) AddExportRootClientsByIDWithZone( - ctx context.Context, id int, zone string, clients []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, zone string, clients []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByIDWithZone(ctx, id, zone) if err != nil { return err @@ -707,10 +703,9 @@ func (c *Client) AddExportRootClientsByIDWithZone( // AddExportReadOnlyClientsByIDWithZone adds to the Export's read-only clients property. func (c *Client) AddExportReadOnlyClientsByIDWithZone( - ctx context.Context, id int, zone string, clients []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, zone string, clients []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByIDWithZone(ctx, id, zone) - if err != nil { return err } @@ -720,10 +715,9 @@ func (c *Client) AddExportReadOnlyClientsByIDWithZone( // AddExportReadWriteClientsByIDWithZone adds to the Export's read-write clients property. func (c *Client) AddExportReadWriteClientsByIDWithZone( - ctx context.Context, id int, zone string, clients []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, zone string, clients []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByIDWithZone(ctx, id, zone) - if err != nil { return err } @@ -732,9 +726,7 @@ func (c *Client) AddExportReadWriteClientsByIDWithZone( } func (c *Client) exportAddClients(ctx context.Context, export Export, clientsToAdd []string, ignoreUnresolvableHosts bool) error { - if export == nil { - return errors.New("Export instance is nil, abort calling exportAddClients") } updatedClients := c.getUpdatedClients(ctx, export.ID, export.Clients, clientsToAdd) @@ -743,9 +735,7 @@ func (c *Client) exportAddClients(ctx context.Context, export Export, clientsToA } func (c *Client) exportAddRootClients(ctx context.Context, export Export, clientsToAdd []string, ignoreUnresolvableHosts bool) error { - if export == nil { - return errors.New("Export instance is nil, abort calling exportAddRootClients") } updatedClients := c.getUpdatedClients(ctx, export.ID, export.RootClients, clientsToAdd) @@ -754,9 +744,7 @@ func (c *Client) exportAddRootClients(ctx context.Context, export Export, client } func (c *Client) exportAddReadOnlyClients(ctx context.Context, export Export, clientsToAdd []string, ignoreUnresolvableHosts bool) error { - if export == nil { - return errors.New("Export instance is nil, abort calling exportAddReadOnlyClients") } @@ -767,9 +755,7 @@ func (c *Client) exportAddReadOnlyClients(ctx context.Context, export Export, cl } func (c *Client) exportAddReadWriteClients(ctx context.Context, export Export, clientsToAdd []string, ignoreUnresolvableHosts bool) error { - if export == nil { - return errors.New("Export instance is nil, abort calling exportAddReadWriteClients") } updatedReadWriteClients := c.getUpdatedClients(ctx, export.ID, export.ReadWriteClients, clientsToAdd) @@ -779,7 +765,6 @@ func (c *Client) exportAddReadWriteClients(ctx context.Context, export Export, c } func (c *Client) getUpdatedClients(ctx context.Context, exportID int, clients *[]string, clientsToAdd []string) *[]string { - if clients == nil { clients = &clientsToAdd } else { @@ -793,8 +778,8 @@ func (c *Client) getUpdatedClients(ctx context.Context, exportID int, clients *[ // RemoveExportClientsByID removes the given clients from the Export's clients/read_only_clients/read_write_clients properties. func (c *Client) RemoveExportClientsByID( - ctx context.Context, id int, clientsToRemove []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, clientsToRemove []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -805,8 +790,8 @@ func (c *Client) RemoveExportClientsByID( // RemoveExportClientsByIDWithZone removes the given clients from the // Export's clients/read_only_clients/read_write_clients properties in a specified access zone. func (c *Client) RemoveExportClientsByIDWithZone( - ctx context.Context, id int, zone string, clientsToRemove []string, ignoreUnresolvableHosts bool) error { - + ctx context.Context, id int, zone string, clientsToRemove []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByIDWithZone(ctx, id, zone) if err != nil { return err @@ -816,7 +801,8 @@ func (c *Client) RemoveExportClientsByIDWithZone( // RemoveExportClientsByName removes the given clients from the Export's clients/read_only_clients/read_write_clients properties. func (c *Client) RemoveExportClientsByName( - ctx context.Context, name string, clientsToRemove []string, ignoreUnresolvableHosts bool) error { + ctx context.Context, name string, clientsToRemove []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -828,7 +814,8 @@ func (c *Client) RemoveExportClientsByName( // RemoveExportClientsWithPathAndZone removes the given clients from // the Export's clients/read_only_clients/read_write_clients/root_clients properties with export path and access zone. func (c *Client) RemoveExportClientsWithPathAndZone( - ctx context.Context, path, zone string, clientsToRemove []string, ignoreUnresolvableHosts bool) error { + ctx context.Context, path, zone string, clientsToRemove []string, ignoreUnresolvableHosts bool, +) error { export, err := c.GetExportWithPathAndZone(ctx, path, zone) if err != nil { return err @@ -838,9 +825,7 @@ func (c *Client) RemoveExportClientsWithPathAndZone( } func (c *Client) removeExportClients(ctx context.Context, export Export, clientsToRemove []string, ignoreUnresolvableHosts bool) error { - if export == nil { - return errors.New("Export instance is nil, abort calling ExportRemoveClients") } @@ -866,8 +851,8 @@ func (c *Client) removeClients(clientsToRemove []string, sourceClients []string) // SetExportClients sets the Export's clients property. func (c *Client) SetExportClients( - ctx context.Context, name string, clients ...string) error { - + ctx context.Context, name string, clients ...string, +) error { ok, id, err := c.IsExported(ctx, name) if err != nil { return err @@ -880,36 +865,36 @@ func (c *Client) SetExportClients( // SetExportClientsByID sets the Export's clients property. func (c *Client) SetExportClientsByID( - ctx context.Context, id int, clients ...string) error { - + ctx context.Context, id int, clients ...string, +) error { return apiv2.ExportUpdate(ctx, c.API, &apiv2.Export{ID: id, Clients: &clients}) } // SetExportClientsByIDWithZone sets the Export's clients with access zone property. func (c *Client) SetExportClientsByIDWithZone( - ctx context.Context, id int, zone string, ignoreUnresolvableHosts bool, clients ...string) error { - + ctx context.Context, id int, zone string, ignoreUnresolvableHosts bool, clients ...string, +) error { return apiv2.ExportUpdateWithZone(ctx, c.API, &apiv2.Export{ID: id, Clients: &clients}, zone, ignoreUnresolvableHosts) } // ClearExportClients sets the Export's clients property to nil. func (c *Client) ClearExportClients( - ctx context.Context, name string) error { - + ctx context.Context, name string, +) error { return c.SetExportClients(ctx, name, []string{}...) } // ClearExportClientsByID sets the Export's clients property to nil. func (c *Client) ClearExportClientsByID( - ctx context.Context, id int) error { - + ctx context.Context, id int, +) error { return c.SetExportClientsByID(ctx, id, []string{}...) } // GetExportRootClients returns an Export's root_clients property. func (c *Client) GetExportRootClients( - ctx context.Context, name string) ([]string, error) { - + ctx context.Context, name string, +) ([]string, error) { ex, err := c.GetExportByName(ctx, name) if err != nil { return nil, err @@ -925,8 +910,8 @@ func (c *Client) GetExportRootClients( // GetExportRootClientsByID returns an Export's clients property. func (c *Client) GetExportRootClientsByID( - ctx context.Context, id int) ([]string, error) { - + ctx context.Context, id int, +) ([]string, error) { ex, err := c.GetExportByID(ctx, id) if err != nil { return nil, err @@ -942,8 +927,8 @@ func (c *Client) GetExportRootClientsByID( // AddExportRootClients adds to the Export's root_clients property. func (c *Client) AddExportRootClients( - ctx context.Context, name string, clients ...string) error { - + ctx context.Context, name string, clients ...string, +) error { ex, err := c.GetExportByName(ctx, name) if err != nil { return err @@ -963,8 +948,8 @@ func (c *Client) AddExportRootClients( // AddExportRootClientsByID adds to the Export's root_clients property. func (c *Client) AddExportRootClientsByID( - ctx context.Context, id int, clients ...string) error { - + ctx context.Context, id int, clients ...string, +) error { ex, err := c.GetExportByID(ctx, id) if err != nil { return err @@ -984,8 +969,8 @@ func (c *Client) AddExportRootClientsByID( // SetExportRootClients sets the Export's root_clients property. func (c *Client) SetExportRootClients( - ctx context.Context, name string, clients ...string) error { - + ctx context.Context, name string, clients ...string, +) error { ok, id, err := c.IsExported(ctx, name) if err != nil { return err @@ -999,30 +984,30 @@ func (c *Client) SetExportRootClients( // SetExportRootClientsByID sets the Export's clients property. func (c *Client) SetExportRootClientsByID( - ctx context.Context, id int, clients ...string) error { - + ctx context.Context, id int, clients ...string, +) error { return apiv2.ExportUpdate( ctx, c.API, &apiv2.Export{ID: id, RootClients: &clients}) } // ClearExportRootClients sets the Export's root_clients property to nil. func (c *Client) ClearExportRootClients( - ctx context.Context, name string) error { - + ctx context.Context, name string, +) error { return c.SetExportRootClients(ctx, name, []string{}...) } // ClearExportRootClientsByID sets the Export's clients property to nil. func (c *Client) ClearExportRootClientsByID( - ctx context.Context, id int) error { - + ctx context.Context, id int, +) error { return c.SetExportRootClientsByID(ctx, id, []string{}...) } // Unexport stops exporting a given volume from the cluster. func (c *Client) Unexport( - ctx context.Context, name string) error { - + ctx context.Context, name string, +) error { ok, id, err := c.IsExported(ctx, name) if err != nil { return err @@ -1035,7 +1020,8 @@ func (c *Client) Unexport( // UnexportWithZone stops exporting a given volume in the given from the cluster. func (c *Client) UnexportWithZone( - ctx context.Context, name, zone string) error { + ctx context.Context, name, zone string, +) error { ok, id, err := c.IsExportedWithZone(ctx, name, zone) if err != nil { return err @@ -1048,23 +1034,23 @@ func (c *Client) UnexportWithZone( // UnexportByID unexports an Export by its ID. func (c *Client) UnexportByID( - ctx context.Context, id int) error { - + ctx context.Context, id int, +) error { return apiv2.Unexport(ctx, c.API, id) } // UnexportByIDWithZone unexports an Export by its ID and zone. func (c *Client) UnexportByIDWithZone( - ctx context.Context, id int, zone string) error { - + ctx context.Context, id int, zone string, +) error { return apiv2.UnexportWithZone(ctx, c.API, id, zone) } // IsExported returns a flag and export ID if the provided volume name is // already exported. func (c *Client) IsExported( - ctx context.Context, name string) (bool, int, error) { - + ctx context.Context, name string, +) (bool, int, error) { export, err := c.GetExportByName(ctx, name) if err != nil { return false, 0, err @@ -1078,8 +1064,8 @@ func (c *Client) IsExported( // IsExportedWithZone returns a flag and export ID if the provided volume name in the // specified zone isalready exported. func (c *Client) IsExportedWithZone( - ctx context.Context, name, zone string) (bool, int, error) { - + ctx context.Context, name, zone string, +) (bool, int, error) { export, err := c.GetExportByNameWithZone(ctx, name, zone) if err != nil { return false, 0, err @@ -1092,8 +1078,8 @@ func (c *Client) IsExportedWithZone( // GetExportsWithParams returns exports based on the parameters func (c *Client) GetExportsWithParams( - ctx context.Context, params api.OrderedValues) (Exports, error) { - + ctx context.Context, params api.OrderedValues, +) (Exports, error) { exports, err := apiv2.ExportsListWithParams(ctx, c.API, params) if err != nil { return nil, err @@ -1104,8 +1090,8 @@ func (c *Client) GetExportsWithParams( // GetExportsWithResume returns the next page of exports // based on the resume token from the previous call. func (c *Client) GetExportsWithResume( - ctx context.Context, resume string) (Exports, error) { - + ctx context.Context, resume string, +) (Exports, error) { exports, err := apiv2.ExportsListWithResume(ctx, c.API, resume) if err != nil { return nil, err @@ -1116,8 +1102,8 @@ func (c *Client) GetExportsWithResume( // GetExportsWithLimit returns a number of exports in the default sequence // and the number is the parameter limit. func (c *Client) GetExportsWithLimit( - ctx context.Context, limit string) (Exports, error) { - + ctx context.Context, limit string, +) (Exports, error) { exports, err := apiv2.ExportsListWithLimit(ctx, c.API, limit) if err != nil { return nil, err @@ -1142,13 +1128,15 @@ func (c *Client) ExportPathWithZone(ctx context.Context, path, zone, description // GetExportWithPath gets the export with target path func (c *Client) GetExportWithPath( - ctx context.Context, path string) (Export, error) { + ctx context.Context, path string, +) (Export, error) { return apiv2.GetExportWithPath(ctx, c.API, path) } // GetExportWithPathAndZone gets the export with target path and access zone func (c *Client) GetExportWithPathAndZone( - ctx context.Context, path, zone string) (Export, error) { + ctx context.Context, path, zone string, +) (Export, error) { return apiv2.GetExportWithPathAndZone(ctx, c.API, path, zone) } diff --git a/exports_test.go b/exports_test.go index 244d8bc..f782bf6 100644 --- a/exports_test.go +++ b/exports_test.go @@ -18,12 +18,13 @@ package goisilon import ( "context" "fmt" - apiv4 "github.com/dell/goisilon/api/v4" - "github.com/dell/goisilon/openapi" "sort" "strconv" "testing" + apiv4 "github.com/dell/goisilon/api/v4" + "github.com/dell/goisilon/openapi" + log "github.com/akutz/gournal" "github.com/dell/goisilon/api" "github.com/stretchr/testify/assert" @@ -231,8 +232,8 @@ func testUserMapping( volumeName string, getMap func(ctx context.Context, id int) (UserMapping, error), enaMap func(ctx context.Context, id int, user string) error, - disMap func(ctx context.Context, id int) error) { - + disMap func(ctx context.Context, id int) error, +) { var ( err error exportID int @@ -318,7 +319,6 @@ func TestExportClientsAdd(t *testing.T) { } func TestAddExportClientsByID(t *testing.T) { - // Add the test exports volumeName1 := "test_get_exports1" vol, err := client.CreateVolume(defaultCtx, volumeName1) @@ -350,9 +350,9 @@ func TestAddExportClientsByID(t *testing.T) { } func testAddExportClientsByID(t *testing.T, exportID int, export Export, addExportClientsByID func( - ctx context.Context, id int, clients []string, ignoreUnresolvableHosts bool) error) { - - var clientsToAdd = []string{"192.168.1.110", "192.168.1.110", "192.168.1.111", "192.168.1.112", "192.168.1.113"} + ctx context.Context, id int, clients []string, ignoreUnresolvableHosts bool) error, +) { + clientsToAdd := []string{"192.168.1.110", "192.168.1.110", "192.168.1.111", "192.168.1.112", "192.168.1.113"} log.Debug(defaultCtx, "add '%v' to '%v' for export '%d'", clientsToAdd, *export.Clients, exportID) @@ -361,12 +361,10 @@ func testAddExportClientsByID(t *testing.T, exportID int, export Export, addExpo } func TestRemoveExportClientsByID(t *testing.T) { - testRemoveExportClients(t, client.RemoveExportClientsByID, nil) } func TestRemoveExportClientsByName(t *testing.T) { - testRemoveExportClients(t, nil, client.RemoveExportClientsByName) volumeName1 := "test_get_exports1" // make sure we clean up when we're done @@ -376,8 +374,8 @@ func TestRemoveExportClientsByName(t *testing.T) { func testRemoveExportClients(t *testing.T, removeExportClientsByIDFunc func(ctx context.Context, id int, clientsToRemove []string, ignoreUnresolvableHosts bool) error, - removeExportClientsByNameFunc func(ctx context.Context, name string, clientsToRemove []string, ignoreUnresolvableHosts bool) error) { - + removeExportClientsByNameFunc func(ctx context.Context, name string, clientsToRemove []string, ignoreUnresolvableHosts bool) error, +) { volumeName1 := "test_get_exports1" exportID := exportForClient @@ -386,7 +384,7 @@ func testRemoveExportClients(t *testing.T, fmt.Printf("export '%d' has \n%-20v: '%v'\n%-20v: '%v'\n%-20v: '%v'\n", exportID, "clients", *export.Clients, "read_only_cilents", *export.ReadOnlyClients, "read_write_cilents", *export.ReadWriteClients) - var clientsToRemove = []string{"192.168.1.110", "192.168.1.110", "192.168.1.111", "192.168.1.116", "k8s-node-1.lab.acme.com"} + clientsToRemove := []string{"192.168.1.110", "192.168.1.110", "192.168.1.111", "192.168.1.116", "k8s-node-1.lab.acme.com"} log.Debug(defaultCtx, "remove '%v' from '%v' for export '%d'", clientsToRemove, *export.Clients, exportID) @@ -462,8 +460,8 @@ func testExportClientsGet( t *testing.T, volumeName string, getClients func(ctx context.Context, id int) ([]string, error), - setClients func(ctx context.Context, id int, clients ...string) error) { - + setClients func(ctx context.Context, id int, clients ...string) error, +) { var ( err error exportID int @@ -505,8 +503,8 @@ func testExportClientsSet( t *testing.T, volumeName string, getClients func(ctx context.Context, e Export) []string, - setClients func(ctx context.Context, id int, clients ...string) error) { - + setClients func(ctx context.Context, id int, clients ...string) error, +) { var ( err error export Export @@ -562,8 +560,8 @@ func testExportClientsAdd( volumeName string, getClients func(ctx context.Context, e Export) []string, setClients func(ctx context.Context, id int, clients ...string) error, - addClients func(ctx context.Context, id int, clients ...string) error) { - + addClients func(ctx context.Context, id int, clients ...string) error, +) { var ( err error export Export @@ -637,8 +635,8 @@ func testExportClientsClear( volumeName string, getClients func(ctx context.Context, e Export) []string, setClients func(ctx context.Context, id int, clients ...string) error, - nilClients func(ctx context.Context, id int) error) { - + nilClients func(ctx context.Context, id int) error, +) { var ( err error export Export diff --git a/openapi/model_error.go b/openapi/model_error.go index 6fa16a2..2e55590 100644 --- a/openapi/model_error.go +++ b/openapi/model_error.go @@ -18,6 +18,6 @@ package openapi // Error struct for Error type Error struct { - Code int32 `json:"code"` + Code int32 `json:"code"` Message string `json:"message"` } diff --git a/openapi/model_v12_smb_share_extended.go b/openapi/model_v12_smb_share_extended.go index d90eac4..a815af3 100644 --- a/openapi/model_v12_smb_share_extended.go +++ b/openapi/model_v12_smb_share_extended.go @@ -101,4 +101,3 @@ type V12SmbShareExtended struct { // Numeric ID of the access zone which contains this SMB share Zid int32 `json:"zid"` } - diff --git a/openapi/model_v12_smb_shares.go b/openapi/model_v12_smb_shares.go index f33749c..e250af6 100644 --- a/openapi/model_v12_smb_shares.go +++ b/openapi/model_v12_smb_shares.go @@ -21,7 +21,7 @@ type V12SmbShares struct { // An identifier for a set of shares. Digest *string `json:"digest,omitempty"` // Provide this token as the 'resume' query argument to continue listing results. - Resume *string `json:"resume,omitempty"` + Resume *string `json:"resume,omitempty"` Shares []V12SmbShareExtended `json:"shares"` // Total number of items available. Total *int32 `json:"total,omitempty"` diff --git a/openapi/model_v1_smb_share_permission.go b/openapi/model_v1_smb_share_permission.go index 9c11511..fab49c6 100644 --- a/openapi/model_v1_smb_share_permission.go +++ b/openapi/model_v1_smb_share_permission.go @@ -21,6 +21,6 @@ type V1SmbSharePermission struct { // Specifies the file system rights that are allowed or denied. Permission string `json:"permission"` // Determines whether the permission is allowed or denied. - PermissionType string `json:"permission_type"` - Trustee V1AuthAccessAccessItemFileGroup `json:"trustee"` + PermissionType string `json:"permission_type"` + Trustee V1AuthAccessAccessItemFileGroup `json:"trustee"` } diff --git a/openapi/model_v2_nfs_export.go b/openapi/model_v2_nfs_export.go index 562f6c5..92f1731 100644 --- a/openapi/model_v2_nfs_export.go +++ b/openapi/model_v2_nfs_export.go @@ -41,17 +41,17 @@ type V2NfsExport struct { // Specifies the default character set encoding of the clients connecting to the export, unless otherwise specified. Encoding *string `json:"encoding,omitempty"` // Specifies the reported maximum number of links to a file. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. - LinkMax *int32 `json:"link_max,omitempty"` - MapAll *V2NfsExportMapAll `json:"map_all,omitempty"` + LinkMax *int32 `json:"link_max,omitempty"` + MapAll *V2NfsExportMapAll `json:"map_all,omitempty"` MapFailure *V2NfsExportMapAll `json:"map_failure,omitempty"` // True if user mappings query the OneFS user database. When set to false, user mappings only query local authentication. MapFull *bool `json:"map_full,omitempty"` // True if incoming user IDs (UIDs) are mapped to users in the OneFS user database. When set to false, incoming UIDs are applied directly to file operations. - MapLookupUid *bool `json:"map_lookup_uid,omitempty"` - MapNonRoot *V2NfsExportMapAll `json:"map_non_root,omitempty"` + MapLookupUid *bool `json:"map_lookup_uid,omitempty"` + MapNonRoot *V2NfsExportMapAll `json:"map_non_root,omitempty"` // Determines whether searches for users specified in 'map_all', 'map_root' or 'map_nonroot' are retried if the search fails. - MapRetry *bool `json:"map_retry,omitempty"` - MapRoot *V2NfsExportMapAll `json:"map_root,omitempty"` + MapRetry *bool `json:"map_retry,omitempty"` + MapRoot *V2NfsExportMapAll `json:"map_root,omitempty"` // Specifies the maximum file size for any file accessed from the export. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. MaxFileSize *int64 `json:"max_file_size,omitempty"` // Specifies the reported maximum length of a file name. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. diff --git a/openapi/model_v2_nfs_export_extended.go b/openapi/model_v2_nfs_export_extended.go index c04643b..f1c3c84 100644 --- a/openapi/model_v2_nfs_export_extended.go +++ b/openapi/model_v2_nfs_export_extended.go @@ -45,17 +45,17 @@ type V2NfsExportExtended struct { // Specifies the system-assigned ID for the export. This ID is returned when an export is created through the POST method. Id *int32 `json:"id,omitempty"` // Specifies the reported maximum number of links to a file. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. - LinkMax *int32 `json:"link_max,omitempty"` - MapAll *V2NfsExportMapAll `json:"map_all,omitempty"` + LinkMax *int32 `json:"link_max,omitempty"` + MapAll *V2NfsExportMapAll `json:"map_all,omitempty"` MapFailure *V2NfsExportMapAll `json:"map_failure,omitempty"` // True if user mappings query the OneFS user database. When set to false, user mappings only query local authentication. MapFull *bool `json:"map_full,omitempty"` // True if incoming user IDs (UIDs) are mapped to users in the OneFS user database. When set to false, incoming UIDs are applied directly to file operations. - MapLookupUid *bool `json:"map_lookup_uid,omitempty"` - MapNonRoot *V2NfsExportMapAll `json:"map_non_root,omitempty"` + MapLookupUid *bool `json:"map_lookup_uid,omitempty"` + MapNonRoot *V2NfsExportMapAll `json:"map_non_root,omitempty"` // Determines whether searches for users specified in 'map_all', 'map_root' or 'map_nonroot' are retried if the search fails. - MapRetry *bool `json:"map_retry,omitempty"` - MapRoot *V2NfsExportMapAll `json:"map_root,omitempty"` + MapRetry *bool `json:"map_retry,omitempty"` + MapRoot *V2NfsExportMapAll `json:"map_root,omitempty"` // Specifies the maximum file size for any file accessed from the export. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. MaxFileSize *int64 `json:"max_file_size,omitempty"` // Specifies the reported maximum length of a file name. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. diff --git a/openapi/model_v2_nfs_export_extended_extended.go b/openapi/model_v2_nfs_export_extended_extended.go index b2cd3fe..36238ae 100644 --- a/openapi/model_v2_nfs_export_extended_extended.go +++ b/openapi/model_v2_nfs_export_extended_extended.go @@ -41,17 +41,17 @@ type V2NfsExportExtendedExtended struct { // Specifies the default character set encoding of the clients connecting to the export, unless otherwise specified. Encoding *string `json:"encoding,omitempty"` // Specifies the reported maximum number of links to a file. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. - LinkMax *int32 `json:"link_max,omitempty"` - MapAll *V2NfsExportMapAll `json:"map_all,omitempty"` + LinkMax *int32 `json:"link_max,omitempty"` + MapAll *V2NfsExportMapAll `json:"map_all,omitempty"` MapFailure *V2NfsExportMapAll `json:"map_failure,omitempty"` // True if user mappings query the OneFS user database. When set to false, user mappings only query local authentication. MapFull *bool `json:"map_full,omitempty"` // True if incoming user IDs (UIDs) are mapped to users in the OneFS user database. When set to false, incoming UIDs are applied directly to file operations. - MapLookupUid *bool `json:"map_lookup_uid,omitempty"` - MapNonRoot *V2NfsExportMapAll `json:"map_non_root,omitempty"` + MapLookupUid *bool `json:"map_lookup_uid,omitempty"` + MapNonRoot *V2NfsExportMapAll `json:"map_non_root,omitempty"` // Determines whether searches for users specified in 'map_all', 'map_root' or 'map_nonroot' are retried if the search fails. - MapRetry *bool `json:"map_retry,omitempty"` - MapRoot *V2NfsExportMapAll `json:"map_root,omitempty"` + MapRetry *bool `json:"map_retry,omitempty"` + MapRoot *V2NfsExportMapAll `json:"map_root,omitempty"` // Specifies the maximum file size for any file accessed from the export. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. MaxFileSize *int64 `json:"max_file_size,omitempty"` // Specifies the reported maximum length of a file name. This parameter does not affect server behavior, but is included to accommodate legacy client requirements. diff --git a/openapi/model_v2_nfs_export_map_all.go b/openapi/model_v2_nfs_export_map_all.go index 1fc5028..a830211 100644 --- a/openapi/model_v2_nfs_export_map_all.go +++ b/openapi/model_v2_nfs_export_map_all.go @@ -19,9 +19,9 @@ package openapi // V2NfsExportMapAll Specifies the users and groups to which non-root and root clients are mapped. type V2NfsExportMapAll struct { // True if the user mapping is applied. - Enabled *bool `json:"enabled,omitempty"` + Enabled *bool `json:"enabled,omitempty"` PrimaryGroup *V1AuthAccessAccessItemFileGroup `json:"primary_group,omitempty"` // Specifies persona properties for the secondary user group. A persona consists of either a type and name, or an ID. SecondaryGroups []V2NfsExportMapAllSecondaryGroupsInner `json:"secondary_groups,omitempty"` - User *V1AuthAccessAccessItemFileGroup `json:"user,omitempty"` + User *V1AuthAccessAccessItemFileGroup `json:"user,omitempty"` } diff --git a/openapi/model_v2_nfs_exports.go b/openapi/model_v2_nfs_exports.go index 69ed62f..81bb6d9 100644 --- a/openapi/model_v2_nfs_exports.go +++ b/openapi/model_v2_nfs_exports.go @@ -19,7 +19,7 @@ package openapi // V2NfsExports struct for V2NfsExports type V2NfsExports struct { // An identifier for a set of exports. - Digest *string `json:"digest,omitempty"` + Digest *string `json:"digest,omitempty"` Exports []V2NfsExportExtended `json:"exports,omitempty"` // Provide this token as the 'resume' query argument to continue listing results. Resume *string `json:"resume,omitempty"` diff --git a/quota.go b/quota.go index d91e76e..9f6635d 100644 --- a/quota.go +++ b/quota.go @@ -86,7 +86,8 @@ func (c *Client) GetQuotaWithPath(ctx context.Context, path string) (Quota, erro // CreateQuota creates a new hard directory quota with the specified size // and container option func (c *Client) CreateQuota( - ctx context.Context, name string, container bool, size, softLimit, advisoryLimit, softGracePrd int64) (string, error) { + ctx context.Context, name string, container bool, size, softLimit, advisoryLimit, softGracePrd int64, +) (string, error) { return api.CreateIsiQuota( ctx, c.API, c.API.VolumePath(name), container, size, softLimit, advisoryLimit, softGracePrd) } @@ -94,31 +95,32 @@ func (c *Client) CreateQuota( // CreateQuotaWithPath creates a new hard directory quota with the specified size // and container option func (c *Client) CreateQuotaWithPath( - ctx context.Context, path string, container bool, size, softLimit, advisoryLimit, softGracePrd int64) (string, error) { + ctx context.Context, path string, container bool, size, softLimit, advisoryLimit, softGracePrd int64, +) (string, error) { return api.CreateIsiQuota( ctx, c.API, path, container, size, softLimit, advisoryLimit, softGracePrd) } // SetQuotaSize sets the max size (hard threshold) of a quota for a volume func (c *Client) SetQuotaSize( - ctx context.Context, name string, size, softLimit, advisoryLimit, softGracePrd int64) (string, error) { - + ctx context.Context, name string, size, softLimit, advisoryLimit, softGracePrd int64, +) (string, error) { return api.SetIsiQuotaHardThreshold( ctx, c.API, c.API.VolumePath(name), size, softLimit, advisoryLimit, softGracePrd) } // UpdateQuotaSize modifies the max size (hard threshold) of a quota for a volume func (c *Client) UpdateQuotaSize( - ctx context.Context, name string, size, softLimit, advisoryLimit, softGracePrd int64) error { - + ctx context.Context, name string, size, softLimit, advisoryLimit, softGracePrd int64, +) error { return api.UpdateIsiQuotaHardThreshold( ctx, c.API, c.API.VolumePath(name), size, softLimit, advisoryLimit, softGracePrd) } // UpdateQuotaSizeByID modifies the max size (hard threshold) of a quota for a volume func (c *Client) UpdateQuotaSizeByID( - ctx context.Context, ID string, size, softLimit, advisoryLimit, softGracePrd int64) error { - + ctx context.Context, ID string, size, softLimit, advisoryLimit, softGracePrd int64, +) error { return api.UpdateIsiQuotaHardThresholdByID( ctx, c.API, ID, size, softLimit, advisoryLimit, softGracePrd) } diff --git a/quota_test.go b/quota_test.go index a2e5735..18818d2 100644 --- a/quota_test.go +++ b/quota_test.go @@ -24,7 +24,6 @@ import ( // Test both GetQuota() and SetQuota() func TestQuotaGetSet(t *testing.T) { - volumeName := "test_quota_get_set" quotaSize := int64(1234567) var softLimit, advisoryLimit, softGracePrd int64 @@ -64,7 +63,6 @@ func TestQuotaGetSet(t *testing.T) { if quota.Thresholds.Hard != quotaSize { panic(fmt.Sprintf("Unexpected new quota. Expected: %d Actual: %d", quotaSize, quota.Thresholds.Hard)) } - } // Test GetAllQuotas() @@ -79,7 +77,6 @@ func TestAllQuotasGet(t *testing.T) { // Test UpdateQuota() func TestQuotaUpdate(t *testing.T) { - volumeName := "test_quota_update" quotaSize := int64(1234567) updatedQuotaSize := int64(22345000) @@ -127,12 +124,10 @@ func TestQuotaUpdate(t *testing.T) { if quota.Thresholds.Hard != updatedQuotaSize { panic(fmt.Sprintf("Updated quota not set properly. Expected: %d Actual: %d", updatedQuotaSize, quota.Thresholds.Hard)) } - } // Test ClearQuota() func TestQuotaClear(t *testing.T) { - volumeName := "test_quota_clear" quotaSize := int64(1234567) var softLimit, advisoryLimit, softGracePrd int64 @@ -180,7 +175,6 @@ func TestQuotaClear(t *testing.T) { // Test ClearQuotaByID() func TestQuotaClearByID(t *testing.T) { - volumeName := "test_quota_clear_by_id" quotaSize := int64(1234567) var softLimit, advisoryLimit, softGracePrd int64 @@ -220,7 +214,6 @@ func TestQuotaClearByID(t *testing.T) { // Test IsQuotaLicenseActivated() func TestIsQuotaLicenseActivated(t *testing.T) { - t.Log("start TestIsQuotaLicenseActivated") isActivated, _ := client.IsQuotaLicenseActivated(defaultCtx) @@ -230,7 +223,6 @@ func TestIsQuotaLicenseActivated(t *testing.T) { // Test TestQuotaUpdateByID() func TestQuotaUpdateByID(t *testing.T) { - volumeName := "test_quota_update" quotaSize := int64(1234567) updatedQuotaSize := int64(22345000) @@ -278,5 +270,4 @@ func TestQuotaUpdateByID(t *testing.T) { if quota.Thresholds.Hard != updatedQuotaSize { panic(fmt.Sprintf("Updated quota not set properly. Expected: %d Actual: %d", updatedQuotaSize, quota.Thresholds.Hard)) } - } diff --git a/replication.go b/replication.go index 73b6e57..9990320 100644 --- a/replication.go +++ b/replication.go @@ -27,13 +27,17 @@ import ( apiv11 "github.com/dell/goisilon/api/v11" ) -const defaultPoll = 5 * time.Second -const defaultTimeout = 10 * time.Minute // set high timeout, we expect to be canceled via context before +const ( + defaultPoll = 5 * time.Second + defaultTimeout = 10 * time.Minute // set high timeout, we expect to be canceled via context before +) -const retryInterval = 15 * time.Second -const maxRetries = 20 // with 15 sec, it is 4 retries per min. For 5 minutes, it is 20 retries -const retryablePolicyError = "is in an error state. Please resolve it and retry" -const retryableReportError = "A new quota domain that has not finished QuotaScan has been found" +const ( + retryInterval = 15 * time.Second + maxRetries = 20 // with 15 sec, it is 4 retries per min. For 5 minutes, it is 20 retries + retryablePolicyError = "is in an error state. Please resolve it and retry" + retryableReportError = "A new quota domain that has not finished QuotaScan has been found" +) const ( RESYNC_PREP apiv11.JOB_ACTION = "resync_prep" @@ -331,7 +335,6 @@ func (c *Client) WaitForTargetPolicyCondition(ctx context.Context, policyName st } func (c *Client) SyncPolicy(ctx context.Context, policyName string) error { - // get all running // if running - wait for it and succeed // if no running - start new - wait for it and succeed @@ -412,7 +415,6 @@ func (c *Client) SyncPolicy(ctx context.Context, policyName string) error { } return nil } - } func (c *Client) GetJobsByPolicyName(ctx context.Context, policyName string) ([]apiv11.Job, error) { diff --git a/role_test.go b/role_test.go index b8aac5d..6c2eb1e 100644 --- a/role_test.go +++ b/role_test.go @@ -44,7 +44,6 @@ func TestRoleGet(t *testing.T) { // Test GetRoleByID(), AddRoleMember(), RemoveRoleMember() and IsRoleMemberOf() func TestRoleMemberAdd(t *testing.T) { - roleId := "SystemAdmin" userName := "test_user_roleMember" @@ -95,7 +94,7 @@ func TestRoleMemberAdd(t *testing.T) { } assertFalse(t, isRoleMember) - //add/remove role member by uid + // add/remove role member by uid uid, err := strconv.ParseInt(user.Uid.Id[4:], 10, 32) uid32 := int32(uid) if err != nil { diff --git a/shares.go b/shares.go index 31dd31c..7e396a0 100644 --- a/shares.go +++ b/shares.go @@ -1,22 +1,23 @@ /* - Copyright (c) 2023 Dell Inc, or its subsidiaries. +Copyright (c) 2023 Dell Inc, or its subsidiaries. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package goisilon import ( "context" + apiv12 "github.com/dell/goisilon/api/v12" "github.com/dell/goisilon/openapi" ) diff --git a/shares_test.go b/shares_test.go index 75f57a7..e2776b0 100644 --- a/shares_test.go +++ b/shares_test.go @@ -1,25 +1,26 @@ /* - Copyright (c) 2023 Dell Inc, or its subsidiaries. +Copyright (c) 2023 Dell Inc, or its subsidiaries. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ package goisilon import ( + "testing" + v12 "github.com/dell/goisilon/api/v12" "github.com/dell/goisilon/openapi" "github.com/stretchr/testify/assert" - "testing" ) func TestClient_SmbShareWithStructParams(t *testing.T) { diff --git a/snapshots.go b/snapshots.go index 7302fbc..6dca598 100644 --- a/snapshots.go +++ b/snapshots.go @@ -27,8 +27,10 @@ import ( api "github.com/dell/goisilon/api/v1" ) -const namespacePath = "namespace" -const snapShot = ".snapshot" +const ( + namespacePath = "namespace" + snapShot = ".snapshot" +) // SnapshotList represents a list of Isilon snapshots. type SnapshotList []*api.IsiSnapshot @@ -48,8 +50,8 @@ func (c *Client) GetSnapshots(ctx context.Context) (SnapshotList, error) { // GetSnapshotsByPath returns a list of snapshots covering the supplied path. func (c *Client) GetSnapshotsByPath( - ctx context.Context, path string) (SnapshotList, error) { - + ctx context.Context, path string, +) (SnapshotList, error) { snapshots, err := api.GetIsiSnapshots(ctx, c.API) if err != nil { return nil, err @@ -66,8 +68,8 @@ func (c *Client) GetSnapshotsByPath( // GetSnapshot returns a snapshot matching id, or if that is not found, matching name func (c *Client) GetSnapshot( - ctx context.Context, id int64, name string) (Snapshot, error) { - + ctx context.Context, id int64, name string, +) (Snapshot, error) { // if we have an id, use it to find the snapshot snapshot, err := api.GetIsiSnapshot(ctx, c.API, id) if err == nil { @@ -95,20 +97,22 @@ func (c *Client) GetSnapshot( // CreateSnapshot creates a snapshot called name of the given path. func (c *Client) CreateSnapshot( - ctx context.Context, volName, snapshotName string) (Snapshot, error) { + ctx context.Context, volName, snapshotName string, +) (Snapshot, error) { return api.CreateIsiSnapshot(ctx, c.API, c.API.VolumePath(volName), snapshotName) } // CreateSnapshotWithPath creates a snapshot by snapshot name and the path of volume. func (c *Client) CreateSnapshotWithPath( - ctx context.Context, path, snapshotName string) (Snapshot, error) { + ctx context.Context, path, snapshotName string, +) (Snapshot, error) { return api.CreateIsiSnapshot(ctx, c.API, path, snapshotName) } // RemoveSnapshot removes the snapshot by id, or failing that, the snapshot matching name. func (c *Client) RemoveSnapshot( - ctx context.Context, id int64, name string) error { - + ctx context.Context, id int64, name string, +) error { snapshot, err := c.GetSnapshot(ctx, id, name) if err != nil { return err @@ -120,8 +124,8 @@ func (c *Client) RemoveSnapshot( // CopySnapshot copies all files/directories in a snapshot to a new directory. func (c *Client) CopySnapshot( ctx context.Context, - sourceID int64, sourceName, accessZone, destinationName string) (Volume, error) { - + sourceID int64, sourceName, accessZone, destinationName string, +) (Volume, error) { snapshot, err := c.GetSnapshot(ctx, sourceID, sourceName) if err != nil { return nil, err @@ -150,8 +154,8 @@ func (c *Client) CopySnapshotWithIsiPath( ctx context.Context, isiPath, snapshotSourceVolumeIsiPath string, sourceID int64, - sourceName, destinationName string, accessZone string) (Volume, error) { - + sourceName, destinationName string, accessZone string, +) (Volume, error) { snapshot, err := c.GetIsiSnapshotByIdentity(ctx, strconv.FormatInt(sourceID, 10)) if err != nil { return nil, err @@ -164,12 +168,12 @@ func (c *Client) CopySnapshotWithIsiPath( ctx, c.API, isiPath, snapshotSourceVolumeIsiPath, snapshot.Name, path.Base(snapshot.Path), destinationName, accessZone) - //The response will be null on success of the snapshot creation otherwise it will return the response with a success state equal to false and with details + // The response will be null on success of the snapshot creation otherwise it will return the response with a success state equal to false and with details if resp != nil && !resp.Success && resp.Errors != nil { var copySnapError bytes.Buffer for _, errMes := range resp.Errors { - //Extracting the error message from the JSON array + // Extracting the error message from the JSON array copySnapError.WriteString("Error Source = " + errMes.Source + "," + "Message = " + errMes.Message + "," + "," + "Source = " + errMes.Source + "," + "Target = " + errMes.Target + " \n") } err = errors.New(copySnapError.String()) @@ -186,24 +190,24 @@ func (c *Client) CopySnapshotWithIsiPath( // GetIsiSnapshotByIdentity query a snapshot by ID or name // param identity string: name or id func (c *Client) GetIsiSnapshotByIdentity( - ctx context.Context, identity string) (Snapshot, error) { - + ctx context.Context, identity string, +) (Snapshot, error) { return api.GetIsiSnapshotByIdentity(ctx, c.API, identity) } // IsSnapshotExistent checks if a snapshot already exists // param identity string: name or id func (c *Client) IsSnapshotExistent( - ctx context.Context, identity string) bool { - + ctx context.Context, identity string, +) bool { snapshot, _ := api.GetIsiSnapshotByIdentity(ctx, c.API, identity) return snapshot != nil } // GetSnapshotFolderSize returns the total size of a snapshot folder func (c *Client) GetSnapshotFolderSize(ctx context.Context, - isiPath, name string, accessZone string) (int64, error) { - + isiPath, name string, accessZone string, +) (int64, error) { snapshot, err := c.GetIsiSnapshotByIdentity(ctx, name) if err != nil { return 0, err @@ -227,8 +231,8 @@ func (c *Client) GetSnapshotFolderSize(ctx context.Context, // GetSnapshotIsiPath returns the snapshot directory path func (c *Client) GetSnapshotIsiPath( ctx context.Context, - isiPath, snapshotId string, accessZone string) (string, error) { - + isiPath, snapshotId string, accessZone string, +) (string, error) { snapshot, err := c.GetIsiSnapshotByIdentity(ctx, snapshotId) if err != nil { return "", err @@ -237,7 +241,7 @@ func (c *Client) GetSnapshotIsiPath( return "", fmt.Errorf("Snapshot doesn't exist for snapshot id: (%s) and access Zone (%s)", snapshotId, accessZone) } - //get zone base path + // get zone base path zone, err := api.GetZoneByName(ctx, c.API, accessZone) if err != nil { return "", err @@ -245,7 +249,7 @@ func (c *Client) GetSnapshotIsiPath( snapshotPath := api.GetRealVolumeSnapshotPathWithIsiPath(isiPath, zone.Path, snapshot.Name, accessZone) snapshotPath = path.Join(snapshotPath, path.Base(snapshot.Path)) - //If isi path is different then zone base path i.e. isi path contains multiple directories + // If isi path is different then zone base path i.e. isi path contains multiple directories if strings.Compare(zone.Path, isiPath) != 0 { parts := strings.SplitN(snapshotPath, namespacePath, 2) if len(parts) < 2 { diff --git a/snapshots_test.go b/snapshots_test.go index 5aec074..16685b9 100644 --- a/snapshots_test.go +++ b/snapshots_test.go @@ -91,11 +91,9 @@ func TestSnapshotsGet(t *testing.T) { if _, found := snapshotMap[testSnapshot2.Id]; found == false { panic("testSnapshot2 was not in the snapshot list\n") } - } func TestSnapshotsGetByPath(t *testing.T) { - snapshotPath1 := "test_snapshots_get_by_path_volume_1" snapshotPath2 := "test_snapshots_get_by_path_volume_2" snapshotName1 := "test_snapshots_get_by_path_snapshot_1" @@ -180,7 +178,6 @@ func TestSnapshotsGetByPath(t *testing.T) { } func TestSnapshotCreate(t *testing.T) { - snapshotPath := "test_snapshot_create_volume" snapshotName := "test_snapshot_create_snapshot" @@ -224,7 +221,6 @@ func TestSnapshotCreate(t *testing.T) { } func TestSnapshotRemove(t *testing.T) { - snapshotPath := "test_snapshot_remove_volume" snapshotName := "test_snapshot_remove_snapshot" @@ -262,7 +258,6 @@ func TestSnapshotRemove(t *testing.T) { } func TestSnapshotCopy(t *testing.T) { - accessZone := "System" sourceSnapshotPath := "test_snapshot_copy_src_volume" sourceSnapshotName := "test_snapshot_copy_src_snapshot" @@ -335,7 +330,6 @@ func TestSnapshotCopy(t *testing.T) { } func TestSnapshotCopyWithIsiPath(t *testing.T) { - sourceSnapshotPath := "test_snapshot_copy_src_volume" sourceSnapshotName := "test_snapshot_copy_src_snapshot" destinationVolume := "test_snapshot_copy_dst_volume" @@ -409,7 +403,6 @@ func TestSnapshotCopyWithIsiPath(t *testing.T) { } func TestSnapshotGetByIdentity(t *testing.T) { - snapshotPath := "test_snapshots_get_volume" snapshotName1 := "test_snapshots_get_snapshot_0" snapshotName2 := "test_snapshots_get_snapshot_1" @@ -453,7 +446,6 @@ func TestSnapshotGetByIdentity(t *testing.T) { } func TestSnapshotIsExistent(t *testing.T) { - snapshotPath := "test_snapshots_exist_volume" snapshotName1 := "test_snapshots_exist_snapshot_0" @@ -483,11 +475,9 @@ func TestSnapshotIsExistent(t *testing.T) { if !client.IsSnapshotExistent(defaultCtx, snapshotName1) { panic(fmt.Sprintf("not found snapshot %s, expected found\n", snapshotName1)) } - } func TestSnapshotExportWithZone(t *testing.T) { - snapshotPath := "test_snapshots_export_volume" snapshotName1 := "test_snapshots_export_snapshot_0" defaultAccessZone := "System" @@ -517,7 +507,6 @@ func TestSnapshotExportWithZone(t *testing.T) { // unexport snapshot defer client.UnexportByIDWithZone(defaultCtx, id, defaultAccessZone) - } func TestGetRealVolumeSnapshotPathWithIsiPath(t *testing.T) { @@ -559,5 +548,4 @@ func TestSnapshotSizeGet(t *testing.T) { if totalSize < 0 { panic(fmt.Sprintf("Snapshot folder size %d is not correct.\n", totalSize)) } - } diff --git a/user.go b/user.go index bd846ae..b149c58 100644 --- a/user.go +++ b/user.go @@ -43,8 +43,8 @@ func (c *Client) GetAllUsers(ctx context.Context) (UserList, error) { func (c *Client) GetUsersWithFilter(ctx context.Context, queryNamePrefix, queryDomain, queryZone, queryProvider *string, queryCached, queryResolveNames, queryMemberOf *bool, - queryLimit *int32) (UserList, error) { - + queryLimit *int32, +) (UserList, error) { return api.GetIsiUserList(ctx, c.API, queryNamePrefix, queryDomain, queryZone, queryProvider, queryCached, queryResolveNames, queryMemberOf, queryLimit) } @@ -60,7 +60,8 @@ func (c *Client) CreateUserByName(ctx context.Context, name string) (string, err func (c *Client) CreateUserWithOptions( ctx context.Context, name string, uid *int32, queryForce *bool, queryZone, queryProvider *string, email, homeDirectory, password, fullName, shell, primaryGroupName *string, - primaryGroupId, expiry *int32, enabled, passwordExpires, promptPasswordChange, unlock *bool) (string, error) { + primaryGroupId, expiry *int32, enabled, passwordExpires, promptPasswordChange, unlock *bool, +) (string, error) { return api.CreateIsiUser( ctx, c.API, name, queryForce, queryZone, queryProvider, @@ -76,8 +77,8 @@ func (c *Client) UpdateUserByNameOrUID( ctx context.Context, name *string, uid *int32, queryForce *bool, queryZone, queryProvider *string, email, homeDirectory, password, fullName, shell, primaryGroupName *string, - newUid, primaryGroupId, expiry *int32, enabled, passwordExpires, promptPasswordChange, unlock *bool) error { - + newUid, primaryGroupId, expiry *int32, enabled, passwordExpires, promptPasswordChange, unlock *bool, +) error { return api.UpdateIsiUser( ctx, c.API, name, uid, queryForce, queryZone, queryProvider, diff --git a/user_group.go b/user_group.go index 26ef58b..78f8019 100644 --- a/user_group.go +++ b/user_group.go @@ -46,8 +46,8 @@ func (c *Client) GetAllGroups(ctx context.Context) (GroupList, error) { func (c *Client) GetGroupsWithFilter(ctx context.Context, queryNamePrefix, queryDomain, queryZone, queryProvider *string, queryCached, queryResolveNames, queryMemberOf *bool, - queryLimit *int32) (GroupList, error) { - + queryLimit *int32, +) (GroupList, error) { return api.GetIsiGroupList(ctx, c.API, queryNamePrefix, queryDomain, queryZone, queryProvider, queryCached, queryResolveNames, queryMemberOf, queryLimit) } @@ -79,7 +79,8 @@ func (c *Client) CreatGroupByName(ctx context.Context, name string) (string, err // Optional filter: force, zone and provider. func (c *Client) CreateGroupWithOptions( ctx context.Context, name string, gid *int32, members []api.IsiAuthMemberItem, - queryForce *bool, queryZone, queryProvider *string) (string, error) { + queryForce *bool, queryZone, queryProvider *string, +) (string, error) { return api.CreateIsiGroup(ctx, c.API, name, gid, members, queryForce, queryZone, queryProvider) } @@ -87,7 +88,8 @@ func (c *Client) CreateGroupWithOptions( // Required: newGid, // Optional filter: zone and provider. func (c *Client) UpdateIsiGroupGIDByNameOrUID( - ctx context.Context, name *string, gid *int32, newGid int32, queryZone, queryProvider *string) error { + ctx context.Context, name *string, gid *int32, newGid int32, queryZone, queryProvider *string, +) error { return api.UpdateIsiGroupGID(ctx, c.API, name, gid, newGid, queryZone, queryProvider) } diff --git a/user_group_test.go b/user_group_test.go index 19c8525..0db7dc6 100644 --- a/user_group_test.go +++ b/user_group_test.go @@ -87,7 +87,6 @@ func TestGroupCreate(t *testing.T) { // Test GetGroupByNameOrGID(), CreatGroupByName(), UpdateIsiGroupGIDByNameOrUID() and DeleteGroupByNameOrGID() func TestGroupUpdate(t *testing.T) { - groupName := "test_group_create_update" _, err := client.CreatGroupByName(defaultCtx, groupName) defer client.DeleteGroupByNameOrGID(defaultCtx, &groupName, nil) diff --git a/user_test.go b/user_test.go index d796908..3732c86 100644 --- a/user_test.go +++ b/user_test.go @@ -47,7 +47,6 @@ func TestUserGet(t *testing.T) { // Test GetUserByNameOrUID(), CreateUser(), CreateUserWithOptions() and DeleteUserByNameOrUID() func TestUserCreate(t *testing.T) { - userName := "test_user_create_options" uid := int32(100000) email := "test.dell.com" diff --git a/volume.go b/volume.go index 7027c77..18f4133 100644 --- a/volume.go +++ b/volume.go @@ -38,8 +38,8 @@ type VolumeChildrenMap map[string]*apiv2.ContainerChild // GetVolume returns a specific volume by name or ID func (c *Client) GetVolume( - ctx context.Context, id, name string) (Volume, error) { - + ctx context.Context, id, name string, +) (Volume, error) { if id != "" { name = id } @@ -47,14 +47,14 @@ func (c *Client) GetVolume( if err != nil { return nil, err } - var isiVolume = &apiv1.IsiVolume{Name: name, AttributeMap: volume.AttributeMap} + isiVolume := &apiv1.IsiVolume{Name: name, AttributeMap: volume.AttributeMap} return isiVolume, nil } // GetVolumeWithIsiPath returns a specific volume by name or ID with isiPath func (c *Client) GetVolumeWithIsiPath( - ctx context.Context, isiPath, id, name string) (Volume, error) { - + ctx context.Context, isiPath, id, name string, +) (Volume, error) { if id != "" { name = id } @@ -62,13 +62,14 @@ func (c *Client) GetVolumeWithIsiPath( if err != nil { return nil, err } - var isiVolume = &apiv1.IsiVolume{Name: name, AttributeMap: volume.AttributeMap} + isiVolume := &apiv1.IsiVolume{Name: name, AttributeMap: volume.AttributeMap} return isiVolume, nil } // IsVolumeExistent checks whether a volume already exists func (c *Client) IsVolumeExistent( - ctx context.Context, id, name string) bool { + ctx context.Context, id, name string, +) bool { // Need change here if id != "" { name = id @@ -87,7 +88,8 @@ func (c *Client) IsVolumeExistent( // IsVolumeExistentWithIsiPath checks whether a volume already exists with isiPath func (c *Client) IsVolumeExistentWithIsiPath( - ctx context.Context, isiPath, id, name string) bool { + ctx context.Context, isiPath, id, name string, +) bool { // Need change here if id != "" { name = id @@ -106,7 +108,6 @@ func (c *Client) IsVolumeExistentWithIsiPath( // GetVolumes returns a list of volumes func (c *Client) GetVolumes(ctx context.Context) ([]Volume, error) { - volumes, err := apiv1.GetIsiVolumes(ctx, c.API) if err != nil { return nil, err @@ -121,63 +122,68 @@ func (c *Client) GetVolumes(ctx context.Context) ([]Volume, error) { // CreateVolume creates a volume func (c *Client) CreateVolume( - ctx context.Context, name string) (Volume, error) { + ctx context.Context, name string, +) (Volume, error) { _, err := apiv1.CreateIsiVolume(ctx, c.API, name) if err != nil { return nil, err } - var isiVolume = &apiv1.IsiVolume{Name: name, AttributeMap: nil} + isiVolume := &apiv1.IsiVolume{Name: name, AttributeMap: nil} return isiVolume, nil } // CreateVolumeWithIsipath creates a volume with isiPath func (c *Client) CreateVolumeWithIsipath( - ctx context.Context, isiPath, name, isiVolumePathPermissions string) (Volume, error) { + ctx context.Context, isiPath, name, isiVolumePathPermissions string, +) (Volume, error) { _, err := apiv1.CreateIsiVolumeWithIsiPath(ctx, c.API, isiPath, name, isiVolumePathPermissions) if err != nil { return nil, err } - var isiVolume = &apiv1.IsiVolume{Name: name, AttributeMap: nil} + isiVolume := &apiv1.IsiVolume{Name: name, AttributeMap: nil} return isiVolume, nil } // CreateVolumeWithIsipathMetaData creates a volume with isiPath func (c *Client) CreateVolumeWithIsipathMetaData( - ctx context.Context, isiPath, name, isiVolumePathPermissions string, metadata map[string]string) (Volume, error) { + ctx context.Context, isiPath, name, isiVolumePathPermissions string, metadata map[string]string, +) (Volume, error) { _, err := apiv1.CreateIsiVolumeWithIsiPathMetaData(ctx, c.API, isiPath, name, isiVolumePathPermissions, metadata) if err != nil { return nil, err } - var isiVolume = &apiv1.IsiVolume{Name: name, AttributeMap: nil} + isiVolume := &apiv1.IsiVolume{Name: name, AttributeMap: nil} return isiVolume, nil } // CreateVolumeNoACL creates a volume without setting ACL func (c *Client) CreateVolumeNoACL( - ctx context.Context, name string) (Volume, error) { - + ctx context.Context, name string, +) (Volume, error) { _, err := apiv1.CreateIsiVolumeWithACL(ctx, c.API, name, "0777") if err != nil { return nil, err } - var isiVolume = &apiv1.IsiVolume{Name: name, AttributeMap: nil} + isiVolume := &apiv1.IsiVolume{Name: name, AttributeMap: nil} return isiVolume, nil } // DeleteVolume deletes a volume func (c *Client) DeleteVolume( - ctx context.Context, name string) error { + ctx context.Context, name string, +) error { _, err := apiv1.DeleteIsiVolume(ctx, c.API, name) return err } // DeleteVolumeWithIsiPath deletes a volume with isiPath func (c *Client) DeleteVolumeWithIsiPath( - ctx context.Context, isiPath, name string) error { + ctx context.Context, isiPath, name string, +) error { _, err := apiv1.DeleteIsiVolumeWithIsiPath(ctx, c.API, isiPath, name) return err } @@ -199,7 +205,6 @@ func newConcurrentHTTPChan() chan bool { // all descendent directories to the current user prior to issuing a delete // call. func (c *Client) ForceDeleteVolume(ctx context.Context, name string) error { - var ( user = c.API.User() vpl = len(c.API.VolumesPath()) + 1 @@ -209,7 +214,7 @@ func (c *Client) ForceDeleteVolume(ctx context.Context, name string) error { setACLWait = &sync.WaitGroup{} setACLChan = newConcurrentHTTPChan() setACLDone = make(chan int) - mode = apiv2.FileMode(0755) + mode = apiv2.FileMode(0o755) acl = &apiv2.ACL{ Action: &apiv2.PActionTypeReplace, Authoritative: &apiv2.PAuthoritativeTypeMode, @@ -289,7 +294,8 @@ func (c *Client) ForceDeleteVolume(ctx context.Context, name string) error { // CopyVolume creates a volume based on an existing volume func (c *Client) CopyVolume( - ctx context.Context, src, dest string) (Volume, error) { + ctx context.Context, src, dest string, +) (Volume, error) { _, err := apiv1.CopyIsiVolume(ctx, c.API, src, dest) if err != nil { return nil, err @@ -300,7 +306,8 @@ func (c *Client) CopyVolume( // CopyVolumeWithIsiPath creates a volume based on an existing volume func (c *Client) CopyVolumeWithIsiPath( - ctx context.Context, isiPath, src, dest string) (Volume, error) { + ctx context.Context, isiPath, src, dest string, +) (Volume, error) { _, err := apiv1.CopyIsiVolumeWithIsiPath(ctx, c.API, isiPath, src, dest) if err != nil { return nil, err @@ -311,35 +318,37 @@ func (c *Client) CopyVolumeWithIsiPath( // ExportVolume exports a volume func (c *Client) ExportVolume( - ctx context.Context, name string) (int, error) { - + ctx context.Context, name string, +) (int, error) { return c.Export(ctx, name) } // ExportVolumeWithZone exports a volume in the specified access zone func (c *Client) ExportVolumeWithZone( - ctx context.Context, name, zone, description string) (int, error) { + ctx context.Context, name, zone, description string, +) (int, error) { return c.ExportWithZone(ctx, name, zone, description) } // ExportVolumeWithZoneAndPath exports a volume in the specified access zone and path func (c *Client) ExportVolumeWithZoneAndPath( - ctx context.Context, path, zone, description string) (int, error) { + ctx context.Context, path, zone, description string, +) (int, error) { return c.ExportWithZoneAndPath(ctx, path, zone, description) } // UnexportVolume stops exporting a volume func (c *Client) UnexportVolume( - ctx context.Context, name string) error { - + ctx context.Context, name string, +) error { return c.Unexport(ctx, name) } // QueryVolumeChildren retrieves a list of all of a volume's descendent files // and directories. func (c *Client) QueryVolumeChildren( - ctx context.Context, name string) (VolumeChildrenMap, error) { - + ctx context.Context, name string, +) (VolumeChildrenMap, error) { return apiv2.ContainerChildrenMapAll(ctx, c.API, name) } @@ -348,8 +357,8 @@ func (c *Client) CreateVolumeDir( ctx context.Context, volumeName, dirPath string, fileMode os.FileMode, - overwrite, recursive bool) error { - + overwrite, recursive bool, +) error { return apiv2.ContainerCreateDir( ctx, c.API, volumeName, dirPath, apiv2.FileMode(fileMode), overwrite, recursive) @@ -362,8 +371,8 @@ func (c *Client) CreateVolumeDir( // Volume-to-Export relationship. func (c *Client) GetVolumeExportMap( ctx context.Context, - includeRootClients bool) (map[Volume]Export, error) { - + includeRootClients bool, +) (map[Volume]Export, error) { volumes, err := c.GetVolumes(ctx) if err != nil { return nil, err @@ -416,8 +425,8 @@ func (c *Client) GetVolumeExportMap( // GetVolumeSize returns the total size of a snapshot folder func (c *Client) GetVolumeSize(ctx context.Context, - isiPath, name string) (int64, error) { - + isiPath, name string, +) (int64, error) { folder, err := apiv1.GetIsiVolumeWithSize(ctx, c.API, isiPath, name) if err != nil { return 0, err diff --git a/volume_test.go b/volume_test.go index fec18ec..b850d94 100644 --- a/volume_test.go +++ b/volume_test.go @@ -158,6 +158,7 @@ func TestVolumeGetCreateMetaData(*testing.T) { panic(fmt.Sprintf("Volume name not set properly. Expected: (%s) Actual: (%s)\n", volumeName, volume.Name)) } } + func TestVolumeDelete(*testing.T) { volumeName := "test_remove_volume_name" @@ -253,7 +254,6 @@ func TestVolumeCopy(*testing.T) { if subTestVolume.Name != destinationSubDirectoryPath { panic(fmt.Sprintf("Destination sub directory name not set properly. Expected: (%s) Actual: (%s)\n", destinationSubDirectoryPath, subTestVolume.Name)) } - } func TestVolumeCopyWithIsiPath(*testing.T) { @@ -315,7 +315,6 @@ func TestVolumeCopyWithIsiPath(*testing.T) { if subTestVolume.Name != destinationSubDirectoryPath { panic(fmt.Sprintf("Destination sub directory name not set properly. Expected: (%s) Actual: (%s)\n", destinationSubDirectoryPath, subTestVolume.Name)) } - } func TestVolumeExport(*testing.T) { @@ -324,7 +323,6 @@ func TestVolumeExport(*testing.T) { if err != nil { panic(err) } - } func TestVolumeUnexport(*testing.T) { @@ -333,7 +331,6 @@ func TestVolumeUnexport(*testing.T) { if err != nil { panic(err) } - } func TestVolumePath(*testing.T) { @@ -356,7 +353,7 @@ func TestVolumeQueryChildren(t *testing.T) { var ( ctx = defaultCtx - //context.WithValue(defaultCtx, log.LevelKey(), log.InfoLevel) + // context.WithValue(defaultCtx, log.LevelKey(), log.InfoLevel) err error volume Volume @@ -403,10 +400,10 @@ func TestVolumeQueryChildren(t *testing.T) { volChildCount = 9 - newDirMode = apiv2.FileMode(0755) - newFileMode = apiv2.FileMode(0644) - badDirMode = apiv2.FileMode(0700) - badFileMode = apiv2.FileMode(0400) + newDirMode = apiv2.FileMode(0o755) + newFileMode = apiv2.FileMode(0o644) + badDirMode = apiv2.FileMode(0o700) + badFileMode = apiv2.FileMode(0o400) newDirACL = &apiv2.ACL{ Action: &apiv2.PActionTypeReplace, @@ -484,7 +481,8 @@ func TestVolumeQueryChildren(t *testing.T) { defer client.ForceDeleteVolume(ctx, volumeName) setACLsWithPaths := func( - ctx context.Context, acl *apiv2.ACL, paths ...string) { + ctx context.Context, acl *apiv2.ACL, paths ...string, + ) { for _, p := range paths { assertNoError( t,