egnyte

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package egnyte provides an API interface to Egnyte APIs

Index

Constants

View Source
const (
	FilesystemScope       = "Egnyte.filesystem"
	UserScope             = "Egnyte.user"
	GroupScope            = "Egnyte.group"
	PermissionScope       = "Egnyte.permission"
	LaunchWebSessionScope = "Egnyte.launchwebsession"
)

OAuth Scopes

View Source
const (
	TimeFormat             = "Mon, 02 Jan 2006 15:04:05"
	LetterAndNumberPattern = `^[a-zA-Z0-9]*$`

	CheckSumResponseVersion = "2"
	ModTimeLayout           = "Mon, 02 Jan 2006 15:04:05 MST"
	Version                 = "v0.1.0"
	SourceName              = "go-sdk"
)
View Source
const (
	// Filesystem URIS
	URI_LIST          = URI_PREFIX_V1 + "fs%s"
	URI_DELETE_OBJECT = URI_PREFIX_V1 + "fs%s"
	URI_GET_FILE      = URI_PREFIX_V1 + "fs-content%s"
	URI_CREATE_FOLDER = URI_PREFIX_V1 + "fs%s"

	URI_CHUNKED_UPLOAD = URI_PREFIX_V1 + "fs-content-chunked%s"

	// Auth
	URI_OAUTH = "/puboauth/token"

	// Event URIS
	URI_FETCH_EVENT_ID = URI_PREFIX_V1 + "events/cursor"

	// Group Management URIs
	URI_GROUPS = URI_PREFIX_V2 + "groups"

	// User Management URIs
	URI_USERS    = URI_PREFIX_V2 + "users"
	URI_USERINFO = URI_PREFIX_V1 + "userinfo"

	// Permission URIs
	URI_PERMISSIONS = URI_PREFIX_V2 + "perms"
)
View Source
const URI_PREFIX_V1 = "/pubapi/v1/"
View Source
const URI_PREFIX_V2 = "/pubapi/v2/"

Variables

View Source
var ClientId string
View Source
var Domain string
View Source
var FolderRequired = errors.New("object must be a folder")
View Source
var Password string
View Source
var Username string

Functions

func Execute

func Execute()

func GetAccessToken

func GetAccessToken(ctx context.Context, config map[string]string) (*oauth2.Token, error)

GetAccessToken return auth token with grant type password This returns err if invalid details is provided else return auth token

func OAuthEndpoint

func OAuthEndpoint(domain string) oauth2.Endpoint

OAuthEndpoint constructs an `oauth2.Endpoint` for the given domain This returns nil if invalid domain is provided

func SHA512Digest

func SHA512Digest(buf []byte) string

SHA512Digest encode data into SHA512

Types

type ChunkUploadInfo

type ChunkUploadInfo struct {
	// contains filtered or unexported fields
}

func (*ChunkUploadInfo) GetChunk

func (c *ChunkUploadInfo) GetChunk() ([]byte, int64, int, error)

GetChunk returns chunk

func (*ChunkUploadInfo) GetLastChunk

func (c *ChunkUploadInfo) GetLastChunk() ([]byte, int)

func (*ChunkUploadInfo) GetRemainingBytes

func (c *ChunkUploadInfo) GetRemainingBytes() int64

func (*ChunkUploadInfo) GetResultCsum

func (c *ChunkUploadInfo) GetResultCsum() string

GetResultCsum return final check sum of all chunks

func (*ChunkUploadInfo) Init

func (c *ChunkUploadInfo) Init(data io.Reader, size int64, chunkSize int64)

func (*ChunkUploadInfo) SetChunkCheckSum

func (c *ChunkUploadInfo) SetChunkCheckSum(chunkNum int, csum string)

type Client

type Client struct {
	http.Client

	Username string
	Email    string

	WebAppURL string
	// contains filtered or unexported fields
}

Custom Client with extra metadata

func NewClient

func NewClient(ctx context.Context, rootUrl, token string, baseClient *http.Client) (*Client, error)

NewClient takes a http.Client, a root URL, and an auth token as input and returns a custom client.

func (*Client) CreateGroup

func (c *Client) CreateGroup(ctx context.Context, name string, members []*GroupMember) (*Group, error)

CreateGroup creates a group

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, user *User, sendInvite bool) (*User, error)

CreateUser creates a user using the provided User object

func (*Client) DeleteGroup

func (c *Client) DeleteGroup(ctx context.Context, groupId string) error

DeleteGroup deletes the group

func (*Client) DeleteUser

func (c *Client) DeleteUser(ctx context.Context, userId int) error

DeleteUser deletes an user

func (*Client) EventCursor

