├── go.mod ├── onedrive ├── testdata │ ├── fake_asyncJobSuccessFile.json │ ├── fake_asyncJobFailed.json │ ├── fake_asyncJobSuccessFolder.json │ ├── fake_permission.json │ ├── fake_driveItems_withEmptyQuery_searchResults.json │ ├── fake_invalid_authentication.json │ ├── fake_defaultDrive.json │ ├── fake_drives.json │ ├── fake_driveItem.json │ ├── fake_permissions.json │ ├── fake_driveItems.json │ └── fake_driveItems_searchResults.json ├── owner.go ├── sharelinktype.go ├── sharelinkscope.go ├── specialfolder.go ├── error.go ├── user.go ├── driveasyncjob.go ├── permission_test.go ├── drives.go ├── drivesearch.go ├── drives_test.go ├── driveitems_test.go ├── onedrive_test.go ├── drivesearch_test.go ├── driveasyncjob_test.go ├── permission.go ├── onedrive.go └── driveitems.go ├── .gitignore ├── doc.go ├── test ├── integration │ ├── test.go │ ├── drivesasyncjob_test.go │ ├── drivesearch_test.go │ ├── drives_test.go │ ├── permission_test.go │ └── driveitems_test.go └── README.md ├── .github └── workflows │ ├── go.yml │ └── codeql-analysis.yml ├── CODE_OF_CONDUCT.md ├── README.md ├── go.sum └── LICENSE /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/goh-chunlin/go-onedrive 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/h2non/filetype v1.1.1 7 | golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84 8 | ) 9 | -------------------------------------------------------------------------------- /onedrive/testdata/fake_asyncJobSuccessFile.json: -------------------------------------------------------------------------------- 1 | { 2 | "operation": "itemCopy", 3 | "percentageComplete": 100.0, 4 | "resourceId": "0000000000000002!2", 5 | "status": "completed" 6 | } -------------------------------------------------------------------------------- /onedrive/testdata/fake_asyncJobFailed.json: -------------------------------------------------------------------------------- 1 | { 2 | "errorCode": "RelationshipNameAlreadyExists_1629.ce04", 3 | "operation": "itemCopy", 4 | "status": "failed", 5 | "statusDescription": "Completed 0/0 files; 0/3 bytes" 6 | } -------------------------------------------------------------------------------- /onedrive/testdata/fake_asyncJobSuccessFolder.json: -------------------------------------------------------------------------------- 1 | { 2 | "errorCode": "", 3 | "operation": "itemCopy", 4 | "percentageComplete": 100.0, 5 | "resourceId": "0000000000000001!1", 6 | "status": "completed", 7 | "statusDescription": "Completed 17/17 files; 1232869/1232869 bytes" 8 | } -------------------------------------------------------------------------------- /onedrive/owner.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | // Owner represents the owner of a OneDrive drive. 8 | type Owner struct { 9 | User User `json:"user"` 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ -------------------------------------------------------------------------------- /onedrive/testdata/fake_permission.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "123ABC", 3 | "roles": ["write"], 4 | "link": { 5 | "type": "view", 6 | "scope": "anonymous", 7 | "webUrl": "https://1drv.ms/A6913278E564460AA616C71B28AD6EB6", 8 | "application": { 9 | "id": "1234", 10 | "displayName": "Sample Application" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /onedrive/testdata/fake_driveItems_withEmptyQuery_searchResults.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": { 3 | "code": "invalidRequest", 4 | "message": "Search Query cannot be empty.", 5 | "innerError": { 6 | "date": "2020-12-21T11:12:39", 7 | "request-id": "3b752cb4-89a9-46f1-9b68-bfde2d3efdcd", 8 | "client-request-id": "6bf29bcc-c0fc-0f5c-3f98-1a88a24534a2" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /onedrive/testdata/fake_invalid_authentication.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": { 3 | "code": "InvalidAuthenticationToken", 4 | "message": "CompactToken validation failed with reason code: 80049228.", 5 | "innerError": { 6 | "date": "2020-11-13T04:27:35", 7 | "request-id": "00000000-0000-0000-0000-000000000001", 8 | "client-request-id": "00000000-0000-0000-0000-000000000002" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /onedrive/testdata/fake_defaultDrive.json: -------------------------------------------------------------------------------- 1 | { 2 | "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity", 3 | "id": "0000000000000001", 4 | "driveType": "personal", 5 | "owner": { 6 | "user": { 7 | "displayName": "User Display Name", 8 | "id": "0000000000000002" 9 | } 10 | }, 11 | "quota": { 12 | "deleted": 1, 13 | "remaining": 2000, 14 | "state": "normal", 15 | "total": 3000, 16 | "used": 999, 17 | "storagePlanInformation": { 18 | "upgradeAvailable": true 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | // Package api is the root of the packages used to access Microsoft OneDrive. 6 | // 7 | // Within api there exist also testing utilities. 8 | // 9 | // 10 | // Versioning and Stability 11 | // 12 | // Note that versioning and stability is strictly not communicated through Go 13 | // modules. Go modules are used only for dependency management. 14 | // 15 | // As a user, you should always locally vendor any API(s) that your code 16 | // relies upon in this module. 17 | package api 18 | -------------------------------------------------------------------------------- /onedrive/sharelinktype.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | // ShareLinkType the possible values for the type property of SharingLink 8 | // 9 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/sharinglink?view=odsp-graph-online#type-options 10 | type ShareLinkType int 11 | 12 | const ( 13 | View ShareLinkType = iota 14 | Edit 15 | Embed 16 | ) 17 | 18 | func (shareLinkType ShareLinkType) toString() string { 19 | return [...]string{"view", "edit", "embed"}[shareLinkType] 20 | } 21 | -------------------------------------------------------------------------------- /onedrive/sharelinkscope.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | // ShareLinkType the possible values for the scope property of SharingLink 8 | // 9 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/sharinglink?view=odsp-graph-online#scope-options 10 | type ShareLinkScope int 11 | 12 | const ( 13 | Anonymous ShareLinkScope = iota 14 | Organization 15 | ) 16 | 17 | func (shareLinkScope ShareLinkScope) toString() string { 18 | return [...]string{"anonymous", "organization"}[shareLinkScope] 19 | } 20 | -------------------------------------------------------------------------------- /test/integration/test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package integration 6 | 7 | import ( 8 | "context" 9 | "os" 10 | 11 | "github.com/goh-chunlin/go-onedrive/onedrive" 12 | 13 | "golang.org/x/oauth2" 14 | ) 15 | 16 | var client *onedrive.Client 17 | 18 | func setup() (context.Context, *onedrive.Client) { 19 | accessToken := os.Getenv("MICROSOFT_GRAPH_ACCESS_TOKEN") 20 | 21 | ctx := context.Background() 22 | ts := oauth2.StaticTokenSource( 23 | &oauth2.Token{AccessToken: accessToken}, 24 | ) 25 | tc := oauth2.NewClient(ctx, ts) 26 | 27 | client = onedrive.NewClient(tc) 28 | 29 | return ctx, client 30 | } 31 | -------------------------------------------------------------------------------- /onedrive/specialfolder.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | // DriveSpecialFolder indicates the pre-defined special folder in OneDrive 8 | // 9 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get_specialfolder?view=odsp-graph-online#special-folder-names 10 | type DriveSpecialFolder int 11 | 12 | const ( 13 | Documents DriveSpecialFolder = iota 14 | Photos 15 | CameraRoll 16 | AppRoot 17 | Music 18 | ) 19 | 20 | func (specialFolder DriveSpecialFolder) toString() string { 21 | return [...]string{"documents", "photos", "cameraroll", "approot", "music"}[specialFolder] 22 | } 23 | -------------------------------------------------------------------------------- /test/integration/drivesasyncjob_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package integration 6 | 7 | import "testing" 8 | 9 | func TestDriveAsyncJob_Monitor(t *testing.T) { 10 | // ctx, client := setup() 11 | 12 | // a, err := client.DriveAsyncJob.Monitor(ctx, "<>") 13 | // if err != nil { 14 | // t.Errorf("Error: %v\n", err) 15 | // return 16 | // } 17 | // fmt.Printf("Status: %v\n", a) 18 | 19 | // time.Sleep(5 * time.Second) 20 | 21 | // b, err := client.DriveAsyncJob.Monitor(ctx, "<>") 22 | // if err != nil { 23 | // t.Errorf("Error: %v\n", err) 24 | // return 25 | // } 26 | // fmt.Printf("Status: %v\n", b) 27 | } 28 | -------------------------------------------------------------------------------- /onedrive/testdata/fake_drives.json: -------------------------------------------------------------------------------- 1 | { 2 | "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives", 3 | "value": [ 4 | { 5 | "id": "0000000000000001", 6 | "driveType": "personal", 7 | "owner": { 8 | "user": { 9 | "displayName": "User Display Name", 10 | "id": "0000000000000002" 11 | } 12 | }, 13 | "quota": { 14 | "deleted": 1, 15 | "remaining": 2000, 16 | "state": "normal", 17 | "total": 3000, 18 | "used": 999, 19 | "storagePlanInformation": { 20 | "upgradeAvailable": true 21 | } 22 | } 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /onedrive/testdata/fake_driveItem.json: -------------------------------------------------------------------------------- 1 | { 2 | "createdBy": { 3 | "user": { 4 | "id": "efee1b77-fb3b-4f65-99d6-274c11914d12", 5 | "displayName": "Ryan Gregg" 6 | } 7 | }, 8 | "createdDateTime": "2016-03-21T20:01:37Z", 9 | "cTag": "\"c:{86EB4C8E-D20D-46B9-AD41-23B8868DDA8A},0\"", 10 | "eTag": "\"{86EB4C8E-D20D-46B9-AD41-23B8868DDA8A},1\"", 11 | "folder": { 12 | "childCount": 120 13 | }, 14 | "id": "01NKDM7HMOJTVYMDOSXFDK2QJDXCDI3WUK", 15 | "lastModifiedBy": { 16 | "user": { 17 | "id": "efee1b77-fb3b-4f65-99d6-274c11914d12", 18 | "displayName": "Ryan Gregg" 19 | } 20 | }, 21 | "lastModifiedDateTime": "2016-03-21T20:01:37Z", 22 | "name": "OneDrive", 23 | "root": {}, 24 | "size": 157286400, 25 | "webUrl": "https://contoso-my.sharepoint.com/personal/rgregg_contoso_com/Documents" 26 | } -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go Build 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | 11 | build: 12 | name: Build 13 | runs-on: ubuntu-latest 14 | steps: 15 | 16 | - name: Set up Go 1.15.x 17 | uses: actions/setup-go@v2 18 | with: 19 | go-version: ^1.15 20 | 21 | - name: Check out code into the Go module directory 22 | uses: actions/checkout@v2 23 | 24 | - name: Get dependencies 25 | run: | 26 | go get -v -t -d ./... 27 | if [ -f Gopkg.toml ]; then 28 | curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh 29 | dep ensure 30 | fi 31 | working-directory: onedrive 32 | 33 | - name: Build 34 | run: go build -v . 35 | working-directory: onedrive 36 | 37 | - name: Test 38 | run: go test -v . 39 | working-directory: onedrive 40 | -------------------------------------------------------------------------------- /onedrive/error.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | // ErrorResponse represents the error response returned by OneDrive drive API. 8 | type ErrorResponse struct { 9 | Error *Error `json:"error"` 10 | } 11 | 12 | // Error represents the error in the response returned by OneDrive drive API. 13 | type Error struct { 14 | Code string `json:"code"` 15 | Message string `json:"message"` 16 | LocalizedMessage string `json:"localizedMessage"` 17 | InnerError *InnerError `json:"innerError"` 18 | } 19 | 20 | // InnerError represents the error details in the error returned by OneDrive drive API. 21 | type InnerError struct { 22 | Date string `json:"date"` 23 | RequestId string `json:"request-id"` 24 | ClientRequestId string `json:"client-request-id"` 25 | } 26 | -------------------------------------------------------------------------------- /onedrive/user.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "context" 9 | ) 10 | 11 | type UserService service 12 | 13 | // User represents an user in Microsoft Live. 14 | type User struct { 15 | Id string `json:"id"` 16 | DisplayName string `json:"displayName"` 17 | Email string `json:"mail"` 18 | 19 | } 20 | 21 | // OneDrive API docs: https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http 22 | func (s *UserService) GetCurrentUserDetails(ctx context.Context) (*User, error) { 23 | apiURL := "me" 24 | 25 | req, err := s.client.NewRequest("GET", apiURL, nil) 26 | if err != nil { 27 | return nil, err 28 | } 29 | 30 | var oneDriveResponse *User 31 | err = s.client.Do(ctx, req, false, &oneDriveResponse) 32 | if err != nil { 33 | return nil, err 34 | } 35 | 36 | return oneDriveResponse, nil 37 | } 38 | -------------------------------------------------------------------------------- /test/integration/drivesearch_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package integration 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | ) 11 | 12 | func TestDriveSearch_Search(t *testing.T) { 13 | ctx, client := setup() 14 | 15 | searchDriveItems, err := client.DriveSearch.SearchAll(ctx, "Shana") 16 | if err != nil { 17 | t.Errorf("Error: %v\n", err) 18 | return 19 | } 20 | for _, driveItem := range searchDriveItems.DriveItems { 21 | fmt.Printf("Results: %v\n", driveItem.Name) 22 | } 23 | } 24 | 25 | func TestDriveSearch_SearchWithApostrophe(t *testing.T) { 26 | ctx, client := setup() 27 | 28 | searchDriveItems, err := client.DriveSearch.Search(ctx, "Rabbit's") 29 | if err != nil { 30 | t.Errorf("Error: %v\n", err) 31 | return 32 | } 33 | for _, driveItem := range searchDriveItems.DriveItems { 34 | fmt.Printf("Results: %v\n", driveItem.Name) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /onedrive/testdata/fake_permissions.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "value": [ 4 | { 5 | "id": "1", 6 | "roles": ["write"], 7 | "link": { 8 | "webUrl": "https://onedrive.live.com/redir?resid=5D33DD65C6932946!70859&authkey=!AL7N1QAfSWcjNU8&ithint=folder%2cgif", 9 | "type": "edit" 10 | } 11 | }, 12 | { 13 | "id": "2", 14 | "roles": ["write"], 15 | "grantedTo": { 16 | "user": { 17 | "id": "5D33DD65C6932946", 18 | "displayName": "John Doe" 19 | } 20 | }, 21 | "inheritedFrom": { 22 | "driveId": "1234567890ABD", 23 | "id": "1234567890ABC!123", 24 | "path": "/drive/root:/Documents" } 25 | }, 26 | { 27 | "id": "3", 28 | "roles": ["write"], 29 | "link": { 30 | "webUrl": "https://onedrive.live.com/redir?resid=5D33DD65C6932946!70859&authkey=!AL7N1QAfSWcjNU8&ithint=folder%2cgif", 31 | "type": "edit", 32 | "application": { 33 | "id": "12345", 34 | "displayName": "Contoso Time Manager" 35 | } 36 | } 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /test/integration/drives_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package integration 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | ) 11 | 12 | func TestDrives_GetDefaultDrive(t *testing.T) { 13 | ctx, client := setup() 14 | 15 | defaultDrive, err := client.Drives.Get(ctx, "") 16 | if err != nil { 17 | t.Errorf("Error: %v\n", err) 18 | return 19 | } 20 | fmt.Printf("Default Drive ID: %v\n", defaultDrive.Id) 21 | fmt.Printf("Default Drive Owner: %v\n", defaultDrive.Owner.User.DisplayName) 22 | } 23 | 24 | func TestDrives_GetDriveById(t *testing.T) { 25 | // ctx, client := setup() 26 | 27 | // specifiedDrive, err := client.Drives.Get(ctx, "<>") 28 | // if err != nil { 29 | // t.Errorf("Error: %v\n", err) 30 | // return 31 | // } 32 | // fmt.Printf("Specified Drive ID: %v\n", specifiedDrive.Id) 33 | // fmt.Printf("Specified Drive Owner: %v\n", specifiedDrive.Owner.User.DisplayName) 34 | } 35 | 36 | func TestDrives_GetAllDrives(t *testing.T) { 37 | ctx, client := setup() 38 | 39 | drives, err := client.Drives.List(ctx) 40 | if err != nil { 41 | t.Errorf("Error: %v\n", err) 42 | return 43 | } 44 | for _, drive := range drives.Drives { 45 | fmt.Printf("Results: %v\n", drive.Owner.User.DisplayName) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/integration/permission_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package integration 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | func TestPermission_CreateAnynomousViewLink(t *testing.T) { 12 | // ctx, client := setup() 13 | 14 | // permission, err := client.DrivePermissions.CreateShareLink(ctx, "<>", onedrive.View, onedrive.Anonymous) 15 | // if err != nil { 16 | // t.Errorf("Error: %v\n", err) 17 | // return 18 | // } 19 | // fmt.Printf("Result: %v\n", permission.Link.Type+"; "+permission.Link.Scope+"; "+permission.Link.URL) 20 | } 21 | 22 | func TestPermission_List(t *testing.T) { 23 | // ctx, client := setup() 24 | 25 | // permissions, err := client.DrivePermissions.List(ctx, "<>") 26 | // if err != nil { 27 | // t.Errorf("Error: %v\n", err) 28 | // return 29 | // } 30 | 31 | // fmt.Printf("Number of Permissions: %v\n", len(permissions)) 32 | // for _, permission := range permissions { 33 | // fmt.Printf("Results: %v\n", permission.ID+"; "+permission.Link.Type+"; "+permission.Link.Scope+"; "+permission.Link.URL) 34 | // } 35 | } 36 | 37 | func TestPermission_Delete(t *testing.T) { 38 | // ctx, client := setup() 39 | 40 | // err := client.DrivePermissions.Delete(ctx, "", "<>", "<>") 41 | // if err != nil { 42 | // t.Errorf("Error: %v\n", err) 43 | // return 44 | // } 45 | } 46 | -------------------------------------------------------------------------------- /onedrive/driveasyncjob.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import "context" 8 | 9 | // DriveAsyncJobService handles communication with the drive items searching related methods of the OneDrive API. 10 | // 11 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/long-running-actions?view=odsp-graph-online 12 | type DriveAsyncJobService service 13 | 14 | // OneDriveAsyncJobMonitorResponse represents the JSON object returned by the OneDrive Async Job Monitoring API. 15 | type OneDriveAsyncJobMonitorResponse struct { 16 | ErrorCode string `json:"errorCode"` 17 | ResourceId string `json:"resourceId"` 18 | Operation string `json:"operation"` 19 | Status string `json:"status"` 20 | StatusDescription string `json:"statusDescription"` 21 | PercentageCompleted float64 `json:"percentageCompleted"` 22 | } 23 | 24 | // Retrieve a status report from the monitor URL of OneDrive. 25 | // 26 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/long-running-actions?view=odsp-graph-online#retrieve-a-status-report-from-the-monitor-url 27 | func (s *DriveAsyncJobService) Monitor(ctx context.Context, monitorUrl string) (*OneDriveAsyncJobMonitorResponse, error) { 28 | req, err := s.client.NewRequestToOneDrive("GET", monitorUrl, nil) 29 | if err != nil { 30 | return nil, err 31 | } 32 | 33 | var oneDriveResponse *OneDriveAsyncJobMonitorResponse 34 | err = s.client.Do(ctx, req, true, &oneDriveResponse) 35 | if err != nil { 36 | return nil, err 37 | } 38 | 39 | return oneDriveResponse, nil 40 | } 41 | -------------------------------------------------------------------------------- /onedrive/permission_test.go: -------------------------------------------------------------------------------- 1 | package onedrive 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "net/http" 8 | "reflect" 9 | "testing" 10 | ) 11 | 12 | func TestCreateSharingLink(t *testing.T) { 13 | client, mux, _, teardown := setup() 14 | 15 | defer teardown() 16 | 17 | jsonData := getTestDataFromFile(t, "fake_permission.json") 18 | mux.HandleFunc("/me/drive/items/1/createLink", func(w http.ResponseWriter, r *http.Request) { 19 | testMethod(t, r, http.MethodPost) 20 | 21 | fmt.Fprint(w, string(jsonData)) 22 | }) 23 | 24 | ctx := context.Background() 25 | gotOneDriveResponse, err := client.DrivePermissions.CreateShareLink(ctx, "1", View, Anonymous) 26 | if err != nil { 27 | t.Errorf("CreateShareLink returned error: %v", err) 28 | } 29 | 30 | var wantDriveItem *Permission 31 | if err := json.Unmarshal(jsonData, &wantDriveItem); err != nil { 32 | t.Fatal(err) 33 | } 34 | 35 | if !reflect.DeepEqual(gotOneDriveResponse, wantDriveItem) { 36 | t.Errorf("CreateShareLink returned %+v, want %+v", gotOneDriveResponse, wantDriveItem) 37 | } 38 | } 39 | 40 | func TestListPermissions(t *testing.T) { 41 | client, mux, _, teardown := setup() 42 | 43 | defer teardown() 44 | 45 | jsonData := getTestDataFromFile(t, "fake_permissions.json") 46 | mux.HandleFunc("/me/drive/items/1/permissions", func(w http.ResponseWriter, r *http.Request) { 47 | testMethod(t, r, http.MethodGet) 48 | 49 | fmt.Fprint(w, string(jsonData)) 50 | }) 51 | 52 | ctx := context.Background() 53 | gotOneDriveResponse, err := client.DrivePermissions.List(ctx, "1") 54 | if err != nil { 55 | t.Errorf("List returned error: %v", err) 56 | } 57 | 58 | var wantDriveItem *ListPermissionsResponse 59 | if err := json.Unmarshal(jsonData, &wantDriveItem); err != nil { 60 | t.Fatal(err) 61 | } 62 | 63 | if !reflect.DeepEqual(gotOneDriveResponse, wantDriveItem.Value) { 64 | t.Errorf("List returned %+v, want %+v", gotOneDriveResponse, wantDriveItem) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | go-onedrive Tests 2 | =============== 3 | 4 | This directory contains additional test suites beyond the unit tests already in 5 | [../onedrive](../onedrive). Whereas the unit tests run very quickly (since they 6 | don't make any network calls) and are run by GitHub Action on every commit, the tests 7 | in this directory are only run manually. 8 | 9 | The test packages are: 10 | 11 | Integration 12 | ----------- 13 | 14 | This will exercise the entire go-onedrive library (or at least as much as is 15 | practical) against the live Microsoft Graph (and OneDrive API if Monitor is tested). 16 | These tests will verify that the library is properly coded against the actual behavior 17 | of the API, and will (hopefully) fail upon any incompatible change in the API. 18 | 19 | Because these tests are running using live data, there is a much higher 20 | probability of false positives in test failures due to network issues, test 21 | data having been changed, etc. 22 | 23 | These tests send real network traffic to the Microsoft Graph. 24 | Additionally, in order to test the methods that modify data, a real OAuth token 25 | will need to be present. While the tests will try to be well-behaved in terms 26 | of what data they modify, it is **strongly** recommended that these tests only 27 | be run using a dedicated test account. 28 | 29 | Run the tests under the integration folder using: 30 | 31 | ```bash 32 | SET MICROSOFT_GRAPH_ACCESS_TOKEN=XXX 33 | go test -v 34 | ``` 35 | 36 |
37 | 38 |
39 | 40 | *Access Token can be retrieved from the Microsoft Graph Explorer. It will also be auto refreshed.* 41 | 42 | Some of the tests are commented out because those test will create/delete/update the 43 | drive items and folders on the actual OneDrive. So, you can decide to uncomment them 44 | when you are going to test those operations. 45 | 46 | There is a keyword `<>` in the test where it is for you to key in the actual value 47 | based on your OneDrive setup, for example the actual Drive ID of your OneDrive Music 48 | folder. -------------------------------------------------------------------------------- /onedrive/drives.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "context" 9 | "net/url" 10 | ) 11 | 12 | // DrivesService handles communication with the drives related methods of the OneDrive API. 13 | // 14 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/drive?view=odsp-graph-online 15 | type DrivesService service 16 | 17 | // OneDriveDrivesResponse represents the JSON object containing drive list returned by the OneDrive API. 18 | type OneDriveDrivesResponse struct { 19 | ODataContext string `json:"@odata.context"` 20 | Drives []*Drive `json:"value"` 21 | } 22 | 23 | // Drive represents a OneDrive drive. 24 | type Drive struct { 25 | Id string `json:"id"` 26 | DriveType string `json:"driveType"` 27 | Owner *Owner `json:"owner"` 28 | Quota *DriveQuota `json:"quota"` 29 | } 30 | 31 | // DriveQuota represents the usage quota of a drive. 32 | type DriveQuota struct { 33 | Used int `json:"used"` 34 | Deleted int `json:"deleted"` 35 | Remaining int `json:"remaining"` 36 | Total int `json:"total"` 37 | State string `json:"state"` 38 | } 39 | 40 | // Get a specified drive of the authenticated user. 41 | // 42 | // If driveId is empty, it means the selected drive will be the default drive of 43 | // the authenticated user. 44 | // 45 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get?view=odsp-graph-online 46 | func (s *DrivesService) Get(ctx context.Context, driveId string) (*Drive, error) { 47 | apiURL := "me/drives/" + url.PathEscape(driveId) 48 | if driveId == "" { 49 | apiURL = "me/drive" 50 | } 51 | 52 | req, err := s.client.NewRequest("GET", apiURL, nil) 53 | if err != nil { 54 | return nil, err 55 | } 56 | 57 | var defaultDrive *Drive 58 | err = s.client.Do(ctx, req, false, &defaultDrive) 59 | if err != nil { 60 | return nil, err 61 | } 62 | 63 | return defaultDrive, nil 64 | } 65 | 66 | // List all the drives of the authenticated user. 67 | // 68 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_list?view=odsp-graph-online 69 | func (s *DrivesService) List(ctx context.Context) (*OneDriveDrivesResponse, error) { 70 | req, err := s.client.NewRequest("GET", "me/drives", nil) 71 | if err != nil { 72 | return nil, err 73 | } 74 | 75 | var oneDriveResponse *OneDriveDrivesResponse 76 | err = s.client.Do(ctx, req, false, &oneDriveResponse) 77 | if err != nil { 78 | return nil, err 79 | } 80 | 81 | return oneDriveResponse, nil 82 | } 83 | -------------------------------------------------------------------------------- /onedrive/drivesearch.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "context" 9 | "fmt" 10 | "strings" 11 | ) 12 | 13 | // DriveSearchService handles communication with the drive items searching related methods of the OneDrive API. 14 | // 15 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_search?view=odsp-graph-online 16 | type DriveSearchService service 17 | 18 | // OneDriveDriveSearchResponse represents the JSON object returned by the OneDrive API. 19 | type OneDriveDriveSearchResponse struct { 20 | ODataContext string `json:"@odata.context"` 21 | DriveItems []*DriveItem `json:"value"` 22 | } 23 | 24 | // Search the items in the default drive of the authenticated user. 25 | // 26 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_search?view=odsp-graph-online#request 27 | func (s *DriveSearchService) Search(ctx context.Context, query string) (*OneDriveDriveSearchResponse, error) { 28 | // For requests that use single quotes, if there are parameter values 29 | // also containing single quotes, those must be double escaped; otherwise, 30 | // the request will fail due to invalid syntax. 31 | // 32 | // Reference: https://docs.microsoft.com/en-us/graph/query-parameters 33 | query = strings.Replace(query, "'", "''", -1) 34 | 35 | apiURL := fmt.Sprintf("me/drive/root/search(q='%v')", query) 36 | 37 | req, err := s.client.NewRequest("GET", apiURL, nil) 38 | if err != nil { 39 | return nil, err 40 | } 41 | 42 | var oneDriveResponse *OneDriveDriveSearchResponse 43 | err = s.client.Do(ctx, req, false, &oneDriveResponse) 44 | if err != nil { 45 | return nil, err 46 | } 47 | 48 | return oneDriveResponse, nil 49 | } 50 | 51 | // Search the items in the default drive of the authenticated user as well as items shared with the user. 52 | // 53 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_search?view=odsp-graph-online#searching-for-items-a-user-can-access 54 | func (s *DriveSearchService) SearchAll(ctx context.Context, query string) (*OneDriveDriveSearchResponse, error) { 55 | query = strings.Replace(query, "'", "''", -1) 56 | 57 | apiURL := fmt.Sprintf("me/drive/search(q='%v')", query) 58 | 59 | req, err := s.client.NewRequest("GET", apiURL, nil) 60 | if err != nil { 61 | return nil, err 62 | } 63 | 64 | var oneDriveResponse *OneDriveDriveSearchResponse 65 | err = s.client.Do(ctx, req, false, &oneDriveResponse) 66 | if err != nil { 67 | return nil, err 68 | } 69 | 70 | return oneDriveResponse, nil 71 | } 72 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL Scan" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '15 5 * * 3' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | language: [ 'go' ] 32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 33 | # Learn more: 34 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 35 | 36 | steps: 37 | - name: Checkout repository 38 | uses: actions/checkout@v2 39 | 40 | # Initializes the CodeQL tools for scanning. 41 | - name: Initialize CodeQL 42 | uses: github/codeql-action/init@v1 43 | with: 44 | languages: ${{ matrix.language }} 45 | # If you wish to specify custom queries, you can do so here or in a config file. 46 | # By default, queries listed here will override any specified in a config file. 47 | # Prefix the list here with "+" to use these queries and those in the config file. 48 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 49 | 50 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 51 | # If this step fails, then you should remove it and run the build manually (see below) 52 | - name: Autobuild 53 | uses: github/codeql-action/autobuild@v1 54 | 55 | # ℹ️ Command-line programs to run using the OS shell. 56 | # 📚 https://git.io/JvXDl 57 | 58 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 59 | # and modify them (or add more) to build your code if your project 60 | # uses a compiled language 61 | 62 | - run: | 63 | go get -v -t -d ./... 64 | if [ -f Gopkg.toml ]; then 65 | curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh 66 | dep ensure 67 | fi 68 | go build -v . 69 | working-directory: onedrive 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v1 73 | -------------------------------------------------------------------------------- /onedrive/drives_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io/ioutil" 12 | "net/http" 13 | "os" 14 | "reflect" 15 | "testing" 16 | ) 17 | 18 | func TestDrivesService_Default_authenticatedUser(t *testing.T) { 19 | client, mux, _, teardown := setup() 20 | 21 | defer teardown() 22 | 23 | mux.HandleFunc("/me/drive", func(w http.ResponseWriter, r *http.Request) { 24 | testMethod(t, r, "GET") 25 | 26 | jsonData := getTestDataFromFile(t, "fake_defaultDrive.json") 27 | 28 | fmt.Fprint(w, string(jsonData)) 29 | }) 30 | 31 | ctx := context.Background() 32 | gotDefaultDrive, err := client.Drives.Get(ctx, "") 33 | if err != nil { 34 | t.Errorf("Drives.Default returned error: %v", err) 35 | } 36 | 37 | jsonFile, err := os.Open("testdata/fake_defaultDrive.json") 38 | 39 | if err != nil { 40 | t.Errorf("Cannot load the file data for comparison: %v", err) 41 | } 42 | 43 | defer jsonFile.Close() 44 | 45 | comparedToData, err := ioutil.ReadAll(jsonFile) 46 | 47 | if err != nil { 48 | t.Errorf("Cannot load the file data for comparison: %v", err) 49 | } 50 | 51 | var wantDefaultDrive *Drive 52 | json.Unmarshal(comparedToData, &wantDefaultDrive) 53 | 54 | if !reflect.DeepEqual(gotDefaultDrive, wantDefaultDrive) { 55 | t.Errorf("Drives.Default returned %+v, want %+v", gotDefaultDrive, wantDefaultDrive) 56 | } 57 | 58 | } 59 | 60 | func TestDrivesService_List_authenticatedUser(t *testing.T) { 61 | client, mux, _, teardown := setup() 62 | 63 | defer teardown() 64 | 65 | mux.HandleFunc("/me/drives", func(w http.ResponseWriter, r *http.Request) { 66 | testMethod(t, r, "GET") 67 | 68 | jsonData := getTestDataFromFile(t, "fake_drives.json") 69 | 70 | fmt.Fprint(w, string(jsonData)) 71 | }) 72 | 73 | ctx := context.Background() 74 | gotOneDriveResponse, err := client.Drives.List(ctx) 75 | if err != nil { 76 | t.Errorf("Drives.List returned error: %v", err) 77 | } 78 | 79 | jsonFile, err := os.Open("testdata/fake_drives.json") 80 | 81 | if err != nil { 82 | t.Errorf("Cannot load the file data for comparison: %v", err) 83 | } 84 | 85 | defer jsonFile.Close() 86 | 87 | comparedToData, err := ioutil.ReadAll(jsonFile) 88 | 89 | if err != nil { 90 | t.Errorf("Cannot load the file data for comparison: %v", err) 91 | } 92 | 93 | var wantOneDriveResponse *OneDriveDrivesResponse 94 | json.Unmarshal(comparedToData, &wantOneDriveResponse) 95 | 96 | if !reflect.DeepEqual(gotOneDriveResponse, wantOneDriveResponse) { 97 | t.Errorf("Drives.List returned %+v, want %+v", gotOneDriveResponse, wantOneDriveResponse) 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /onedrive/driveitems_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io/ioutil" 12 | "net/http" 13 | "os" 14 | "reflect" 15 | "testing" 16 | ) 17 | 18 | func TestDriveItemsService_ListRoot_authenticatedUser(t *testing.T) { 19 | client, mux, _, teardown := setup() 20 | 21 | defer teardown() 22 | 23 | mux.HandleFunc("/me/drive/root/children", func(w http.ResponseWriter, r *http.Request) { 24 | testMethod(t, r, "GET") 25 | 26 | jsonData := getTestDataFromFile(t, "fake_driveItems.json") 27 | 28 | fmt.Fprint(w, string(jsonData)) 29 | }) 30 | 31 | ctx := context.Background() 32 | gotOneDriveResponse, err := client.DriveItems.List(ctx, "") 33 | if err != nil { 34 | t.Errorf("DriveItems.List returned error: %v", err) 35 | } 36 | 37 | jsonFile, err := os.Open("testdata/fake_driveItems.json") 38 | 39 | if err != nil { 40 | t.Errorf("Cannot load the file data for comparison: %v", err) 41 | } 42 | 43 | defer jsonFile.Close() 44 | 45 | comparedToData, err := ioutil.ReadAll(jsonFile) 46 | 47 | if err != nil { 48 | t.Errorf("Cannot load the file data for comparison: %v", err) 49 | } 50 | 51 | var wantOneDriveResponse *OneDriveDriveItemsResponse 52 | json.Unmarshal(comparedToData, &wantOneDriveResponse) 53 | 54 | if !reflect.DeepEqual(gotOneDriveResponse, wantOneDriveResponse) { 55 | t.Errorf("Drives.List returned %+v, want %+v", gotOneDriveResponse, wantOneDriveResponse) 56 | } 57 | 58 | } 59 | 60 | func TestDriveItemsService_Get_authenticatedUser(t *testing.T) { 61 | client, mux, _, teardown := setup() 62 | 63 | defer teardown() 64 | 65 | mux.HandleFunc("/me/drive/items/1", func(w http.ResponseWriter, r *http.Request) { 66 | testMethod(t, r, "GET") 67 | 68 | jsonData := getTestDataFromFile(t, "fake_driveItem.json") 69 | 70 | fmt.Fprint(w, string(jsonData)) 71 | }) 72 | 73 | ctx := context.Background() 74 | gotDriveItem, err := client.DriveItems.Get(ctx, "1") 75 | if err != nil { 76 | t.Errorf("DriveItems.Get returned error: %v", err) 77 | } 78 | 79 | jsonFile, err := os.Open("testdata/fake_driveItem.json") 80 | 81 | if err != nil { 82 | t.Errorf("Cannot load the file data for comparison: %v", err) 83 | } 84 | 85 | defer jsonFile.Close() 86 | 87 | comparedToData, err := ioutil.ReadAll(jsonFile) 88 | 89 | if err != nil { 90 | t.Errorf("Cannot load the file data for comparison: %v", err) 91 | } 92 | 93 | var wantDriveItem *DriveItem 94 | json.Unmarshal(comparedToData, &wantDriveItem) 95 | 96 | if !reflect.DeepEqual(gotDriveItem, wantDriveItem) { 97 | t.Errorf("Drives.Item returned %+v, want %+v", gotDriveItem, wantDriveItem) 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /onedrive/onedrive_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "fmt" 9 | "io/ioutil" 10 | "net/http" 11 | "net/http/httptest" 12 | "net/url" 13 | "os" 14 | "testing" 15 | ) 16 | 17 | const ( 18 | // baseURLPath is a non-empty Client.BaseURL path to use during tests, 19 | // to ensure relative URLs are used for all endpoints. 20 | baseURLPath = "/api" 21 | baseOneDriveURLPath = "/test-onedrive-api" 22 | ) 23 | 24 | // setup sets up a test HTTP server along with a onedrive.Client that is 25 | // configured to talk to that test server. Tests should register handlers on 26 | // mux which provide mock responses for the API method being tested. 27 | func setup() (client *Client, mux *http.ServeMux, serverURL string, teardown func()) { 28 | // mux is the HTTP request multiplexer used with the test server. 29 | mux = http.NewServeMux() 30 | 31 | // Ensure that tests catch mistakes where the endpoint URL is specified as absolute rather than relative. 32 | apiHandler := http.NewServeMux() 33 | apiHandler.Handle(baseURLPath+"/", http.StripPrefix(baseURLPath, mux)) 34 | apiHandler.Handle(baseOneDriveURLPath+"/", http.StripPrefix(baseOneDriveURLPath, mux)) 35 | apiHandler.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { 36 | fmt.Fprintln(os.Stderr, "FAIL: Client.BaseURL path prefix is not preserved in the request URL:") 37 | fmt.Fprintln(os.Stderr) 38 | fmt.Fprintln(os.Stderr, "\t"+req.URL.String()) 39 | fmt.Fprintln(os.Stderr) 40 | fmt.Fprintln(os.Stderr, "\tDid you accidentally use an absolute endpoint URL rather than relative?") 41 | http.Error(w, "Client.BaseURL path prefix is not preserved in the request URL.", http.StatusInternalServerError) 42 | }) 43 | 44 | // server is a test HTTP server used to provide mock API responses. 45 | server := httptest.NewServer(apiHandler) 46 | 47 | // client is the GitHub client being tested and is configured to use test server. 48 | client = NewClient(nil) 49 | url, _ := url.Parse(server.URL + baseURLPath + "/") 50 | client.BaseURL = url 51 | 52 | return client, mux, server.URL, server.Close 53 | } 54 | 55 | func testMethod(t *testing.T, r *http.Request, want string) { 56 | t.Helper() 57 | if got := r.Method; got != want { 58 | t.Errorf("Request method: %v, want %v", got, want) 59 | } 60 | } 61 | 62 | func testHeader(t *testing.T, r *http.Request, header string, want string) { 63 | t.Helper() 64 | if got := r.Header.Get(header); got != want { 65 | t.Errorf("Header.Get(%q) returned %q, want %q", header, got, want) 66 | } 67 | } 68 | 69 | func getTestDataFromFile(t *testing.T, fileName string) []byte { 70 | jsonFile, err := os.Open("testdata/" + fileName) 71 | 72 | if err != nil { 73 | t.Errorf("Cannot load the test data: %v", err) 74 | } 75 | 76 | defer jsonFile.Close() 77 | 78 | testData, err := ioutil.ReadAll(jsonFile) 79 | 80 | if err != nil { 81 | t.Errorf("Cannot load the test data: %v", err) 82 | } 83 | 84 | return testData 85 | } 86 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting **Goh Chun Lin**. Chun Lin and the team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. Chun Lin and the team are obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /onedrive/drivesearch_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io/ioutil" 12 | "net/http" 13 | "os" 14 | "reflect" 15 | "testing" 16 | ) 17 | 18 | func TestDriveSearchService_SearchWithEmptyQuery_authenticatedUser(t *testing.T) { 19 | client, mux, _, teardown := setup() 20 | 21 | defer teardown() 22 | mux.HandleFunc("/me/drive/root/search(q='')", func(w http.ResponseWriter, r *http.Request) { 23 | testMethod(t, r, "GET") 24 | 25 | jsonData := getTestDataFromFile(t, "fake_driveItems_withEmptyQuery_searchResults.json") 26 | 27 | fmt.Fprint(w, string(jsonData)) 28 | }) 29 | 30 | ctx := context.Background() 31 | _, err := client.DriveSearch.Search(ctx, "") 32 | if err == nil { 33 | t.Errorf("There should be an error") 34 | } 35 | 36 | } 37 | 38 | func TestDriveSearchService_SearchDriveItems_authenticatedUser(t *testing.T) { 39 | client, mux, _, teardown := setup() 40 | 41 | defer teardown() 42 | mux.HandleFunc("/me/drive/root/search(q='Test')", func(w http.ResponseWriter, r *http.Request) { 43 | testMethod(t, r, "GET") 44 | 45 | jsonData := getTestDataFromFile(t, "fake_driveItems_searchResults.json") 46 | 47 | fmt.Fprint(w, string(jsonData)) 48 | }) 49 | 50 | ctx := context.Background() 51 | gotOneDriveResponse, err := client.DriveSearch.Search(ctx, "Test") 52 | if err != nil { 53 | t.Errorf("DriveSearch.Search returned error: %v", err) 54 | } 55 | 56 | jsonFile, err := os.Open("testdata/fake_driveItems_searchResults.json") 57 | 58 | if err != nil { 59 | t.Errorf("Cannot load the file data for comparison: %v", err) 60 | } 61 | 62 | defer jsonFile.Close() 63 | 64 | comparedToData, err := ioutil.ReadAll(jsonFile) 65 | 66 | if err != nil { 67 | t.Errorf("Cannot load the file data for comparison: %v", err) 68 | } 69 | 70 | var wantOneDriveResponse *OneDriveDriveSearchResponse 71 | json.Unmarshal(comparedToData, &wantOneDriveResponse) 72 | 73 | if !reflect.DeepEqual(gotOneDriveResponse, wantOneDriveResponse) { 74 | t.Errorf("DriveSearch.Search returned %+v, want %+v", gotOneDriveResponse, wantOneDriveResponse) 75 | } 76 | 77 | } 78 | 79 | func TestDriveSearchService_SearchAllDriveItems_authenticatedUser(t *testing.T) { 80 | client, mux, _, teardown := setup() 81 | 82 | defer teardown() 83 | mux.HandleFunc("/me/drive/search(q='Test')", func(w http.ResponseWriter, r *http.Request) { 84 | testMethod(t, r, "GET") 85 | 86 | jsonData := getTestDataFromFile(t, "fake_driveItems_searchResults.json") 87 | 88 | fmt.Fprint(w, string(jsonData)) 89 | }) 90 | 91 | ctx := context.Background() 92 | gotOneDriveResponse, err := client.DriveSearch.SearchAll(ctx, "Test") 93 | if err != nil { 94 | t.Errorf("DriveSearch.SearchAll returned error: %v", err) 95 | } 96 | 97 | jsonFile, err := os.Open("testdata/fake_driveItems_searchResults.json") 98 | 99 | if err != nil { 100 | t.Errorf("Cannot load the file data for comparison: %v", err) 101 | } 102 | 103 | defer jsonFile.Close() 104 | 105 | comparedToData, err := ioutil.ReadAll(jsonFile) 106 | 107 | if err != nil { 108 | t.Errorf("Cannot load the file data for comparison: %v", err) 109 | } 110 | 111 | var wantOneDriveResponse *OneDriveDriveSearchResponse 112 | json.Unmarshal(comparedToData, &wantOneDriveResponse) 113 | 114 | if !reflect.DeepEqual(gotOneDriveResponse, wantOneDriveResponse) { 115 | t.Errorf("DriveSearch.SearchAll returned %+v, want %+v", gotOneDriveResponse, wantOneDriveResponse) 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /onedrive/driveasyncjob_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "context" 9 | "encoding/json" 10 | "fmt" 11 | "io/ioutil" 12 | "net/http" 13 | "os" 14 | "reflect" 15 | "testing" 16 | ) 17 | 18 | func TestDriveAsyncJobService_Monitor_SuccessFile(t *testing.T) { 19 | client, mux, _, teardown := setup() 20 | 21 | defer teardown() 22 | 23 | mux.HandleFunc("/monitor/asyncJobSuccessFile", func(w http.ResponseWriter, r *http.Request) { 24 | testMethod(t, r, "GET") 25 | 26 | jsonData := getTestDataFromFile(t, "fake_asyncJobSuccessFile.json") 27 | 28 | fmt.Fprint(w, string(jsonData)) 29 | }) 30 | 31 | ctx := context.Background() 32 | gotOneDriveResponse, err := client.DriveAsyncJob.Monitor(ctx, "/test-onedrive-api/monitor/asyncJobSuccessFile") 33 | if err != nil { 34 | t.Errorf("DriveItems.Monitor returned error: %v", err) 35 | } 36 | 37 | jsonFile, err := os.Open("testdata/fake_asyncJobSuccessFile.json") 38 | 39 | if err != nil { 40 | t.Errorf("Cannot load the file data for comparison: %v", err) 41 | } 42 | 43 | defer jsonFile.Close() 44 | 45 | comparedToData, err := ioutil.ReadAll(jsonFile) 46 | 47 | if err != nil { 48 | t.Errorf("Cannot load the file data for comparison: %v", err) 49 | } 50 | 51 | var wantOneDriveResponse *OneDriveAsyncJobMonitorResponse 52 | json.Unmarshal(comparedToData, &wantOneDriveResponse) 53 | 54 | if !reflect.DeepEqual(gotOneDriveResponse, wantOneDriveResponse) { 55 | t.Errorf("Drives.Monitor returned %+v, want %+v", gotOneDriveResponse, wantOneDriveResponse) 56 | } 57 | 58 | } 59 | 60 | func TestDriveAsyncJobService_Monitor_SuccessFolder(t *testing.T) { 61 | client, mux, _, teardown := setup() 62 | 63 | defer teardown() 64 | 65 | mux.HandleFunc("/monitor/asyncJobSuccessFolder", func(w http.ResponseWriter, r *http.Request) { 66 | testMethod(t, r, "GET") 67 | 68 | jsonData := getTestDataFromFile(t, "fake_asyncJobSuccessFolder.json") 69 | 70 | fmt.Fprint(w, string(jsonData)) 71 | }) 72 | 73 | ctx := context.Background() 74 | gotOneDriveResponse, err := client.DriveAsyncJob.Monitor(ctx, "/test-onedrive-api/monitor/asyncJobSuccessFolder") 75 | if err != nil { 76 | t.Errorf("DriveItems.Monitor returned error: %v", err) 77 | } 78 | 79 | jsonFile, err := os.Open("testdata/fake_asyncJobSuccessFolder.json") 80 | 81 | if err != nil { 82 | t.Errorf("Cannot load the file data for comparison: %v", err) 83 | } 84 | 85 | defer jsonFile.Close() 86 | 87 | comparedToData, err := ioutil.ReadAll(jsonFile) 88 | 89 | if err != nil { 90 | t.Errorf("Cannot load the file data for comparison: %v", err) 91 | } 92 | 93 | var wantOneDriveResponse *OneDriveAsyncJobMonitorResponse 94 | json.Unmarshal(comparedToData, &wantOneDriveResponse) 95 | 96 | if !reflect.DeepEqual(gotOneDriveResponse, wantOneDriveResponse) { 97 | t.Errorf("Drives.Monitor returned %+v, want %+v", gotOneDriveResponse, wantOneDriveResponse) 98 | } 99 | 100 | } 101 | 102 | func TestDriveAsyncJobService_Monitor_Failed(t *testing.T) { 103 | client, mux, _, teardown := setup() 104 | 105 | defer teardown() 106 | 107 | mux.HandleFunc("/monitor/asyncJobFailed", func(w http.ResponseWriter, r *http.Request) { 108 | testMethod(t, r, "GET") 109 | 110 | jsonData := getTestDataFromFile(t, "fake_asyncJobFailed.json") 111 | 112 | fmt.Fprint(w, string(jsonData)) 113 | }) 114 | 115 | ctx := context.Background() 116 | gotOneDriveResponse, err := client.DriveAsyncJob.Monitor(ctx, "/test-onedrive-api/monitor/asyncJobFailed") 117 | if err != nil { 118 | t.Errorf("DriveItems.Monitor returned error: %v", err) 119 | } 120 | 121 | jsonFile, err := os.Open("testdata/fake_asyncJobFailed.json") 122 | 123 | if err != nil { 124 | t.Errorf("Cannot load the file data for comparison: %v", err) 125 | } 126 | 127 | defer jsonFile.Close() 128 | 129 | comparedToData, err := ioutil.ReadAll(jsonFile) 130 | 131 | if err != nil { 132 | t.Errorf("Cannot load the file data for comparison: %v", err) 133 | } 134 | 135 | var wantOneDriveResponse *OneDriveAsyncJobMonitorResponse 136 | json.Unmarshal(comparedToData, &wantOneDriveResponse) 137 | 138 | if !reflect.DeepEqual(gotOneDriveResponse, wantOneDriveResponse) { 139 | t.Errorf("Drives.Monitor returned %+v, want %+v", gotOneDriveResponse, wantOneDriveResponse) 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /onedrive/permission.go: -------------------------------------------------------------------------------- 1 | package onedrive 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "net/http" 7 | "net/url" 8 | ) 9 | 10 | // PermissionService handles permission settings of a drive item 11 | // 12 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/permission?view=odsp-graph-online 13 | type PermissionService service 14 | 15 | // Permission is the permission of a drive item. 16 | type Permission struct { 17 | ID string `json:"id"` 18 | GrantedTo interface{} `json:"grantedTo"` 19 | Link SharingLink `json:"link"` 20 | Roles []string `json:"roles"` 21 | } 22 | 23 | // CreateShareLinkRequest is the request for creating a share link. 24 | type CreateShareLinkRequest struct { 25 | Type string `json:"type"` // The type of sharing link to create. Either view, edit, or embed. 26 | Scope string `json:"scope"` // Optional. The scope of link to create. Either anonymous or organization. 27 | } 28 | 29 | // SharingLink resource groups link-related data items into a single structure. 30 | // Ref: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/sharinglink?view=odsp-graph-online 31 | type SharingLink struct { 32 | Type string `json:"type"` // The type of sharing link to create. Either view, edit, or embed. 33 | Scope string `json:"scope"` // Optional. The scope of link to create. Either anonymous or organization. 34 | URL string `json:"webUrl"` 35 | } 36 | 37 | // CreateShareLink will create a new sharing link if the specified link type doesn't already exist for the calling application. 38 | // If a sharing link of the specified type already exists for the app, the existing sharing link will be returned. 39 | // 40 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createlink?view=odsp-graph-online 41 | func (s *PermissionService) CreateShareLink(ctx context.Context, itemId string, permissionType ShareLinkType, permissionScope ShareLinkScope) (*Permission, error) { 42 | apiURL := "me/drive/items/" + url.PathEscape(itemId) + "/createLink" 43 | 44 | body := &CreateShareLinkRequest{Type: permissionType.toString(), Scope: permissionScope.toString()} 45 | req, err := s.client.NewRequest(http.MethodPost, apiURL, body) 46 | if err != nil { 47 | return nil, err 48 | } 49 | 50 | var oneDriveResponse *Permission 51 | err = s.client.Do(ctx, req, false, &oneDriveResponse) 52 | if err != nil { 53 | return nil, err 54 | } 55 | 56 | return oneDriveResponse, nil 57 | } 58 | 59 | // ListPermissionsResponse is the response of list permissions of a drive item 60 | type ListPermissionsResponse struct { 61 | Value []Permission `json:"value"` 62 | } 63 | 64 | // List lists the effective sharing permissions of on a DriveItem. 65 | // 66 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_list_permissions?view=odsp-graph-online 67 | func (s *PermissionService) List(ctx context.Context, itemId string) ([]Permission, error) { 68 | apiURL := "me/drive/items/" + url.PathEscape(itemId) + "/permissions" 69 | 70 | req, err := s.client.NewRequest(http.MethodGet, apiURL, nil) 71 | if err != nil { 72 | return nil, err 73 | } 74 | 75 | var oneDriveResponse *ListPermissionsResponse 76 | err = s.client.Do(ctx, req, false, &oneDriveResponse) 77 | if err != nil { 78 | return nil, err 79 | } 80 | 81 | return oneDriveResponse.Value, nil 82 | } 83 | 84 | // Delete will delete a sharing permission from a file or folder. 85 | // Only sharing permissions that are not inherited can be deleted. The inheritedFrom property must be null. 86 | // 87 | // If driveId is empty, it means the selected drive will be the default drive of 88 | // the authenticated user. 89 | // 90 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delete?view=odsp-graph-online 91 | func (s *PermissionService) Delete(ctx context.Context, driveId string, itemId string, permissionId string) error { 92 | if itemId == "" { 93 | return errors.New("Please provide the Item ID of the item to be deleted.") 94 | } 95 | 96 | apiURL := "me/drive/items/" + url.PathEscape(itemId) 97 | if driveId != "" { 98 | apiURL = "me/drives/" + url.PathEscape(driveId) + "/items/" + url.PathEscape(itemId) 99 | } 100 | 101 | apiURL += "/permissions/" + url.PathEscape(permissionId) 102 | 103 | req, err := s.client.NewRequest("DELETE", apiURL, nil) 104 | if err != nil { 105 | return err 106 | } 107 | 108 | var driveItem *DriveItem 109 | err = s.client.Do(ctx, req, false, &driveItem) 110 | if err != nil { 111 | return err 112 | } 113 | 114 | return nil 115 | } 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-onedrive 2 | 3 |
4 | 5 |
6 | 7 | ![Go Build](https://github.com/goh-chunlin/go-onedrive/workflows/Go%20Build/badge.svg?branch=main) 8 | ![CodeQL Scan](https://github.com/goh-chunlin/go-onedrive/workflows/CodeQL%20Scan/badge.svg?branch=main) 9 | [![Go Report Card](https://goreportcard.com/badge/github.com/goh-chunlin/go-onedrive)](https://goreportcard.com/report/github.com/goh-chunlin/go-onedrive) 10 | [![Go Reference](https://pkg.go.dev/badge/github.com/goh-chunlin/go-onedrive.svg)](https://pkg.go.dev/github.com/goh-chunlin/go-onedrive) 11 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 12 | [![Donate](https://img.shields.io/badge/$-donate-ff69b4.svg)](https://www.buymeacoffee.com/chunlin) 13 | 14 | go-onedrive is a Golang client library for accessing the [Microsoft OneDrive REST API](https://docs.microsoft.com/en-us/onedrive/developer/rest-api/?view=odsp-graph-online). 15 | 16 | This project is inspired by a few open-source projects, especially the [go-github project from Google](https://github.com/google/go-github). 17 | 18 | Currently, **go-onedrive requires Golang version 1.15 or greater**. go-onedrive tracks [Golang version support policy](https://golang.org/doc/devel/release.html#policy). I'll do my best not to break older versions of Golang if I don't have to, but due to tooling constraints, I don't always test older versions. 19 | 20 | ## Getting Started ## 21 | 22 | Module support was introduced in Go 1.15. Starting from Go 1.16, module-aware mode is enabled by default. Hence, I'll assume the module-aware mode is enabled when using this library. 23 | 24 | In the go.mod file, please make sure the correct package with the correct version is used. 25 | 26 | ``` 27 | ... 28 | 29 | require ( 30 | github.com/goh-chunlin/go-onedrive v1.1.1 31 | ... 32 | ) 33 | ``` 34 | 35 | The current latest version should be **v1.1.1** (updated on **17th July 2021**, as shown on the [Releases page](https://github.com/goh-chunlin/go-onedrive/releases)). 36 | 37 | In other go source files, you can then import the go-onedrive library as follows. 38 | ```go 39 | import "github.com/goh-chunlin/go-onedrive/onedrive" 40 | ``` 41 | 42 | Construct a new OneDrive client, then use the various services on the client to access different parts of the OneDrive API. For example: 43 | 44 | ```go 45 | ctx := context.Background() 46 | ts := oauth2.StaticTokenSource( 47 | &oauth2.Token{AccessToken: "..."}, 48 | ) 49 | tc := oauth2.NewClient(ctx, ts) 50 | 51 | client := onedrive.NewClient(tc) 52 | 53 | // list all OneDrive drives for the current logged in user 54 | drives, err := client.Drives.List(ctx) 55 | ``` 56 | 57 | NOTE: Using the [context](https://godoc.org/context) package, one can easily pass cancelation signals and deadlines to various services of the client for handling a request. In case there is no context available, then `context.Background()` can be used as a starting point. 58 | 59 | ## Authentication ## 60 | 61 | The go-onedrive library does not directly handle authentication. Instead, when creating a new client, pass an `http.Client` that can handle authentication for you. The easiest and recommended way to do this is using the [oauth2](https://github.com/golang/oauth2) 62 | library. 63 | 64 | Note that when using an authenticated Client, all calls made by the client will 65 | include the specified OAuth token. Therefore, authenticated clients should 66 | almost never be shared between different users. 67 | 68 | See the [oauth2 docs](https://godoc.org/golang.org/x/oauth2) for complete instructions on using that library. 69 | 70 | ## Contributing ## 71 | 72 | This library is being initially developed as a library for my personal project as listed below. 73 | - [Lunar.Music.Web](https://github.com/goh-chunlin/Lunar.Music.Web). 74 | 75 | Hence, API methods will likely be implemented in the order that they are needed by my personal project. However, I still welcome you to contribute to this project to support the following features. 76 | 77 | - [x] General 78 | - [x] Async job to track progress 79 | - [x] Search 80 | - [x] Drives 81 | - [x] Get default drive 82 | - [x] Get individual drive 83 | - [x] List all available drives 84 | - [x] Folders 85 | - [x] Create 86 | - [x] Copy 87 | - [x] Delete 88 | - [x] List children (items) 89 | - [x] Move 90 | - [x] Rename 91 | - [x] Create share link to a folder and its content 92 | - [x] List share links of a folder 93 | - [x] Items 94 | - [x] Get individual item 95 | - [x] Copy 96 | - [x] Delete 97 | - [x] Move 98 | - [x] Rename 99 | - [x] Create share link to an item 100 | - [x] Delete share link (or permission) of an item 101 | - [x] List share links of an item 102 | - [x] Upload simple item size < 4MB 103 | - [x] Upload and then replace with item size < 4MB 104 | - [x] Upload large item without additional retry attempts 105 | 106 | ## Sensei Projects ## 107 | 108 | Special thanks go to the following projects for providing useful references which help me in the development of this library. 109 | - [google/go-github](https://github.com/google/go-github); 110 | - [ggordan/go-onedrive](https://github.com/ggordan/go-onedrive); 111 | - [googleapis/google-api-go-client](https://github.com/googleapis/google-api-go-client). 112 | 113 | ## License ## 114 | 115 | This library is distributed under the GPL-3.0 License found in the [LICENSE](./LICENSE) file. 116 | -------------------------------------------------------------------------------- /onedrive/testdata/fake_driveItems.json: -------------------------------------------------------------------------------- 1 | { 2 | "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/drive/items('0000000000000001')/children", 3 | "@odata.count": 2, 4 | "value": [ 5 | { 6 | "createdDateTime": "2020-11-06T16:06:03.94Z", 7 | "cTag": "adDoxRjNBOUZDRDU3ODc4OUREITEzMjE5LjYzNzQwMjc4NjczNjQzMDAwMA", 8 | "eTag": "aMUYzQTlGQ0Q1Nzg3ODlERCExMzIxOS4y", 9 | "id": "1F3A9FCD578789DD!13219", 10 | "lastModifiedDateTime": "2020-11-06T16:57:53.643Z", 11 | "name": "AlbumImages", 12 | "size": 19135783, 13 | "webUrl": "https://1drv.ms/f/000001", 14 | "reactions": { 15 | "commentCount": 0 16 | }, 17 | "createdBy": { 18 | "application": { 19 | "displayName": "MSOffice15", 20 | "id": "00000000004" 21 | }, 22 | "device": { 23 | "id": "00000000003" 24 | }, 25 | "user": { 26 | "displayName": "User Display Name", 27 | "id": "0000000000000002" 28 | }, 29 | "oneDriveSync": { 30 | "@odata.type": "#microsoft.graph.identity", 31 | "id": "ef240ac9-30b7-4482-a273-105b5a62e451" 32 | } 33 | }, 34 | "lastModifiedBy": { 35 | "application": { 36 | "displayName": "OneDrive website", 37 | "id": "00000000005" 38 | }, 39 | "user": { 40 | "displayName": "User Display Name", 41 | "id": "0000000000000002" 42 | } 43 | }, 44 | "parentReference": { 45 | "driveId": "00000000003", 46 | "driveType": "personal", 47 | "id": "1F3A9FCD578789DD!000", 48 | "name": "Music", 49 | "path": "/drive/root:/Music" 50 | }, 51 | "fileSystemInfo": { 52 | "createdDateTime": "2020-11-06T16:06:02Z", 53 | "lastModifiedDateTime": "2020-11-06T16:08:30.73Z" 54 | }, 55 | "folder": { 56 | "childCount": 21, 57 | "view": { 58 | "viewType": "thumbnails", 59 | "sortBy": "takenOrCreatedDateTime", 60 | "sortOrder": "ascending" 61 | } 62 | } 63 | }, 64 | { 65 | "@microsoft.graph.downloadUrl": "https://public.by.files.1drv.com/y4mFXQDo_lDQCiQy-5W4bsg5rovTLQiKlnNAlK5lAFzgBHLctzjjaOn7zT44T7ObhymLeeun2dXOu2Ml8pz5VrCeVhpSIeborhdm2_1An2xDNf3tBV6GyM2Jbo4snlXQvDGMlQDuliorvB_M0J8uypk4BChIwPpNxGeoxjBWgOXp2EqDwA8op0B4_IpWyR09i6vHuJpxaJlkyQTu3vSHc5RfXsv8jmb0nYAKw9QeKP9Ztc", 66 | "createdDateTime": "2020-10-27T13:42:23.28Z", 67 | "cTag": "aYzoxRjNBOUZDRDU3ODc4OUREITEzMTY1LjI1Nw", 68 | "description": "ThanksAT", 69 | "eTag": "aMUYzQTlGQ0Q1Nzg3ODlERCExMzE2NS4y", 70 | "id": "1F3A9FCD578789DD!13165", 71 | "lastModifiedDateTime": "2020-10-27T13:42:42.087Z", 72 | "name": "AttackOnTitan-ThanksAT.mp3", 73 | "size": 5774636, 74 | "webUrl": "https://1drv.ms/u/s!AN2Jh1fNnzof5m0", 75 | "reactions": { 76 | "commentCount": 0 77 | }, 78 | "createdBy": { 79 | "application": { 80 | "displayName": "OneDrive", 81 | "id": "00000000006" 82 | }, 83 | "user": { 84 | "displayName": "User Display Name", 85 | "id": "0000000000000002" 86 | } 87 | }, 88 | "lastModifiedBy": { 89 | "application": { 90 | "displayName": "OneDrive", 91 | "id": "00000000006" 92 | }, 93 | "user": { 94 | "displayName": "User Display Name", 95 | "id": "0000000000000002" 96 | } 97 | }, 98 | "parentReference": { 99 | "driveId": "00000000003", 100 | "driveType": "personal", 101 | "id": "1F3A9FCD578789DD!000", 102 | "name": "Music", 103 | "path": "/drive/root:/Music" 104 | }, 105 | "audio": { 106 | "album": "Music 001", 107 | "albumArtist": "Artist 001", 108 | "bitrate": 192, 109 | "duration": 240430, 110 | "hasDrm": false, 111 | "isVariableBitrate": false, 112 | "title": "Album 001", 113 | "year": 2020 114 | }, 115 | "file": { 116 | "mimeType": "audio/mpeg", 117 | "hashes": { 118 | "quickXorHash": "KsRWfXmpnaoXqUBrcgTQPlxcoGM=", 119 | "sha1Hash": "AA4A8B91E267AD8145BA44D89352CD0C08EFDB2A", 120 | "sha256Hash": "405BCC9D246EE6270C301221C77C527DCC8EFD6EC6F794964FFAFB844276BBB5" 121 | } 122 | }, 123 | "fileSystemInfo": { 124 | "createdDateTime": "2020-10-27T13:42:23.28Z", 125 | "lastModifiedDateTime": "2020-10-27T12:16:50.573Z" 126 | } 127 | } 128 | ] 129 | } -------------------------------------------------------------------------------- /test/integration/driveitems_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package integration 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | ) 11 | 12 | func TestDriveItems_GetItemsInDefaultDriveRoot(t *testing.T) { 13 | //ctx, client := setup() 14 | // 15 | //driveItems, err := client.DriveItems.List(ctx, "") 16 | //if err != nil { 17 | // t.Errorf("Error: %v\n", err) 18 | // return 19 | //} 20 | //for _, driveItem := range driveItems.DriveItems { 21 | // fmt.Printf("Results: %v\n", driveItem.Name) 22 | //} 23 | } 24 | 25 | func TestDriveItems_GetItemsInSpecificFolder(t *testing.T) { 26 | // ctx, client := setup() 27 | 28 | // driveItems, err := client.DriveItems.List(ctx, "<>") 29 | // if err != nil { 30 | // t.Errorf("Error: %v\n", err) 31 | // return 32 | // } 33 | // for _, driveItem := range driveItems.DriveItems { 34 | // fmt.Printf("Results: %v\n", driveItem.Name) 35 | // } 36 | } 37 | 38 | func TestDriveItems_GetMusicFolder(t *testing.T) { 39 | //ctx, client := setup() 40 | // 41 | //musicDriveItem, err := client.DriveItems.GetSpecial(ctx, onedrive.Music) 42 | //if err != nil { 43 | // t.Errorf("Error: %v\n", err) 44 | // return 45 | //} 46 | //fmt.Printf("Music DriveItem Name: %v\n", musicDriveItem.Name) 47 | //fmt.Printf("Music DriveItem Id: %v\n", musicDriveItem.Id) 48 | } 49 | 50 | func TestDriveItems_GetItemsInMusicFolder(t *testing.T) { 51 | //ctx, client := setup() 52 | // 53 | //musicDriveItems, err := client.DriveItems.ListSpecial(ctx, onedrive.Music) 54 | //if err != nil { 55 | // t.Errorf("Error: %v\n", err) 56 | // return 57 | //} 58 | //for _, driveItem := range musicDriveItems.DriveItems { 59 | // fmt.Printf("Results: %v\n", driveItem.Name) 60 | //} 61 | } 62 | 63 | func TestDriveItems_CreateNewFolders(t *testing.T) { 64 | // ctx, client := setup() 65 | 66 | // newFolder, err := client.DriveItems.CreateNewFolder(ctx, "", "", "New Folder") 67 | // if err != nil { 68 | // t.Errorf("Error: %v\n", err) 69 | // return 70 | // } 71 | // fmt.Printf("New Folder Name: %v\n", newFolder.Name) 72 | // fmt.Printf("New Folder Id: %v\n", newFolder.Id) 73 | 74 | // // create a new subfolder "Inner SubFolder" in the "New Folder" created above for the authenticated user 75 | // newSubFolder, err := client.DriveItems.CreateNewFolder(ctx, "", newFolder.Id, "Inner SubFolder") 76 | // if err != nil { 77 | // t.Errorf("Error: %v\n", err) 78 | // return 79 | // } 80 | // fmt.Printf("New SubFolder Name: %v\n", newSubFolder.Name) 81 | // fmt.Printf("New SubFolder Id: %v\n", newSubFolder.Id) 82 | 83 | // // create a new folder "New Folder A" in the root of a selected drive for the authenticated user 84 | // newFolderA, err := client.DriveItems.CreateNewFolder(ctx, "<>", "", "New Folder A") 85 | // if err != nil { 86 | // t.Errorf("Error: %v\n", err) 87 | // return 88 | // } 89 | // fmt.Printf("New Folder Name: %v\n", newFolderA.Name) 90 | // fmt.Printf("New Folder Id: %v\n", newFolderA.Id) 91 | } 92 | 93 | func TestDriveItems_Move(t *testing.T) { 94 | //ctx, client := setup() 95 | 96 | // _, err = client.DriveItems.Move(ctx, "", "<>", "<>") 97 | // if err != nil { 98 | // t.Errorf("Error: %v\n", err) 99 | // return 100 | // } 101 | } 102 | 103 | func TestDriveItems_Delete(t *testing.T) { 104 | // ctx, client := setup() 105 | 106 | // err := client.DriveItems.Delete(ctx, "", "<>") 107 | // if err != nil { 108 | // t.Errorf("Error: %v\n", err) 109 | // return 110 | // } 111 | } 112 | 113 | func TestDriveItems_RenameItem(t *testing.T) { 114 | // ctx, client := setup() 115 | 116 | // renameResponse, err := client.DriveItems.Rename(ctx, "", "<>", "Test 1.txt") 117 | // if err != nil { 118 | // t.Errorf("Error: %v\n", err) 119 | // return 120 | // } 121 | // fmt.Printf("Results: %v\n", renameResponse.Name) 122 | } 123 | 124 | func TestDriveItems_CopyItem(t *testing.T) { 125 | // ctx, client := setup() 126 | 127 | // copyResponse, err := client.DriveItems.Copy(ctx, "", "<>", "", "<>", "Test 2.txt") 128 | // if err != nil { 129 | // t.Errorf("Error: %v\n", err) 130 | // return 131 | // } 132 | // fmt.Printf("Location: %v\n", copyResponse.Location) 133 | } 134 | 135 | func TestDriveItems_CopyFolder(t *testing.T) { 136 | // ctx, client := setup() 137 | 138 | //copyResponse, err = client.DriveItems.Copy(ctx, "", "<>", "", "<>", "New Folder") 139 | // if err != nil { 140 | // t.Errorf("Error: %v\n", err) 141 | // return 142 | // } 143 | // fmt.Printf("Location: %v\n", copyResponse.Location) 144 | } 145 | 146 | func TestDriveItems_UploadFile(t *testing.T) { 147 | // ctx, client := setup() 148 | 149 | // uploadedDriveItem, err := client.DriveItems.UploadNewFile(ctx, "", "<>", `<>`) 150 | // if err != nil { 151 | // t.Errorf("Error: %v\n", err) 152 | // return 153 | // } 154 | // fmt.Printf("Uploaded DriveItem: %v\n", uploadedDriveItem) 155 | } 156 | 157 | func TestDriveItems_UploadFileAndReplace(t *testing.T) { 158 | // ctx, client := setup() 159 | 160 | // uploadedDriveItem, err := client.DriveItems.UploadToReplaceFile(ctx, "", `<>`, "<>") 161 | // if err != nil { 162 | // t.Errorf("Error: %v\n", err) 163 | // return 164 | // } 165 | // fmt.Printf("Uploaded DriveItem: %v\n", uploadedDriveItem) 166 | } 167 | 168 | func TestDriveItems_UploadNewFileLarge(t *testing.T) { 169 | ctx, client := setup() 170 | folderID := "" 171 | fileLoc := "" 172 | //split a large file by 1280 KiB (3*320 KiB) and upload to upload session, unlimited total size 173 | //recommended: 5-10 mb 174 | uploadedDriveItem, err := client.DriveItems.UploadNewFileLarge(ctx, "", folderID, fileLoc, 320*1024*16) 175 | if err != nil { 176 | t.Errorf("Error: %v\n", err) 177 | return 178 | } 179 | //upload a large file without splitting (can handle file <60MB) 180 | fmt.Printf("Uploaded DriveItem: %v\n", uploadedDriveItem) 181 | //split 182 | uploadedDriveItem, err = client.DriveItems.UploadNewFileLarge(ctx, "", folderID, fileLoc, 0) 183 | if err != nil { 184 | t.Errorf("Error: %v\n", err) 185 | return 186 | } 187 | fmt.Printf("Uploaded DriveItem: %v\n", uploadedDriveItem) 188 | } 189 | -------------------------------------------------------------------------------- /onedrive/testdata/fake_driveItems_searchResults.json: -------------------------------------------------------------------------------- 1 | { 2 | "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)", 3 | "value": [ 4 | { 5 | "@odata.type": "#microsoft.graph.driveItem", 6 | "@microsoft.graph.downloadUrl": "https://public.by.files.1drv.com/Test-C30NdubB7LCYGUQwJCj5cqvc3UJCVn-4tftEv1JzB6Fm53guUHCelCaGLcL8R4_0A58zDfnXYK1Sn3gKMOfI1dl2gplnBksAMz2PjplwyMhx-_P0", 7 | "createdDateTime": "2020-11-28T11:57:20.457Z", 8 | "cTag": "Test", 9 | "description": "Test", 10 | "eTag": "Test", 11 | "id": "Test!Test", 12 | "lastModifiedDateTime": "2020-11-28T12:17:35.32Z", 13 | "name": "Test.png", 14 | "size": 869771, 15 | "webUrl": "https://1drv.ms/i/s!Test", 16 | "reactions": { 17 | "commentCount": 0 18 | }, 19 | "createdBy": { 20 | "application": { 21 | "displayName": "OneDrive website", 22 | "id": "00000000005" 23 | }, 24 | "device": { 25 | "id": "1800059a3671a1" 26 | }, 27 | "user": { 28 | "displayName": "User Display Name", 29 | "id": "0000000000000002" 30 | }, 31 | "oneDriveSync": { 32 | "@odata.type": "#microsoft.graph.identity", 33 | "id": "ef240ac9-30b7-4482-a273-105b5a62e451" 34 | } 35 | }, 36 | "lastModifiedBy": { 37 | "application": { 38 | "displayName": "OneDrive website", 39 | "id": "00000000005" 40 | }, 41 | "user": { 42 | "displayName": "User Display Name", 43 | "id": "0000000000000002" 44 | } 45 | }, 46 | "parentReference": { 47 | "driveId": "1f3a9fcd578789dd", 48 | "driveType": "personal", 49 | "id": "Test!13219", 50 | "name": "AlbumImages", 51 | "path": "/drive/root:/Music/AlbumImages" 52 | }, 53 | "file": { 54 | "mimeType": "image/png", 55 | "hashes": { 56 | "quickXorHash": "HEd9VHrvSaq28r5CdHsFNS7IvTc=", 57 | "sha1Hash": "3DFCC70761ADBD525FC327DBA4BCBCC057A76B36", 58 | "sha256Hash": "86F447874270945C3EE90A4A020D03A392B368ACB313EAF09AF28714FC656236" 59 | } 60 | }, 61 | "fileSystemInfo": { 62 | "createdDateTime": "2020-11-28T11:57:05Z", 63 | "lastModifiedDateTime": "2020-11-28T11:57:40.04Z" 64 | }, 65 | "image": { 66 | "height": 960, 67 | "width": 640 68 | }, 69 | "photo": {}, 70 | "searchResult": { 71 | "onClickTelemetryUrl": "https://www.bing.com/personalsearchclick?IG=22A96EAAC043447E817A5A6196F23AA4&CID=1F3A9FCD578789DD0000000000000000&ID=DevEx%2c5023&q=Shakugan&resid=1F3A9FCD578789DD%2113291" 72 | } 73 | }, 74 | { 75 | "@odata.type": "#microsoft.graph.driveItem", 76 | "@microsoft.graph.downloadUrl": "https://public.by.files.1drv.com/Test-V2A2FfNHzvwQcnK_fl4kAklvoQ2y80hR1q_Z_fab3xIF6grsE3tSxxRZJGaIIBSoREWlu1sdLynV8BV8RcxnTNy-o7pRn_J3tYIqfHKhMx0rd05zA8hAJUjvZPcoABmMjtwkA2VfSr_YR87c0vKiEM", 77 | "createdDateTime": "2020-12-08T05:29:18.74Z", 78 | "cTag": "Test", 79 | "description": "Test", 80 | "eTag": "Test", 81 | "id": "Test!13317", 82 | "lastModifiedDateTime": "2020-12-08T05:33:36.743Z", 83 | "name": "Test.mp3", 84 | "size": 4690355, 85 | "webUrl": "https://1drv.ms/u/s!Test", 86 | "reactions": { 87 | "commentCount": 0 88 | }, 89 | "createdBy": { 90 | "application": { 91 | "displayName": "OneDrive website", 92 | "id": "00000000005" 93 | }, 94 | "device": { 95 | "id": "1800059a3671a1" 96 | }, 97 | "user": { 98 | "displayName": "User Display Name", 99 | "id": "0000000000000002" 100 | }, 101 | "oneDriveSync": { 102 | "@odata.type": "#microsoft.graph.identity", 103 | "id": "ef240ac9-30b7-4482-a273-105b5a62e451" 104 | } 105 | }, 106 | "lastModifiedBy": { 107 | "device": { 108 | "id": "1800059a3671a1" 109 | }, 110 | "application": { 111 | "displayName": "OneDrive website", 112 | "id": "00000000005" 113 | }, 114 | "user": { 115 | "displayName": "User Display Name", 116 | "id": "0000000000000002" 117 | }, 118 | "oneDriveSync": { 119 | "@odata.type": "#microsoft.graph.identity", 120 | "id": "ef240ac9-30b7-4482-a273-105b5a62e451" 121 | } 122 | }, 123 | "parentReference": { 124 | "driveId": "Test", 125 | "driveType": "personal", 126 | "id": "Test!2538", 127 | "name": "Music", 128 | "path": "/drive/root:/Music" 129 | }, 130 | "audio": { 131 | "album": "Test", 132 | "albumArtist": "Test", 133 | "bitrate": 128, 134 | "duration": 292884, 135 | "hasDrm": false, 136 | "isVariableBitrate": false, 137 | "title": "Test" 138 | }, 139 | "file": { 140 | "mimeType": "audio/mpeg", 141 | "hashes": { 142 | "quickXorHash": "Test=", 143 | "sha1Hash": "Test", 144 | "sha256Hash": "Test" 145 | } 146 | }, 147 | "fileSystemInfo": { 148 | "createdDateTime": "2020-10-25T13:53:53Z", 149 | "lastModifiedDateTime": "2020-12-08T05:07:20Z" 150 | }, 151 | "searchResult": { 152 | "onClickTelemetryUrl": "https://www.bing.com/personalsearchclick?IG=22A96EAAC043447E817A5A6196F23AA4&CID=1F3A9FCD578789DD0000000000000000&ID=DevEx%2c5024&q=Shakugan&resid=1F3A9FCD578789DD%2113317" 153 | } 154 | } 155 | ] 156 | } -------------------------------------------------------------------------------- /onedrive/onedrive.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "bytes" 9 | "context" 10 | "encoding/json" 11 | "errors" 12 | "fmt" 13 | "io/ioutil" 14 | "net/http" 15 | "net/url" 16 | "strconv" 17 | "strings" 18 | ) 19 | 20 | const ( 21 | defaultBaseURL = "https://graph.microsoft.com/v1.0/" 22 | oneDriveBaseUrl = "https://api.onedrive.com/v1.0/" 23 | ) 24 | 25 | type service struct { 26 | client *Client 27 | } 28 | 29 | // A Client manages communication with the OneDrive API. 30 | type Client struct { 31 | client *http.Client // HTTP client used to communicate with the API. 32 | 33 | // Base URL for API requests. Defaults to the public OneDrive API. BaseURL should 34 | // always be specified with a trailing slash. 35 | BaseURL *url.URL 36 | 37 | common service // Reuse a single struct instead of allocating one for each service on the heap. 38 | 39 | // Services used for talking to different parts of the OneDrive API. 40 | User *UserService 41 | Drives *DrivesService 42 | DriveItems *DriveItemsService 43 | DriveSearch *DriveSearchService 44 | DriveAsyncJob *DriveAsyncJobService 45 | DrivePermissions *PermissionService 46 | } 47 | 48 | // NewClient returns a new OneDrive API client. If a nil httpClient is 49 | // provided, a new http.Client will be used. To use API methods which require 50 | // authentication, provide an http.Client that will perform the authentication 51 | // for you (such as that provided by the golang.org/x/oauth2 library). 52 | func NewClient(httpClient *http.Client) *Client { 53 | if httpClient == nil { 54 | httpClient = &http.Client{} 55 | } 56 | baseURL, _ := url.Parse(defaultBaseURL) 57 | 58 | c := &Client{client: httpClient, BaseURL: baseURL} 59 | 60 | c.common.client = c 61 | 62 | c.User = (*UserService)(&c.common) 63 | c.Drives = (*DrivesService)(&c.common) 64 | c.DriveItems = (*DriveItemsService)(&c.common) 65 | c.DriveSearch = (*DriveSearchService)(&c.common) 66 | c.DriveAsyncJob = (*DriveAsyncJobService)(&c.common) 67 | c.DrivePermissions = (*PermissionService)(&c.common) 68 | 69 | return c 70 | } 71 | 72 | // NewRequest creates an API request. A relative URL can be provided in relativeURL, 73 | // in which case it is resolved relative to the BaseURL of the Client. 74 | // Relative URLs should always be specified WITHOUT a preceding slash. 75 | func (c *Client) NewRequest(method, relativeURL string, body interface{}) (*http.Request, error) { 76 | if !strings.HasSuffix(c.BaseURL.Path, "/") { 77 | return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not.", c.BaseURL) 78 | } 79 | 80 | apiUrl, err := c.BaseURL.Parse(relativeURL) 81 | if err != nil { 82 | return nil, err 83 | } 84 | 85 | if body != nil { 86 | jsonBody, err := json.Marshal(body) 87 | 88 | if err != nil { 89 | return nil, err 90 | } 91 | 92 | req, err := http.NewRequest(method, apiUrl.String(), bytes.NewBuffer([]byte(jsonBody))) 93 | req.Header.Set("Content-Type", "application/json") 94 | 95 | return req, nil 96 | } 97 | 98 | // Create a new request using http 99 | req, err := http.NewRequest(method, apiUrl.String(), nil) 100 | 101 | return req, err 102 | } 103 | 104 | // NewFileUploadRequest creates an API request to upload files. A relative URL can be provided in relativeURL, 105 | // in which case it is resolved relative to the BaseURL of the Client. 106 | // Relative URLs should always be specified WITHOUT a preceding slash. 107 | func (c *Client) NewFileUploadRequest(relativeURL string, contentType string, fileReader *bytes.Reader) (*http.Request, error) { 108 | if !strings.HasSuffix(c.BaseURL.Path, "/") { 109 | return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not.", c.BaseURL) 110 | } 111 | 112 | if fileReader == nil { 113 | return nil, errors.New("Please provide the file reader.") 114 | } 115 | 116 | apiUrl, err := c.BaseURL.Parse(relativeURL) 117 | if err != nil { 118 | return nil, err 119 | } 120 | 121 | // Create a new request using http 122 | req, err := http.NewRequest("PUT", apiUrl.String(), fileReader) 123 | req.Header.Set("Content-Type", contentType) 124 | 125 | return req, err 126 | } 127 | 128 | // NewSessionFileUploadRequest creates an API request to upload files to an upload session. A relative URL can be provided in relativeURL, 129 | // in which case it is resolved relative to the BaseURL of the Client. 130 | // Absolute URLs should always be specified WITHOUT a preceding slash. 131 | // See: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online#upload-bytes-to-the-upload-session 132 | func (c *Client) NewSessionFileUploadRequest(absoluteUrl string, grandOffset, grandTotalSize int64, byteReader *bytes.Reader) (*http.Request, error) { 133 | //only basic check for sessionUpload url. 134 | apiUrl, err := c.BaseURL.Parse(absoluteUrl) 135 | if err != nil { 136 | return nil, err 137 | } 138 | absoluteUrl = apiUrl.String() 139 | // Create a new request using http 140 | contentLength := byteReader.Size() 141 | req, err := http.NewRequest("PUT", absoluteUrl, byteReader) 142 | req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10)) 143 | preliminaryLength := grandOffset 144 | preliminaryRange := grandOffset + contentLength - 1 145 | if preliminaryRange >= grandTotalSize { 146 | preliminaryRange = grandTotalSize - 1 147 | preliminaryLength = preliminaryRange - grandOffset + 1 148 | } 149 | req.Header.Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", preliminaryLength, preliminaryRange, grandTotalSize)) 150 | 151 | return req, err 152 | 153 | } 154 | 155 | // NewRequest creates an API request to OneDrive API directly with an absolute URL. 156 | func (c *Client) NewRequestToOneDrive(method, absoluteUrl string, body interface{}) (*http.Request, error) { 157 | if !strings.HasPrefix(absoluteUrl, oneDriveBaseUrl) && !strings.HasPrefix(absoluteUrl, "/test-onedrive-api") { 158 | return nil, fmt.Errorf("The given URL %q is not a OneDrive API URL.", c.BaseURL) 159 | } 160 | 161 | if strings.HasPrefix(absoluteUrl, "/test-onedrive-api") { 162 | apiUrl, err := c.BaseURL.Parse(absoluteUrl) 163 | if err != nil { 164 | return nil, err 165 | } 166 | 167 | absoluteUrl = apiUrl.String() 168 | } 169 | 170 | if body != nil { 171 | jsonBody, err := json.Marshal(body) 172 | 173 | if err != nil { 174 | return nil, err 175 | } 176 | 177 | req, err := http.NewRequest(method, absoluteUrl, bytes.NewBuffer([]byte(jsonBody))) 178 | req.Header.Set("Content-Type", "application/json") 179 | 180 | return req, nil 181 | } 182 | 183 | // Create a new request using http 184 | req, err := http.NewRequest(method, absoluteUrl, nil) 185 | 186 | return req, err 187 | } 188 | 189 | // Do sends an API request and returns the API response. The API response is 190 | // JSON decoded and stored in the value pointed to by target, or returned as an 191 | // error if an API error has occurred. 192 | func (c *Client) Do(ctx context.Context, req *http.Request, isUsingPlainHttpClient bool, target interface{}) error { 193 | if ctx == nil { 194 | return errors.New("context must be non-nil") 195 | } 196 | req = req.WithContext(ctx) 197 | 198 | var err error 199 | var resp *http.Response 200 | 201 | if isUsingPlainHttpClient { 202 | httpClient := &http.Client{} 203 | resp, err = httpClient.Do(req) 204 | } else { 205 | resp, err = c.client.Do(req) 206 | } 207 | 208 | if err != nil { 209 | // If we got an error, and the context has been canceled, the error from the context is probably more useful. 210 | select { 211 | case <-ctx.Done(): 212 | return ctx.Err() 213 | default: 214 | } 215 | 216 | // If the error type is *url.Error, sanitize its URL before returning. 217 | if e, ok := err.(*url.Error); ok { 218 | if url, err := url.Parse(e.URL); err == nil { 219 | e.URL = sanitizeURL(url).String() 220 | return e 221 | } 222 | } 223 | 224 | return err 225 | } 226 | 227 | defer resp.Body.Close() 228 | 229 | responseBody, err := ioutil.ReadAll(resp.Body) 230 | if err != nil { 231 | return err 232 | } 233 | 234 | locationHeader, isLocationHeaderExist := resp.Header["Location"] 235 | 236 | if resp.StatusCode == 202 && isLocationHeaderExist && len(responseBody) == 0 { 237 | 238 | var jsonStream = "{\"Location\": \"" + locationHeader[0] + "\"}" 239 | 240 | err = json.NewDecoder(strings.NewReader(jsonStream)).Decode(target) 241 | 242 | } else if resp.StatusCode != 204 { 243 | 244 | responseBodyReader := bytes.NewReader(responseBody) 245 | 246 | var oneDriveError *ErrorResponse 247 | if err = json.NewDecoder(responseBodyReader).Decode(&oneDriveError); err != nil { 248 | return err 249 | } 250 | 251 | if oneDriveError.Error != nil { 252 | if oneDriveError.Error.InnerError != nil { 253 | return errors.New(oneDriveError.Error.Code + " - " + oneDriveError.Error.Message + " (" + oneDriveError.Error.InnerError.Date + ")") 254 | } 255 | 256 | return errors.New(oneDriveError.Error.Code + " - " + oneDriveError.Error.Message) 257 | } 258 | 259 | responseBodyReader = bytes.NewReader(responseBody) 260 | err = json.NewDecoder(responseBodyReader).Decode(target) 261 | 262 | } 263 | 264 | return err 265 | } 266 | 267 | // sanitizeURL redacts the client_secret parameter from the URL which may be exposed to the user. 268 | func sanitizeURL(uri *url.URL) *url.URL { 269 | if uri == nil { 270 | return nil 271 | } 272 | params := uri.Query() 273 | if len(params.Get("client_secret")) > 0 { 274 | params.Set("client_secret", "REDACTED") 275 | uri.RawQuery = params.Encode() 276 | } 277 | return uri 278 | } 279 | -------------------------------------------------------------------------------- /onedrive/driveitems.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The go-onedrive AUTHORS. All rights reserved. 2 | // 3 | // Use of this source code is governed by a license that can be found in the LICENSE file. 4 | 5 | package onedrive 6 | 7 | import ( 8 | "bufio" 9 | "bytes" 10 | "context" 11 | "encoding/json" 12 | "errors" 13 | "fmt" 14 | "io" 15 | "net/url" 16 | "os" 17 | 18 | "github.com/h2non/filetype" 19 | ) 20 | 21 | // DriveItemsService handles communication with the drive items related methods of the OneDrive API. 22 | // 23 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem?view=odsp-graph-online 24 | type DriveItemsService service 25 | 26 | // OneDriveDriveItemsResponse represents the JSON object returned by the OneDrive API. 27 | type OneDriveDriveItemsResponse struct { 28 | ODataContext string `json:"@odata.context"` 29 | Count int `json:"@odata.count"` 30 | DriveItems []*DriveItem `json:"value"` 31 | } 32 | 33 | // DriveItem represents a OneDrive drive item. 34 | // Ref https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0 35 | type DriveItem struct { 36 | Name string `json:"name"` 37 | Id string `json:"id"` 38 | DownloadURL string `json:"@microsoft.graph.downloadUrl"` 39 | Description string `json:"description"` 40 | Size int64 `json:"size"` 41 | WebURL string `json:"webUrl"` 42 | Audio *OneDriveAudio `json:"audio"` 43 | Video *OneDriveVideo `json:"video"` 44 | Image *OneDriveImage `json:"image"` 45 | Photo *OneDrivePhoto `json:"photo"` 46 | File *DriveItemFile `json:"file"` 47 | Folder *DriveItemFolder `json:"folder"` 48 | } 49 | 50 | // DriveItemFile represents a OneDrive drive item file info. 51 | type DriveItemFile struct { 52 | MIMEType string `json:"mimeType"` 53 | } 54 | 55 | // DriveItemFolder represents a OneDrive drive item folder info. 56 | type DriveItemFolder struct { 57 | ChildCount int32 `json:"childCount"` 58 | } 59 | 60 | // NewFolderCreationRequest represents the information needed of a new OneDrive folder to be created. 61 | type NewFolderCreationRequest struct { 62 | FolderName string `json:"name"` 63 | FolderFacet Facet `json:"folder"` 64 | ConflictBehavior string `json:"@microsoft.graph.conflictBehavior"` 65 | } 66 | 67 | // NewUploadSessionCreationRequest represents the information needed of a new Upload Session to be created. 68 | type NewUploadSessionCreationRequest struct { 69 | //Will cause unknown malformed request error, so disabled for now. 70 | //FileName string `json:"name,omitempty"` 71 | ConflictBehavior string `json:"@microsoft.graph.conflictBehavior,omitempty"` 72 | } 73 | 74 | // NewUploadSessionCreationResponse represent the JSON object returned by the OneDrive API after requesting an upload session 75 | type NewUploadSessionCreationResponse struct { 76 | UploadURL string `json:"uploadUrl"` 77 | ExpirationDateTime string `json:"expirationDateTime"` 78 | } 79 | 80 | type UploadSessionUploadResponse struct { 81 | ExpirationDateTime string `json:"expirationDateTime"` 82 | NextExpectedRanges []string `json:"nextExpectedRanges"` 83 | //using anonymous struct to store fileInfo. ONLY if the transaction completed 84 | DriveItem 85 | } 86 | 87 | // Facet represents one of the facets for a folder or file. 88 | type Facet struct { 89 | } 90 | 91 | // MoveItemRequest represents the information needed of moving an item in OneDrive. 92 | type MoveItemRequest struct { 93 | ParentFolder ParentReference `json:"parentReference"` 94 | } 95 | 96 | // ParentReference represents the information of a folder in OneDrive. 97 | type ParentReference struct { 98 | Id string `json:"id"` 99 | Path string `json:"path"` 100 | DriveId string `json:"driveId"` 101 | } 102 | 103 | // MoveItemResponse represents the JSON object returned by the OneDrive API after moving an item. 104 | type MoveItemResponse struct { 105 | Id string `json:"id"` 106 | Name string `json:"name"` 107 | ParentFolder ParentReference `json:"parentReference"` 108 | } 109 | 110 | // RenameItemRequest represents the information needed of renaming an item in OneDrive. 111 | type RenameItemRequest struct { 112 | Name string `json:"name"` 113 | } 114 | 115 | // RenameItemResponse represents the JSON object returned by the OneDrive API after renaming an item. 116 | type RenameItemResponse struct { 117 | Id string `json:"id"` 118 | Name string `json:"name"` 119 | File Facet `json:"file"` 120 | } 121 | 122 | // CopyItemRequest represents the information needed of copying an item in OneDrive. 123 | type CopyItemRequest struct { 124 | Name string `json:"name"` 125 | ParentFolder ParentReference `json:"parentReference"` 126 | } 127 | 128 | // CopyItemResponse represents the JSON object returned by the OneDrive API after copying an item. 129 | type CopyItemResponse struct { 130 | Location string `json:"location"` 131 | } 132 | 133 | // OneDriveAudio represents the audio metadata of a OneDrive drive item which is an audio. 134 | type OneDriveAudio struct { 135 | Title string `json:"title"` 136 | Album string `json:"album"` 137 | AlbumArtist string `json:"albumArtist"` 138 | Duration int `json:"duration"` 139 | } 140 | 141 | // OneDriveAudio represents the image metadata of a OneDrive drive item which is an image. 142 | type OneDriveImage struct { 143 | Height float64 `json:"height"` 144 | Width float64 `json:"width"` 145 | } 146 | 147 | // OneDrivePhoto represents the photo metadata of a OneDrive drive item which is a photo. 148 | // Ref https://docs.microsoft.com/en-us/graph/api/resources/photo?view=graph-rest-1.0 149 | type OneDrivePhoto struct { 150 | CameraMake string `json:"cameraMake"` 151 | CameraModel string `json:"cameraModel"` 152 | } 153 | 154 | // OneDriveVideo represents the video metadata of a OneDrive drive item. 155 | // Ref: https://docs.microsoft.com/en-us/graph/api/resources/video?view=graph-rest-1.0 156 | type OneDriveVideo struct { 157 | Duration int `json:"duration"` 158 | Height float64 `json:"height"` 159 | Width float64 `json:"width"` 160 | } 161 | 162 | // List the items of a folder in the default drive of the authenticated user. 163 | // 164 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem?view=odsp-graph-online 165 | func (s *DriveItemsService) List(ctx context.Context, folderId string) (*OneDriveDriveItemsResponse, error) { 166 | apiURL := "me/drive/items/" + url.PathEscape(folderId) + "/children" 167 | if folderId == "" { 168 | apiURL = "me/drive/root/children" 169 | } 170 | 171 | req, err := s.client.NewRequest("GET", apiURL, nil) 172 | if err != nil { 173 | return nil, err 174 | } 175 | 176 | var oneDriveResponse *OneDriveDriveItemsResponse 177 | err = s.client.Do(ctx, req, false, &oneDriveResponse) 178 | if err != nil { 179 | return nil, err 180 | } 181 | 182 | return oneDriveResponse, nil 183 | } 184 | 185 | // List the items of a special folder in the default drive of the authenticated user. 186 | // 187 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get_specialfolder?view=odsp-graph-online#get-children-of-a-special-folder 188 | func (s *DriveItemsService) ListSpecial(ctx context.Context, folderName DriveSpecialFolder) (*OneDriveDriveItemsResponse, error) { 189 | apiURL := "me/drive/special/" + url.PathEscape(folderName.toString()) + "/children" 190 | 191 | req, err := s.client.NewRequest("GET", apiURL, nil) 192 | if err != nil { 193 | return nil, err 194 | } 195 | 196 | var oneDriveResponse *OneDriveDriveItemsResponse 197 | err = s.client.Do(ctx, req, false, &oneDriveResponse) 198 | if err != nil { 199 | return nil, err 200 | } 201 | 202 | return oneDriveResponse, nil 203 | } 204 | 205 | // Get an item in the default drive of the authenticated user. 206 | // 207 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get?view=odsp-graph-online 208 | func (s *DriveItemsService) Get(ctx context.Context, itemId string) (*DriveItem, error) { 209 | if itemId == "" { 210 | return nil, errors.New("Please provide the Item ID of the item.") 211 | } 212 | 213 | apiURL := "me/drive/items/" + url.PathEscape(itemId) 214 | 215 | req, err := s.client.NewRequest("GET", apiURL, nil) 216 | if err != nil { 217 | return nil, err 218 | } 219 | 220 | var driveItem *DriveItem 221 | err = s.client.Do(ctx, req, false, &driveItem) 222 | if err != nil { 223 | return nil, err 224 | } 225 | 226 | return driveItem, nil 227 | } 228 | 229 | // Get an item from special folder in the default drive of the authenticated user. 230 | // 231 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get_specialfolder?view=odsp-graph-online 232 | func (s *DriveItemsService) GetSpecial(ctx context.Context, folderName DriveSpecialFolder) (*DriveItem, error) { 233 | if folderName.toString() == "" { 234 | return nil, errors.New("Please specify which special folder to use.") 235 | } 236 | 237 | apiURL := "me/drive/special/" + url.PathEscape(folderName.toString()) 238 | 239 | req, err := s.client.NewRequest("GET", apiURL, nil) 240 | if err != nil { 241 | return nil, err 242 | } 243 | 244 | var driveItem *DriveItem 245 | err = s.client.Do(ctx, req, false, &driveItem) 246 | if err != nil { 247 | return nil, err 248 | } 249 | 250 | return driveItem, nil 251 | } 252 | 253 | // Create a new folder in a drive of the authenticated user. 254 | // If there is already a folder in the same OneDrive directory with the same name, 255 | // OneDrive will choose a new name for the folder while creating it. 256 | // 257 | // If driveId is empty, it means the selected drive will be the default drive of 258 | // the authenticated user. 259 | // 260 | // If parentFolderName is empty, it means the new folder will be created at 261 | // the root of the default drive. 262 | // 263 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online 264 | func (s *DriveItemsService) CreateNewFolder(ctx context.Context, driveId string, parentFolderName string, folderName string) (*DriveItem, error) { 265 | if folderName == "" { 266 | return nil, errors.New("Please provide the folder name.") 267 | } 268 | 269 | if parentFolderName == "" { 270 | parentFolderName = "root" 271 | } 272 | 273 | apiURL := "me/drive/items/" + url.PathEscape(parentFolderName) + "/children" 274 | if driveId != "" { 275 | apiURL = "me/drives/" + url.PathEscape(driveId) + "/items/" + url.PathEscape(parentFolderName) + "/children" 276 | } 277 | 278 | folderFacet := &Facet{} 279 | 280 | newFolder := &NewFolderCreationRequest{ 281 | FolderName: folderName, 282 | FolderFacet: *folderFacet, 283 | ConflictBehavior: "rename", 284 | } 285 | 286 | req, err := s.client.NewRequest("POST", apiURL, newFolder) 287 | if err != nil { 288 | return nil, err 289 | } 290 | 291 | var driveItem *DriveItem 292 | err = s.client.Do(ctx, req, false, &driveItem) 293 | if err != nil { 294 | return nil, err 295 | } 296 | 297 | return driveItem, nil 298 | } 299 | 300 | // Delete will delete a drive item in a drive of the authenticated user. 301 | // The deleted item will be moved to the Recycle Bin instead of getting permanently deleted. 302 | // 303 | // If driveId is empty, it means the selected drive will be the default drive of 304 | // the authenticated user. 305 | // 306 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delete?view=odsp-graph-online 307 | func (s *DriveItemsService) Delete(ctx context.Context, driveId string, itemId string) error { 308 | if itemId == "" { 309 | return errors.New("Please provide the Item ID of the item to be deleted.") 310 | } 311 | 312 | apiURL := "me/drive/items/" + url.PathEscape(itemId) 313 | if driveId != "" { 314 | apiURL = "me/drives/" + url.PathEscape(driveId) + "/items/" + url.PathEscape(itemId) 315 | } 316 | 317 | _, err := s.client.NewRequest("DELETE", apiURL, nil) 318 | if err != nil { 319 | return err 320 | } 321 | 322 | return nil 323 | } 324 | 325 | // Move a drive item to a new parent folder in a drive of the authenticated user. 326 | // 327 | // When moving an item to the root of a drive, for example, we cannot use "root" 328 | // as the destinationParentFolderId. Instead, we need to provide the actual ID of the root. 329 | // 330 | // If driveId is empty, it means the selected drive will be the default drive of 331 | // the authenticated user. 332 | // 333 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_move?view=odsp-graph-online 334 | func (s *DriveItemsService) Move(ctx context.Context, driveId string, itemId string, destinationParentFolderId string) (*MoveItemResponse, error) { 335 | if itemId == "" { 336 | return nil, errors.New("Please provide the Item ID of the item to be moved.") 337 | } 338 | 339 | if destinationParentFolderId == "" { 340 | return nil, errors.New("Please provide the destination, i.e. the ID of the new parent folder for the item.") 341 | } 342 | 343 | destinationParentFolder := &ParentReference{ 344 | Id: destinationParentFolderId, 345 | } 346 | 347 | targetParentFolder := &MoveItemRequest{ 348 | ParentFolder: *destinationParentFolder, 349 | } 350 | 351 | apiURL := "me/drive/items/" + url.PathEscape(itemId) 352 | if driveId != "" { 353 | apiURL = "me/drives/" + url.PathEscape(driveId) + "/items/" + url.PathEscape(itemId) 354 | } 355 | 356 | req, err := s.client.NewRequest("PATCH", apiURL, targetParentFolder) 357 | if err != nil { 358 | return nil, err 359 | } 360 | 361 | var response *MoveItemResponse 362 | err = s.client.Do(ctx, req, false, &response) 363 | if err != nil { 364 | return nil, err 365 | } 366 | 367 | return response, nil 368 | } 369 | 370 | // Rename a drive item in a drive of the authenticated user. 371 | // 372 | // If driveId is empty, it means the selected drive will be the default drive of 373 | // the authenticated user. 374 | // 375 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_update?view=odsp-graph-online 376 | func (s *DriveItemsService) Rename(ctx context.Context, driveId string, itemId string, newItemName string) (*RenameItemResponse, error) { 377 | if itemId == "" { 378 | return nil, errors.New("Please provide the Item ID of the item to be moved.") 379 | } 380 | 381 | if newItemName == "" { 382 | return nil, errors.New("Please provide a new name for the item.") 383 | } 384 | 385 | newNameRequest := &RenameItemRequest{ 386 | Name: newItemName, 387 | } 388 | 389 | apiURL := "me/drive/items/" + url.PathEscape(itemId) 390 | if driveId != "" { 391 | apiURL = "me/drives/" + url.PathEscape(driveId) + "/items/" + url.PathEscape(itemId) 392 | } 393 | 394 | req, err := s.client.NewRequest("PATCH", apiURL, newNameRequest) 395 | if err != nil { 396 | return nil, err 397 | } 398 | 399 | var response *RenameItemResponse 400 | err = s.client.Do(ctx, req, false, &response) 401 | if err != nil { 402 | return nil, err 403 | } 404 | 405 | return response, nil 406 | } 407 | 408 | // Copy a drive item to a new parent item or with a new name in a drive of the authenticated user. 409 | // 410 | // If sourceDriveId or destinationDriveId is empty, it means the selected drive will be the default drive of 411 | // the authenticated user. 412 | // 413 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_copy?view=odsp-graph-online 414 | func (s *DriveItemsService) Copy(ctx context.Context, sourceDriveId string, itemId string, 415 | destinationDriveId string, destinationFolderId string, newItemName string) (*CopyItemResponse, error) { 416 | if itemId == "" { 417 | return nil, errors.New("Please provide the Item ID of the item to be copied.") 418 | } 419 | 420 | if destinationFolderId == "" { 421 | return nil, errors.New("Please provide the destination, i.e. the ID of the new parent folder for the item.") 422 | } 423 | 424 | if newItemName == "" { 425 | return nil, errors.New("Please provide the name of the new item after the copy is done. OneDrive will reject item name which already exists in destination.") 426 | } 427 | 428 | if destinationDriveId == "" { 429 | reqDefaultDriveInfo, err := s.client.NewRequest("GET", "me/drive", nil) 430 | if err != nil { 431 | return nil, err 432 | } 433 | 434 | var defaultDrive *Drive 435 | err = s.client.Do(ctx, reqDefaultDriveInfo, false, &defaultDrive) 436 | if err != nil { 437 | return nil, err 438 | } 439 | 440 | destinationDriveId = defaultDrive.Id 441 | } 442 | 443 | destinationParentFolder := &ParentReference{ 444 | Id: destinationFolderId, 445 | DriveId: destinationDriveId, 446 | } 447 | 448 | copyItemRequest := &CopyItemRequest{ 449 | ParentFolder: *destinationParentFolder, 450 | Name: newItemName, 451 | } 452 | 453 | apiURL := "me/drive/items/" + url.PathEscape(itemId) + "/copy" 454 | if sourceDriveId != "" { 455 | apiURL = "me/drives/" + url.PathEscape(sourceDriveId) + "/items/" + url.PathEscape(itemId) + "/copy" 456 | } 457 | 458 | req, err := s.client.NewRequest("POST", apiURL, copyItemRequest) 459 | if err != nil { 460 | return nil, err 461 | } 462 | 463 | var response *CopyItemResponse 464 | err = s.client.Do(ctx, req, false, &response) 465 | if err != nil { 466 | return nil, err 467 | } 468 | 469 | return response, nil 470 | } 471 | 472 | // UploadNewFile is to upload a file to a drive of the authenticated user. 473 | // 474 | // By default, this API will upload and then rename an item if there is an existing item 475 | // with the same name on OneDrive. 476 | // 477 | // If driveId is empty, it means the selected drive will be the default drive of 478 | // the authenticated user. 479 | // 480 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online#http-request-to-upload-a-new-file 481 | func (s *DriveItemsService) UploadNewFile(ctx context.Context, driveId string, destinationParentFolderId string, localFilePath string) (*DriveItem, error) { 482 | if destinationParentFolderId == "" { 483 | return nil, errors.New("Please provide the destination, i.e. the ID of the parent folder for this new item.") 484 | } 485 | 486 | if localFilePath == "" { 487 | return nil, errors.New("Please provide the path to the file on local.") 488 | } 489 | 490 | file, err := os.Open(localFilePath) 491 | if err != nil { 492 | return nil, err 493 | } 494 | defer file.Close() 495 | 496 | fileInfo, err := file.Stat() 497 | if err != nil { 498 | return nil, err 499 | } 500 | 501 | if fileInfo.IsDir() { 502 | return nil, errors.New("Only file is allowed to be uploaded here.") 503 | } 504 | 505 | fileSize := fileInfo.Size() 506 | 507 | if fileSize > 4*1024*1024 { 508 | return nil, errors.New("Only file with size less than or equal to 4MB is allowed to be uploaded here.") 509 | } 510 | 511 | fileName := fileInfo.Name() 512 | 513 | apiURL := "me/drive/items/" + url.PathEscape(destinationParentFolderId) + ":/" + url.PathEscape(fileName) + ":/content?@microsoft.graph.conflictBehavior=rename" 514 | if driveId != "" { 515 | apiURL = "me/drives/" + url.PathEscape(driveId) + "/items/" + url.PathEscape(destinationParentFolderId) + ":/" + url.PathEscape(fileName) + ":/content?@microsoft.graph.conflictBehavior=rename" 516 | } 517 | 518 | buffer := make([]byte, fileSize) 519 | file.Read(buffer) 520 | fileReader := bytes.NewReader(buffer) 521 | 522 | fileType, _ := filetype.Match(buffer) 523 | 524 | req, err := s.client.NewFileUploadRequest(apiURL, fileType.MIME.Value, fileReader) 525 | if err != nil { 526 | return nil, err 527 | } 528 | 529 | var response *DriveItem 530 | err = s.client.Do(ctx, req, false, &response) 531 | if err != nil { 532 | return nil, err 533 | } 534 | 535 | return response, nil 536 | } 537 | 538 | // UploadToReplaceFile is to upload a file to replace an existing file in a drive of the authenticated user. 539 | // 540 | // If driveId is empty, it means the selected drive will be the default drive of 541 | // the authenticated user. 542 | // 543 | // OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online#http-request-to-replace-an-existing-item 544 | func (s *DriveItemsService) UploadToReplaceFile(ctx context.Context, driveId string, localFilePath string, itemId string) (*DriveItem, error) { 545 | if localFilePath == "" { 546 | return nil, errors.New("Please provide the path to the file on local.") 547 | } 548 | 549 | if itemId == "" { 550 | return nil, errors.New("Please provide the id of the existing item to replace.") 551 | } 552 | 553 | file, err := os.Open(localFilePath) 554 | if err != nil { 555 | return nil, err 556 | } 557 | defer file.Close() 558 | 559 | fileInfo, err := file.Stat() 560 | if err != nil { 561 | return nil, err 562 | } 563 | 564 | if fileInfo.IsDir() { 565 | return nil, errors.New("Only file is allowed to be uploaded here.") 566 | } 567 | 568 | fileSize := fileInfo.Size() 569 | 570 | if fileSize > 4*1024*1024 { 571 | return nil, errors.New("Only file with size less than or equal to 4MB is allowed to be uploaded here.") 572 | } 573 | 574 | apiURL := "me/drive/items/" + url.PathEscape(itemId) + "/content" 575 | if driveId != "" { 576 | apiURL = "me/drives/" + url.PathEscape(driveId) + "/items/" + url.PathEscape(itemId) + "/content" 577 | } 578 | 579 | buffer := make([]byte, fileSize) 580 | file.Read(buffer) 581 | fileReader := bytes.NewReader(buffer) 582 | 583 | fileType, _ := filetype.Match(buffer) 584 | 585 | targetDriveItem, err := s.Get(ctx, itemId) 586 | if err != nil { 587 | return nil, err 588 | } 589 | 590 | if targetDriveItem.File == nil { 591 | return nil, errors.New("It's prohibited to replace a drive item which is not a file.") 592 | } 593 | 594 | if targetDriveItem.File.MIMEType != fileType.MIME.Value { 595 | 596 | return nil, fmt.Errorf("It's prohibited to replace a file with MIME Type %q which is not the same type as the uploaded file with MEME Type %q.", targetDriveItem.File.MIMEType, fileType.MIME.Value) 597 | } 598 | 599 | req, err := s.client.NewFileUploadRequest(apiURL, fileType.MIME.Value, fileReader) 600 | if err != nil { 601 | return nil, err 602 | } 603 | 604 | var response *DriveItem 605 | err = s.client.Do(ctx, req, false, &response) 606 | if err != nil { 607 | return nil, err 608 | } 609 | 610 | return response, nil 611 | } 612 | 613 | // UploadNewFileLarge is to upload a large file (> 4mb) to a drive of the authenticated user. 614 | // 615 | // This might take a long time, please consider using a new goroutine. 616 | // 617 | // By default, this API will upload and then rename an item if there is an existing item 618 | // with the same name on OneDrive. 619 | // 620 | // If driveId is empty, it means the selected drive will be the default drive of 621 | // the authenticated user. 622 | // 623 | // The recommended splitting size is 5-10 MiB, depending on your internet connection. 624 | // Per Microsoft API, the size per split MUST BE a multiple of 320 KiB (320 * 1024) 625 | // 626 | // OneDrive API docs: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession 627 | func (s *DriveItemsService) UploadNewFileLarge(ctx context.Context, driveId string, destinationParentFolderId string, localFilePath string, sizePerSplit int64) (*DriveItem, error) { 628 | if destinationParentFolderId == "" { 629 | return nil, errors.New("Please provide the destination, i.e. the ID of the parent folder for this new item.") 630 | } 631 | 632 | if localFilePath == "" { 633 | return nil, errors.New("Please provide the path to the file on local.") 634 | } 635 | 636 | file, err := os.Open(localFilePath) 637 | if err != nil { 638 | return nil, err 639 | } 640 | defer file.Close() 641 | 642 | fileInfo, err := file.Stat() 643 | if err != nil { 644 | return nil, err 645 | } 646 | 647 | if fileInfo.IsDir() { 648 | return nil, errors.New("Only file is allowed to be uploaded here.") 649 | } 650 | 651 | fileSize := fileInfo.Size() 652 | 653 | //if size per split is set to zero, we will try to upload the file as a whole 654 | if sizePerSplit == 0 { 655 | if fileSize > 60*1024*1024 { 656 | return nil, errors.New("Only file with size less than or equal to 60MiB is allowed to be uploaded in a single split") 657 | } 658 | } else if sizePerSplit < 0 { 659 | return nil, errors.New("Size per split must be a positive number") 660 | } else if sizePerSplit > 60*1024*1024 { 661 | return nil, errors.New("Size per split must be lesser than 60MiB") 662 | } 663 | 664 | //range should be a multiple of 320 KiB 665 | //see: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online#upload-bytes-to-the-upload-session 666 | if sizePerSplit%(320*1024) != 0 { 667 | return nil, errors.New("Size per split should be a multiple of 320 KiB (327,680 bytes)") 668 | } 669 | 670 | fileName := fileInfo.Name() 671 | 672 | apiURL := fmt.Sprintf("me/drive/items/%s:/%s:/createUploadSession", url.PathEscape(destinationParentFolderId), fileName) 673 | 674 | //Did not find an official API for designated drive, I'll just keep the api in the same format. 675 | if driveId != "" { 676 | apiURL = fmt.Sprintf("me/drives/%s/items/%s:/%s:/createUploadSession", url.PathEscape(driveId), url.PathEscape(destinationParentFolderId), fileName) 677 | } 678 | 679 | sessionCreationRequestInside := NewUploadSessionCreationRequest{ 680 | //select from: rename | fail | replace 681 | ConflictBehavior: "rename", 682 | } 683 | 684 | sessionCreationRequest := struct { 685 | Item NewUploadSessionCreationRequest `json:"item"` 686 | //found a "deferCommit" flag in Graph API, but not in onedrive api. 687 | //docs: https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0 688 | DeferCommit bool `json:"deferCommit"` 689 | }{sessionCreationRequestInside, false} 690 | 691 | sessionCreationReq, err := s.client.NewRequest("POST", apiURL, sessionCreationRequest) 692 | 693 | if err != nil { 694 | return nil, err 695 | } 696 | 697 | var sessionCreationResp *NewUploadSessionCreationResponse 698 | err = s.client.Do(ctx, sessionCreationReq, false, &sessionCreationResp) 699 | if err != nil { 700 | //debug 701 | //b, _ := json.Marshal(sessionCreationRequest) 702 | //fmt.Println("URL:" + sessionCreationReq.URL.String()) 703 | //fmt.Printf("Parameters:\r%v\r\n", string(b)) 704 | return nil, fmt.Errorf("session creation failed %w", err) 705 | } 706 | 707 | fileSessionUploadUrl := sessionCreationResp.UploadURL 708 | 709 | //if sizePerSplit is 0, upload the whole file without splitting it. 710 | 711 | if sizePerSplit == 0 { 712 | sizePerSplit = fileSize 713 | } 714 | 715 | //buffer for storing splitted file 716 | buffer := make([]byte, sizePerSplit) 717 | splitCount := fileSize / sizePerSplit 718 | if fileSize%sizePerSplit != 0 { 719 | splitCount += 1 720 | } 721 | bfReader := bufio.NewReader(file) 722 | var fileUploadResp *UploadSessionUploadResponse 723 | for splitNow := int64(0); splitNow < splitCount; splitNow++ { 724 | length, err := bfReader.Read(buffer) 725 | //should not reach EOF or other type of error. 726 | if err != nil { 727 | return nil, err 728 | } 729 | if int64(length) < sizePerSplit { 730 | bufferLast := buffer[:length] 731 | buffer = bufferLast 732 | } 733 | //construct the request to temporary uploadSession location 734 | sessionFileUploadReq, err := s.client.NewSessionFileUploadRequest(fileSessionUploadUrl, splitNow*sizePerSplit, fileSize, bytes.NewReader(buffer)) 735 | if err != nil { 736 | return nil, err 737 | } 738 | 739 | //execute the PUT query 740 | //UploadSessionUploadResponse is an *compounded* structure that will NOT include a DriveItem struct 741 | //before finalizing the file upload. 742 | err = s.client.Do(ctx, sessionFileUploadReq, false, &fileUploadResp) 743 | if err != nil { 744 | return nil, err 745 | } 746 | } 747 | //something went wrong, it does not return a completed file 748 | if fileUploadResp.Id == "" { 749 | return &fileUploadResp.DriveItem, errors.New("something went wrong. file upload incomplete. consider upload the file in a step-by-step manner") 750 | } 751 | 752 | return &fileUploadResp.DriveItem, nil 753 | } 754 | 755 | // DownloadItem downloads the given item from OneDrive 756 | func (s *DriveItemsService) DownloadItem(ctx context.Context, item *DriveItem) ([]byte, error) { 757 | if item.DownloadURL == "" { 758 | var err error 759 | item, err = s.Get(ctx, item.Id) 760 | if err != nil { 761 | return nil, err 762 | } 763 | } 764 | 765 | resp, err := s.client.client.Get(item.DownloadURL) 766 | if err != nil { 767 | return nil, err 768 | } 769 | defer resp.Body.Close() 770 | 771 | body, err := io.ReadAll(resp.Body) 772 | if err != nil { 773 | return nil, err 774 | } 775 | if resp.StatusCode != 200 { 776 | var errResp ErrorResponse 777 | if err := json.Unmarshal(body, &errResp); err != nil { 778 | return nil, err 779 | } 780 | if errResp.Error == nil { 781 | return nil, fmt.Errorf("%s: %s", resp.Status, string(body)) 782 | } 783 | return nil, errors.New(errResp.Error.Code + ": " + errResp.Error.Message) 784 | } 785 | return body, nil 786 | } 787 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= 5 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= 6 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= 7 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= 8 | cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= 9 | cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= 10 | cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= 11 | cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= 12 | cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= 13 | cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= 14 | cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= 15 | cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= 16 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= 17 | cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= 18 | cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= 19 | cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= 20 | cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= 21 | cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= 22 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= 23 | cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= 24 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= 25 | cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= 26 | cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= 27 | cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= 28 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= 29 | cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= 30 | cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= 31 | cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= 32 | cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= 33 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 34 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 35 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 36 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 37 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 38 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 39 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 40 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 41 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 42 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 43 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 44 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 45 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 46 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 47 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 48 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 49 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 50 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 51 | github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 52 | github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 53 | github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 54 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 55 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 56 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= 57 | github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= 58 | github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= 59 | github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= 60 | github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= 61 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 62 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 63 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 64 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 65 | github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 66 | github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= 67 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 68 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 69 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 70 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 71 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 72 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= 73 | github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= 74 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 75 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 76 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 77 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 78 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 79 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 80 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 81 | github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 82 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 83 | github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k= 84 | github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 85 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 86 | github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= 87 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 88 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 89 | github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 90 | github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 91 | github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 92 | github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 93 | github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= 94 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 95 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 96 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= 97 | github.com/h2non/filetype v1.1.1 h1:xvOwnXKAckvtLWsN398qS9QhlxlnVXBjXBydK2/UFB4= 98 | github.com/h2non/filetype v1.1.1/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= 99 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 100 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 101 | github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= 102 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 103 | github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= 104 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 105 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 106 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 107 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 108 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 109 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 110 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 111 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 112 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 113 | github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 114 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 115 | github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 116 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 117 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 118 | go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 119 | go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 120 | go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 121 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 122 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 123 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 124 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 125 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 126 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 127 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 128 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 129 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= 130 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= 131 | golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 132 | golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 133 | golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= 134 | golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= 135 | golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= 136 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 137 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 138 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 139 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 140 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 141 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 142 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 143 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 144 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 145 | golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= 146 | golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= 147 | golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= 148 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 149 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 150 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 151 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 152 | golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 153 | golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 154 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 155 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 156 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 157 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 158 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 159 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 160 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 161 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 162 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 163 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 164 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 165 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 166 | golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 167 | golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 168 | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 169 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 170 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 171 | golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 172 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 173 | golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 174 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 175 | golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 176 | golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 177 | golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 178 | golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 179 | golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 180 | golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 181 | golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= 182 | golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 183 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 184 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 185 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 186 | golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 187 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 188 | golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84 h1:duBc5zuJsmJXYOVVE/6PxejI+N3AaCqKjtsoLn1Je5Q= 189 | golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= 190 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 191 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 192 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 193 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 194 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 195 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 196 | golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 197 | golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 198 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 199 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 200 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 201 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 202 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 203 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 204 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 205 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 206 | golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 207 | golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 208 | golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 209 | golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 210 | golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 211 | golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 212 | golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 213 | golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 214 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 215 | golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 216 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 217 | golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 218 | golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 219 | golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 220 | golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 221 | golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 222 | golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 223 | golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 224 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 225 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 226 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 227 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 228 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 229 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 230 | golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 231 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 232 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 233 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 234 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 235 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 236 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 237 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 238 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 239 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 240 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 241 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 242 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 243 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 244 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 245 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 246 | golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 247 | golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 248 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 249 | golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 250 | golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 251 | golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 252 | golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 253 | golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 254 | golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 255 | golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 256 | golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 257 | golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 258 | golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 259 | golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 260 | golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 261 | golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= 262 | golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= 263 | golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= 264 | golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 265 | golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 266 | golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 267 | golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 268 | golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= 269 | golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= 270 | golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= 271 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 272 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 273 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 274 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 275 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 276 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 277 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= 278 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 279 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 280 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 281 | google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 282 | google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 283 | google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 284 | google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 285 | google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 286 | google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 287 | google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= 288 | google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= 289 | google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= 290 | google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= 291 | google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= 292 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 293 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 294 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 295 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 296 | google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 297 | google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc= 298 | google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 299 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 300 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 301 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 302 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 303 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 304 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 305 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 306 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= 307 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 308 | google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 309 | google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 310 | google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 311 | google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 312 | google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 313 | google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= 314 | google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 315 | google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 316 | google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 317 | google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 318 | google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 319 | google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 320 | google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 321 | google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 322 | google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= 323 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= 324 | google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= 325 | google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= 326 | google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= 327 | google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= 328 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 329 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 330 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 331 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 332 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 333 | google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 334 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 335 | google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 336 | google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= 337 | google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= 338 | google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= 339 | google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= 340 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 341 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 342 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 343 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 344 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 345 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 346 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 347 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 348 | google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= 349 | google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= 350 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= 351 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 352 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 353 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 354 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 355 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 356 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 357 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 358 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 359 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 360 | honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= 361 | honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= 362 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 363 | rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= 364 | rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= 365 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------