github.com/cs3org/reva/v2@v2.27.7/pkg/eosclient/eosclient.go (about)

     1  // Copyright 2018-2021 CERN
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package eosclient
    20  
    21  import (
    22  	"context"
    23  	"io"
    24  
    25  	"github.com/cs3org/reva/v2/pkg/errtypes"
    26  	"github.com/cs3org/reva/v2/pkg/storage/utils/acl"
    27  )
    28  
    29  // EOSClient is the interface which enables access to EOS instances through various interfaces.
    30  type EOSClient interface {
    31  	AddACL(ctx context.Context, auth, rootAuth Authorization, path string, position uint, a *acl.Entry) error
    32  	RemoveACL(ctx context.Context, auth, rootAuth Authorization, path string, a *acl.Entry) error
    33  	UpdateACL(ctx context.Context, auth, rootAuth Authorization, path string, position uint, a *acl.Entry) error
    34  	GetACL(ctx context.Context, auth Authorization, path, aclType, target string) (*acl.Entry, error)
    35  	ListACLs(ctx context.Context, auth Authorization, path string) ([]*acl.Entry, error)
    36  	GetFileInfoByInode(ctx context.Context, auth Authorization, inode uint64) (*FileInfo, error)
    37  	GetFileInfoByFXID(ctx context.Context, auth Authorization, fxid string) (*FileInfo, error)
    38  	GetFileInfoByPath(ctx context.Context, auth Authorization, path string) (*FileInfo, error)
    39  	SetAttr(ctx context.Context, auth Authorization, attr *Attribute, errorIfExists, recursive bool, path string) error
    40  	UnsetAttr(ctx context.Context, auth Authorization, attr *Attribute, recursive bool, path string) error
    41  	GetAttr(ctx context.Context, auth Authorization, key, path string) (*Attribute, error)
    42  	GetQuota(ctx context.Context, username string, rootAuth Authorization, path string) (*QuotaInfo, error)
    43  	SetQuota(ctx context.Context, rooAuth Authorization, info *SetQuotaInfo) error
    44  	Touch(ctx context.Context, auth Authorization, path string) error
    45  	Chown(ctx context.Context, auth, chownauth Authorization, path string) error
    46  	Chmod(ctx context.Context, auth Authorization, mode, path string) error
    47  	CreateDir(ctx context.Context, auth Authorization, path string) error
    48  	Remove(ctx context.Context, auth Authorization, path string, noRecycle bool) error
    49  	Rename(ctx context.Context, auth Authorization, oldPath, newPath string) error
    50  	List(ctx context.Context, auth Authorization, path string) ([]*FileInfo, error)
    51  	Read(ctx context.Context, auth Authorization, path string) (io.ReadCloser, error)
    52  	Write(ctx context.Context, auth Authorization, path string, stream io.ReadCloser) error
    53  	WriteFile(ctx context.Context, auth Authorization, path, source string) error
    54  	ListDeletedEntries(ctx context.Context, auth Authorization) ([]*DeletedEntry, error)
    55  	RestoreDeletedEntry(ctx context.Context, auth Authorization, key string) error
    56  	PurgeDeletedEntries(ctx context.Context, auth Authorization) error
    57  	ListVersions(ctx context.Context, auth Authorization, p string) ([]*FileInfo, error)
    58  	RollbackToVersion(ctx context.Context, auth Authorization, path, version string) error
    59  	ReadVersion(ctx context.Context, auth Authorization, p, version string) (io.ReadCloser, error)
    60  	GenerateToken(ctx context.Context, auth Authorization, path string, a *acl.Entry) (string, error)
    61  }
    62  
    63  // AttrType is the type of extended attribute,
    64  // either system (sys) or user (user).
    65  type AttrType uint32
    66  
    67  // Attribute represents an EOS extended attribute.
    68  type Attribute struct {
    69  	Type     AttrType
    70  	Key, Val string
    71  }
    72  
    73  // FileInfo represents the metadata information returned by querying the EOS namespace.
    74  type FileInfo struct {
    75  	IsDir      bool
    76  	MTimeNanos uint32
    77  	Inode      uint64            `json:"inode"`
    78  	FID        uint64            `json:"fid"`
    79  	UID        uint64            `json:"uid"`
    80  	GID        uint64            `json:"gid"`
    81  	TreeSize   uint64            `json:"tree_size"`
    82  	MTimeSec   uint64            `json:"mtime_sec"`
    83  	Size       uint64            `json:"size"`
    84  	TreeCount  uint64            `json:"tree_count"`
    85  	File       string            `json:"eos_file"`
    86  	ETag       string            `json:"etag"`
    87  	Instance   string            `json:"instance"`
    88  	XS         *Checksum         `json:"xs"`
    89  	SysACL     *acl.ACLs         `json:"sys_acl"`
    90  	Attrs      map[string]string `json:"attrs"`
    91  }
    92  
    93  // DeletedEntry represents an entry from the trashbin.
    94  type DeletedEntry struct {
    95  	RestorePath   string
    96  	RestoreKey    string
    97  	Size          uint64
    98  	DeletionMTime uint64
    99  	IsDir         bool
   100  }
   101  
   102  // Checksum represents a cheksum entry for a file returned by EOS.
   103  type Checksum struct {
   104  	XSSum  string
   105  	XSType string
   106  }
   107  
   108  // QuotaInfo reports the available bytes and inodes for a particular user.
   109  // eos reports all quota values are unsigned long, see https://github.com/cern-eos/eos/blob/93515df8c0d5a858982853d960bec98f983c1285/mgm/Quota.hh#L135
   110  type QuotaInfo struct {
   111  	AvailableBytes, UsedBytes   uint64
   112  	AvailableInodes, UsedInodes uint64
   113  }
   114  
   115  // SetQuotaInfo encapsulates the information needed to
   116  // create a quota space in EOS for a user
   117  type SetQuotaInfo struct {
   118  	Username  string
   119  	UID       string
   120  	GID       string
   121  	QuotaNode string
   122  	MaxBytes  uint64
   123  	MaxFiles  uint64
   124  }
   125  
   126  // Constants for ACL position
   127  const (
   128  	EndPosition   uint = 0
   129  	StartPosition uint = 1
   130  )
   131  
   132  // Role holds the attributes required to authenticate to EOS via role-based access.
   133  type Role struct {
   134  	UID, GID string
   135  }
   136  
   137  // Authorization specifies the mechanisms through which EOS can be accessed.
   138  // One of the data members must be set.
   139  type Authorization struct {
   140  	Role  Role
   141  	Token string
   142  }
   143  
   144  // AttrAlreadyExistsError is the error raised when setting
   145  // an already existing attr on a resource
   146  const AttrAlreadyExistsError = errtypes.BadRequest("attr already exists")
   147  
   148  // AttrNotExistsError is the error raised when removing
   149  // an attribute that does not exist
   150  const AttrNotExistsError = errtypes.BadRequest("attr not exists")