func (c *Client) EventCursor(ctx context.Context) (*EventID, error)

Our Events API supports polling for changes based on a cursor which indicates a position in the sequence of events that have occurred on your domain

func (*Client) GetGroup

func (c *Client) GetGroup(ctx context.Context, groupId string) (*Group, error)

GetGroup returns the group attributes along with the list of users which are in the group for the provided group ID

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, userId int) (*User, error)

GetUser returns a single user provided user ID

func (*Client) ListGroups

func (c *Client) ListGroups(ctx context.Context) ([]*Group, error)

ListGroups lists all the groups in the domain. Note that this returns only custom groups. Egnyte default groups (i.e. 'All Power Users', 'All Standard Users and Power Users', and 'All Standard Users') are not returned. Returns all groups for this domain by iterating through all available pages

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context) ([]*User, error)

ListUsers retrieves all, or a chosen subset of users Returns all users for this domain by iterating through all available pages

func (*Client) Object

func (c *Client) Object(path string) *Object

Returns a new Object for provided path with the client set in the object

func (*Client) PartialUpdateGroup

func (c *Client) PartialUpdateGroup(ctx context.Context, name string, members []*GroupMember) (*Group, error)

TODO: UpdateGroup

func (*Client) UpdateGroup

func (c *Client) UpdateGroup(ctx context.Context, name string, members []*GroupMember) (*Group, error)

TODO: UpdateGroup

func (*Client) UpdateUser

func (c *Client) UpdateUser(ctx context.Context, user *User) error

UpdateUser updates an user

func (*Client) Userinfo

func (c *Client) Userinfo(ctx context.Context) (*userInfoResponse, error)

Userinfo fetches the username for the provided domain

type Error

type Error struct {
	// StatusCode is the HTTP response status code and will always be populated
	StatusCode int `json:"status_code"`
	// ErrorCode is the Egnyte error code as returned in the response
	ErrorCode string
	Message   string
	// Body is the raw response returned by the server.
	// It is often but not always JSON, depending on how the request fails.
	Body string
	// Header contains the response header fields from the server.
	Header http.Header
}

func (*Error) Error

func (e *Error) Error() string

Error returns a string for the error and satisfies the error interface

func (*Error) Timeout

func (e *Error) Timeout() bool

type EventID

type EventID struct {
	Timestamp     string `json:"timestamp"`
	LatestEventID int64  `json:"latest_event_id"`
	OldestEventID int64  `json:"oldest_event_id"`
}

Event is the latest build ID

type FolderPermission

type FolderPermission struct {
	UserPerms             map[string]string `json:"userPerms"`
	GroupPerms            map[string]string `json:"groupPerms"`
	InheritsPermissions   bool              `json:"inheritsPermissions"`
	KeepParentPermissions bool              `json:"keepParentPermissions"`
}

FolderPermission represents the permissions of a folder in Egnyte

type Group

type Group struct {
	ID          string         `json:"id"`          // The globally unique group ID.
	DisplayName string         `json:"displayName"` // The name of the group.
	Members     []*GroupMember `json:"members"`     // A JSON array containing all users in the group.
}

Group represents an Egnyte group

type GroupMember

type GroupMember struct {
	Username string `json:"username"` // The username of a group member
	ID       int64  `json:"value"`    // The globally unique id of a group member
	Display  string `json:"display"`  // The display name of a group member
}

GroupMember represents a member of an Egnyte group

type MultiPutFileContent

type MultiPutFileContent struct {
	LastModified   string `json:"lastModified"`
	Content        string `json:"content"`
	LastModifiedBy string `json:"lastModifiedBy"`
}

type Object

type Object struct {
	Client             *Client
	Body               io.Reader
	Etag               string
	ModTime            time.Time
	Uploaded           int64     `json:"uploaded"`
	Checksum           string    `json:"checksum"`
	Size               int       `json:"size"`
	Path               string    `json:"path"`
	Name               string    `json:"name"`
	Locked             bool      `json:"locked"`
	IsFolder           bool      `json:"is_folder"`
	EntryID            string    `json:"entry_id"`
	GroupID            string    `json:"group_id"`
	LastModifiedStr    string    `json:"last_modified"`
	LastModifiedEpoch  int64     `json:"lastModified"`
	UploadedBy         string    `json:"uploaded_by"`
	NumVersions        int       `json:"num_versions"`
	ParentID           string    `json:"parent_id"`
	FolderID           string    `json:"folder_id"`
	Count              int       `json:"count"`
	Offset             int       `json:"offset"`
	TotalCount         int       `json:"total_count"`
	RestrictMoveDelete bool      `json:"restrict_move_delete"`
	PublicLinks        string    `json:"public_links"`
	AllowLinks         bool      `json:"allow_links"`
	Folders            []*Object `json:"folders"`
	Files              []*Object `json:"files"`
	Versions           []*Object `json:"versions"`
	Err                error     // This is used to store the error for this file in case of batch upload
}

