drive

package module
v0.0.0-...-d8d83ed Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const APIVersion string = "v1.0"

APIVersion represents the APIVersion of msgraph used by this implementation

View Source
const BaseURL string = "https://graph.microsoft.com"

BaseURL represents the URL used to perform all ms graph API-calls

View Source
const LoginBaseURL string = "https://login.microsoftonline.com"

LoginBaseURL represents the basic url used to acquire a token for the msgraph api

View Source
const MaxPageSize int = 999

MaxPageSize is the maximum Page size for an API-call. This will be rewritten to use paging some day. Currently limits environments to 999 entries (e.g. Users, CalendarEvents etc.)

Variables

This section is empty.

Functions

func NewErr

func NewErr(statusCode int, body []byte) error

Types

type Client

Client represents a msgraph API connection instance.

An instance can also be json-unmarshalled an will immediately be initialized, hence a Token will be grabbed. If grabbing a token fails the JSON-Unmarshal returns an error.

func NewGraphClient

func NewGraphClient(tenantID, applicationID, clientSecret string) (*Client, error)

NewGraphClient creates a new Client instance with the given parameters and grab's a token.

Returns an error if the token can not be initialized. This method does not have to be used to create a new Client

func (*Client) GetDrive

func (cli *Client) GetDrive(id string) *Drive

func (*Client) String

func (cli *Client) String() string

func (*Client) UnmarshalJSON

func (cli *Client) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json unmarshal to be used by the json-library. This method additionally to loading the TenantID, ApplicationID and ClientSecret immediately gets a Token from msgraph (hence initialize this GraphAPI instance) and returns an error if any of the data provided is incorrect or the token can not be acquired

type Drive

type Drive struct {
	ID     string
	Client *Client
}

func (*Drive) Item

func (drv *Drive) Item(path string) (*Item, error)

func (*Drive) ListChildren

func (drv *Drive) ListChildren(path string) ([]*Item, error)

type Item

type Item struct {
	CreatedAt time.Time `json:"createdDateTime"`
	ID        string    `json:"id"`
	LastMod   time.Time `json:"lastModifiedDateTime"`
	Name      string    `json:"name"`
	WebURL    string    `json:"webUrl"`
	Size      int64     `json:"size"`

	CreatedBy struct {
		User `json:"user"`
	} `json:"createdBy"`
	LastModifiedBy struct {
		User `json:"user"`
	} `json:"lastModifiedBy"`

	ParentReference Reference `json:"parentReference"`

	FileSystemInfo struct {
		CreatedDateTime      time.Time `json:"createdDateTime"`
		LastModifiedDateTime time.Time `json:"lastModifiedDateTime"`
	} `json:"fileSystemInfo"`

	Folder *struct {
		ChildCount int `json:"childCount"`
	} `json:"folder,omitempty"`

	DownloadURL string `json:"@microsoft.graph.downloadUrl,omitempty"`

	File *struct {
		MimeType string `json:"mimeType"`
	} `json:"file,omitempty"`

	Image *struct {
		Height int `json:"height"`
		Width  int `json:"width"`
	} `json:"image,omitempty"`
}

func (*Item) IsFolder

func (item *Item) IsFolder() bool

type Reference

type Reference struct {
	DriveID   string `json:"driveId"`
	DriveType string `json:"driveType"`
	ID        string `json:"id"`
	Path      string `json:"path"`
}

type ReqError

type ReqError struct {
	URL        string `json:"-"`
	StatusCode int    `json:"-"`
	Err        struct {
		Code       string `json:"code"`
		Message    string `json:"message"`
		InnerError struct {
			Date            string `json:"date"`
			RequestID       string `json:"request-id"`
			ClientRequestID string `json:"client-request-id"`
		} `json:"innerError"`
	} `json:"error"`

	Raw string `json:"-"`
	// contains filtered or unexported fields
}

func (*ReqError) Error

func (re *ReqError) Error() string

func (*ReqError) String

func (re *ReqError) String() string

type Token

type Token struct {
	TokenType   string    // should always be "Bearer" for msgraph API-calls
	NotBefore   time.Time // time when the access token starts to be valid
	ExpiresOn   time.Time // time when the access token expires
	Resource    string    // will most likely always be https://graph.microsoft.com, hence the BaseURL
	AccessToken string    // the access-token itself
}

func (Token) GetAccessToken

func (t Token) GetAccessToken() string

GetAccessToken teturns the API access token in Bearer format representation ready to send to the API interface.

func (Token) HasExpired

func (t Token) HasExpired() bool

HasExpired returns true if the token has already expired.

Hint: this is a wrapper for >>!token.IsStillValid()<<

func (Token) IsAlreadyValid

func (t Token) IsAlreadyValid() bool

IsAlreadyValid returns true if the token is already valid, hence the NotBefore is before the current time. Otherwise false.

Hint: The current time is determined by time.Now()

func (Token) IsStillValid

func (t Token) IsStillValid() bool

IsStillValid returns true if the token is still valid, hence the current time is before ExpiresOn. Does NOT check it the token is yet valid or in the future.

Hint: The current time is determined by time.Now()

func (Token) IsValid

func (t Token) IsValid() bool

IsValid returns true if the token is already valid and is still valid. Otherwise false.

Hint: this is a wrapper for >>token.IsAlreadyValid() && token.IsStillValid()<<

func (Token) String

func (t Token) String() string

func (*Token) UnmarshalJSON

func (t *Token) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json unmarshal to be used by the json-library.

Hint: the UnmarshalJSON also checks immediately if the token is valid, hence the current time.Now() is after NotBefore and before ExpiresOn

func (Token) WantsToBeRefreshed

func (t Token) WantsToBeRefreshed() bool

WantsToBeRefreshed returns true if the token is already invalid or close to expire (10 second before ExpiresOn), otherwise false. time.Now() is used to determine the current time.

type User

type User struct {
	Email       string `json:"email"`
	ID          string `json:"id"`
	DisplayName string `json:"displayName"`
}

Directories

Path Synopsis
cmd
lambda command
server command

Jump to

Keyboard shortcuts

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