Documentation ¶
Overview ¶
Package graph provides the basic APIs to interact with Microsoft Graph. This includes the DriveItem resource and supporting resources which are the basis of working with files and folders through the Microsoft Graph API.
Index ¶
- Constants
- func Delete(resource string, auth *Auth, headers ...Header) error
- func Get(resource string, auth *Auth, headers ...Header) ([]byte, error)
- func GetItemContent(id string, auth *Auth) ([]byte, uint64, error)
- func GetItemContentStream(id string, auth *Auth, output io.Writer) (uint64, error)
- func IDPath(id string) string
- func IsOffline(err error) bool
- func Patch(resource string, auth *Auth, content io.Reader, headers ...Header) ([]byte, error)
- func Post(resource string, auth *Auth, content io.Reader, headers ...Header) ([]byte, error)
- func Put(resource string, auth *Auth, content io.Reader, headers ...Header) ([]byte, error)
- func QuickXORHash(data *[]byte) string
- func QuickXORHashStream(reader io.ReadSeeker) string
- func Remove(id string, auth *Auth) error
- func Rename(itemID string, itemName string, parentID string, auth *Auth) error
- func Request(resource string, auth *Auth, method string, content io.Reader, ...) ([]byte, error)
- func ResourcePath(path string) string
- func SHA1Hash(data *[]byte) string
- func SHA1HashStream(reader io.ReadSeeker) string
- func SHA256Hash(data *[]byte) string
- func SHA256HashStream(reader io.ReadSeeker) string
- type Auth
- type AuthConfig
- type AuthError
- type Deleted
- type Drive
- type DriveItem
- func GetItem(id string, auth *Auth) (*DriveItem, error)
- func GetItemChild(id string, name string, auth *Auth) (*DriveItem, error)
- func GetItemChildren(id string, auth *Auth) ([]*DriveItem, error)
- func GetItemChildrenPath(path string, auth *Auth) ([]*DriveItem, error)
- func GetItemPath(path string, auth *Auth) (*DriveItem, error)
- func Mkdir(name string, parentID string, auth *Auth) (*DriveItem, error)
- type DriveItemParent
- type DriveQuota
- type File
- type Folder
- type Hashes
- type Header
- type User
Constants ¶
const ( DriveTypePersonal = "personal" DriveTypeBusiness = "business" )
DriveTypePersonal and friends represent the possible different values for a drive's type when fetched from the API.
const GraphURL = "https://graph.microsoft.com/v1.0"
GraphURL is the API endpoint of Microsoft Graph
Variables ¶
This section is empty.
Functions ¶
func GetItemContent ¶
GetItemContent retrieves an item's content from the Graph endpoint.
func GetItemContentStream ¶ added in v0.14.0
GetItemContentStream is the same as GetItemContent, but writes data to an output reader. This function assumes a brand-new io.Writer is used, so "output" must be truncated if there is content already in the io.Writer prior to use.
func QuickXORHash ¶ added in v0.9.1
QuickXORHash computes the Microsoft-specific QuickXORHash. Reusing rclone's implementation until I get the chance to rewrite/add test cases to remove the dependency.
func QuickXORHashStream ¶ added in v0.14.0
func QuickXORHashStream(reader io.ReadSeeker) string
QuickXORHashStream hashes a stream.
func Rename ¶
Rename moves and/or renames an item on the server. The itemName and parentID arguments correspond to the *new* basename or id of the parent.
func Request ¶
func Request(resource string, auth *Auth, method string, content io.Reader, headers ...Header) ([]byte, error)
Request performs an authenticated request to Microsoft Graph
func ResourcePath ¶
ResourcePath translates an item's path to the proper path used by Graph
func SHA1HashStream ¶ added in v0.14.0
func SHA1HashStream(reader io.ReadSeeker) string
SHA1HashStream hashes the contents of a stream.
func SHA256Hash ¶ added in v0.14.0
func SHA256HashStream ¶ added in v0.14.0
func SHA256HashStream(reader io.ReadSeeker) string
Types ¶
type Auth ¶
type Auth struct { AuthConfig `json:"config"` Account string `json:"account"` ExpiresIn int64 `json:"expires_in"` // only used for parsing ExpiresAt int64 `json:"expires_at"` AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` // contains filtered or unexported fields }
Auth represents a set of oauth2 authentication tokens
func Authenticate ¶
func Authenticate(config AuthConfig, path string, headless bool) *Auth
Authenticate performs authentication to Graph or load auth/refreshes it from an existing file. If headless is true, we will authenticate in the terminal.
type AuthConfig ¶ added in v0.13.0
type AuthConfig struct { ClientID string `json:"clientID" yaml:"clientID"` CodeURL string `json:"codeURL" yaml:"codeURL"` TokenURL string `json:"tokenURL" yaml:"tokenURL"` RedirectURL string `json:"redirectURL" yaml:"redirectURL"` }
AuthConfig configures the authentication flow
type AuthError ¶ added in v0.9.2
type AuthError struct { Error string `json:"error"` ErrorDescription string `json:"error_description"` ErrorCodes []int `json:"error_codes"` ErrorURI string `json:"error_uri"` Timestamp string `json:"timestamp"` // json.Unmarshal doesn't like this timestamp format TraceID string `json:"trace_id"` CorrelationID string `json:"correlation_id"` }
AuthError is an authentication error from the Microsoft API. Generally we don't see these unless something goes catastrophically wrong with Microsoft's authentication services.
type Deleted ¶
type Deleted struct {
State string `json:"state,omitempty"`
}
Deleted is used for detecting when items get deleted on the server https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/deleted
type Drive ¶
type Drive struct { ID string `json:"id"` DriveType string `json:"driveType"` // personal | business | documentLibrary Quota DriveQuota `json:"quota,omitempty"` }
Drive has some general information about the user's OneDrive https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/drive
type DriveItem ¶
type DriveItem struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Size uint64 `json:"size,omitempty"` ModTime *time.Time `json:"lastModifiedDatetime,omitempty"` Parent *DriveItemParent `json:"parentReference,omitempty"` Folder *Folder `json:"folder,omitempty"` File *File `json:"file,omitempty"` Deleted *Deleted `json:"deleted,omitempty"` ConflictBehavior string `json:"@microsoft.graph.conflictBehavior,omitempty"` ETag string `json:"eTag,omitempty"` }
DriveItem contains the data fields from the Graph API https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem
func GetItemChild ¶ added in v0.12.0
GetItemChild fetches the named child of an item.
func GetItemChildren ¶ added in v0.9.1
GetItemChildren fetches all children of an item denoted by ID.
func GetItemChildrenPath ¶ added in v0.9.1
GetItemChildrenPath fetches all children of an item denoted by path.
func GetItemPath ¶
GetItemPath fetches a DriveItem by path. Only used in special cases, like for the root item.
func (*DriveItem) ETagIsMatch ¶ added in v0.11.0
ETagIsMatch returns true if the etag matches the one in the DriveItem
func (*DriveItem) IsDir ¶ added in v0.12.0
IsDir returns if the DriveItem represents a directory or not
func (*DriveItem) ModTimeUnix ¶ added in v0.12.0
ModTimeUnix returns the modification time as a unix uint64 time
func (*DriveItem) VerifyChecksum ¶ added in v0.9.1
VerifyChecksum checks to see if a DriveItem's checksum matches what it's supposed to be. This is less of a cryptographic check and more of a file integrity check.
type DriveItemParent ¶
type DriveItemParent struct { //TODO Path is technically available, but we shouldn't use it Path string `json:"path,omitempty"` ID string `json:"id,omitempty"` DriveID string `json:"driveId,omitempty"` DriveType string `json:"driveType,omitempty"` // personal | business | documentLibrary }
DriveItemParent describes a DriveItem's parent in the Graph API https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/itemreference
type DriveQuota ¶
type DriveQuota struct { Deleted uint64 `json:"deleted"` // bytes in recycle bin FileCount uint64 `json:"fileCount"` // unavailable on personal accounts Remaining uint64 `json:"remaining"` State string `json:"state"` // normal | nearing | critical | exceeded Total uint64 `json:"total"` Used uint64 `json:"used"` }
DriveQuota is used to parse the User's current storage quotas from the API https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/quota
type File ¶
type File struct {
Hashes Hashes `json:"hashes,omitempty"`
}
File is used for checking for changes in local files (relative to the server). https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/file
type Folder ¶
type Folder struct {
ChildCount uint32 `json:"childCount,omitempty"`
}
Folder is used for parsing only https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/folder
type Hashes ¶
type Hashes struct { SHA1Hash string `json:"sha1Hash,omitempty"` QuickXorHash string `json:"quickXorHash,omitempty"` }
Hashes are integrity hashes used to determine if file content has changed. https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/hashes
type Header ¶ added in v0.13.0
type Header struct {
// contains filtered or unexported fields
}
This is an additional header that can be specified to Request
type User ¶
type User struct {
UserPrincipalName string `json:"userPrincipalName"`
}
User represents the user. Currently only used to fetch the account email so we can display it in file managers with .xdg-volume-info https://docs.microsoft.com/en-ca/graph/api/user-get
Directories ¶
Path | Synopsis |
---|---|
Package quickxorhash provides the quickXorHash algorithm which is a quick, simple non-cryptographic hash algorithm that works by XORing the bytes in a circular-shifting fashion.
|
Package quickxorhash provides the quickXorHash algorithm which is a quick, simple non-cryptographic hash algorithm that works by XORing the bytes in a circular-shifting fashion. |