Object represents a file or a folder object

func (*Object) ChunkUpload

func (o *Object) ChunkUpload(ctx context.Context, uploadInfo *UploadInfo, extraHeaders map[string]string) error

func (*Object) Copy

func (o *Object) Copy(ctx context.Context, newPath string) error

TODO: Copies a file or folder object to a new path

func (*Object) Create

func (o *Object) Create(ctx context.Context) (*Object, error)

creates a file or folder

func (*Object) Delete

func (o *Object) Delete(ctx context.Context) error

deletes a file or folder

func (*Object) Get

func (o *Object) Get(ctx context.Context) (io.ReadCloser, error)

Downloads a file

func (*Object) GetPermissions

func (o *Object) GetPermissions(ctx context.Context) (*FolderPermission, error)

GetPermissions fetches the permissions for the object

func (*Object) List

func (o *Object) List(ctx context.Context) (*Object, error)

lists a file or folder

func (*Object) Lock

func (o *Object) Lock(ctx context.Context) error

TODO: Lock a file

func (*Object) Move

func (o *Object) Move(ctx context.Context, newPath string) error

TODO: Moves a file or folder object from it's current path to the newPath

func (*Object) RemoveGroupPermission

func (o *Object) RemoveGroupPermission(ctx context.Context, groupName string) error

RemoveGroupPermission removes permissions for the given group on the object

func (*Object) RemoveUserPermission

func (o *Object) RemoveUserPermission(ctx context.Context, userName string) error

RemoveUserPermission removes permissions for the given user on the object

func (*Object) SetGroupPermission

func (o *Object) SetGroupPermission(ctx context.Context, groupName string, permString string) error

SetGroupPermission sets a permission for a single group on the object

func (*Object) SetPermissions

func (o *Object) SetPermissions(ctx context.Context, perms FolderPermission) error

SetPermissions sets the provided permissions on the object

func (*Object) SetUserPermission

func (o *Object) SetUserPermission(ctx context.Context, userName string, permString string) error

SetUserPermission sets a permission for a single user on the object

func (*Object) Stats

func (o *Object) Stats(ctx context.Context) error

TODO: Fetch information about folder size and item counts (for both file version and files inside the folder and all the subfolders)

func (*Object) Unlock

func (o *Object) Unlock(ctx context.Context) error

TODO: Unlock a file

type UploadInfo

type UploadInfo struct {
	Path      string
	Data      io.Reader
	Csum      string
	ChunkNum  int
	ChunkSize int64
	UploadID  string
}

type User

type User struct {
	ID                   int      `json:"id"`
	UserName             string   `json:"userName"`   // The Egnyte username for the user
	ExternalID           string   `json:"externalId"` // This is an immutable unique identifier provided by the API consumer
	Email                string   `json:"email"`      // The email address of the user
	Name                 UserName `json:"name"`       // First and last name of the user
	Active               bool     `json:"active"`     // Whether the user is active or inactive
	CreatedDate          string   `json:"createdDate"`
	LastModificationDate string   `json:"lastModificationDate"`
	LastActiveDate       string   `json:"lastActiveDate"`
	Locked               bool     `json:"locked"`
	AuthType             string   `json:"authType"` // The authentication type for the user
	UserType             string   `json:"userType"` // The type of the user
	// This is the way the user is identified within the SAML Response from an
	// SSO Identity Provider, i.e. the SAML Subject (e.g. jsmith)
	IdpUserID          string      `json:"idpUserId"`
	IsServiceAccount   bool        `json:"isServiceAccount"` // Whether user is a service account or not
	Language           string      `json:"language"`
	DeleteOnExpiry     interface{} `json:"deleteOnExpiry"`
	EmailChangePending bool        `json:"emailChangePending"`
	ExpiryDate         string      `json:"expiryDate"`
	Role               string      `json:"role"` // The role assigned to the user. Only applicable for Power Users
	// Used to bind child authentication policies to a user when using Active
	// Directory authentication in a multi-domain setup (e.g. jmiller@example.com)
	UserPrincipalName string `json:"userPrincipalName"`
	Groups            []struct {
		DisplayName string `json:"displayName"`
		Value       string `json:"value"`
	} `json:"groups"`
}

User represents an Egnyte user

type UserName

type UserName struct {
	FamilyName string `json:"familyName"`
	GivenName  string `json:"givenName"`
}

UserName is used to represent the family name and given name if a user

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL