├── _VERSION ├── auto ├── client.go └── client_test.go ├── image ├── client.go └── client_test.go ├── action ├── client.go └── client_test.go ├── app ├── client_test.go └── client.go ├── errors ├── client.go └── client_test.go ├── group └── client_test.go ├── lock └── client_test.go ├── preview ├── client.go └── client_test.go ├── site ├── client_test.go └── client.go ├── status ├── client.go └── client_test.go ├── style ├── client_test.go └── client.go ├── sync └── client_test.go ├── apikey └── client_test.go ├── bundle └── client_test.go ├── formfield ├── client.go └── client_test.go ├── gpgkey └── client_test.go ├── history └── client_test.go ├── invoice ├── client_test.go └── client.go ├── message └── client_test.go ├── partner └── client_test.go ├── payment ├── client_test.go └── client.go ├── project └── client_test.go ├── request └── client_test.go ├── restore ├── client_test.go └── client.go ├── scimlog ├── client_test.go └── client.go ├── synclog ├── client_test.go └── client.go ├── syncrun ├── client_test.go └── client.go ├── automation └── client_test.go ├── behavior └── client_test.go ├── bundlepath ├── client.go └── client_test.go ├── clickwrap └── client_test.go ├── dnsrecord ├── client_test.go └── client.go ├── emaillog ├── client_test.go └── client.go ├── fileaction ├── client.go └── client_test.go ├── groupuser └── client_test.go ├── ipaddress └── client_test.go ├── permission └── client_test.go ├── priority ├── client_test.go └── client.go ├── publickey └── client_test.go ├── snapshot └── client_test.go ├── as2partner └── client_test.go ├── as2station └── client_test.go ├── bundleaction ├── client_test.go └── client.go ├── filecomment └── client_test.go ├── fileuploadpart ├── client.go └── client_test.go ├── inboxupload ├── client_test.go └── client.go ├── notification └── client_test.go ├── remoteserver └── client_test.go ├── sftphostkey └── client_test.go ├── sharegroup └── client_test.go ├── ssostrategy └── client_test.go ├── userrequest └── client_test.go ├── webhooktest ├── client_test.go └── client.go ├── accountlineitem ├── client.go └── client_test.go ├── apirequestlog ├── client_test.go └── client.go ├── automationlog ├── client_test.go └── client.go ├── automationrun ├── client_test.go └── client.go ├── bundledownload ├── client_test.go └── client.go ├── externalevent └── client_test.go ├── formfieldset └── client_test.go ├── ftpactionlog ├── client_test.go └── client.go ├── historyexport ├── client_test.go └── client.go ├── holidayregion ├── client_test.go └── client.go ├── inbounds3log ├── client_test.go └── client.go ├── inboxrecipient ├── client_test.go └── client.go ├── invoicelineitem ├── client.go └── client_test.go ├── messagecomment └── client_test.go ├── paymentlineitem ├── client.go └── client_test.go ├── publicipaddress ├── client.go └── client_test.go ├── settingschange ├── client_test.go └── client.go ├── sftpactionlog ├── client_test.go └── client.go ├── sharegroupmember ├── client.go └── client_test.go ├── usagesnapshot ├── client_test.go └── client.go ├── usercipheruse ├── client_test.go └── client.go ├── bandwidthsnapshot ├── client_test.go └── client.go ├── bundlerecipient ├── client_test.go └── client.go ├── filemigrationlog ├── client_test.go └── client.go ├── inboxregistration ├── client_test.go └── client.go ├── messagereaction └── client_test.go ├── usagebytopleveldir ├── client.go └── client_test.go ├── webdavactionlog ├── client_test.go └── client.go ├── as2incomingmessage ├── client_test.go └── client.go ├── as2outgoingmessage ├── client_test.go └── client.go ├── bundlenotification └── client_test.go ├── bundleregistration ├── client_test.go └── client.go ├── filecommentreaction ├── client_test.go └── client.go ├── historyexportresult ├── client_test.go └── client.go ├── remotemountbackend └── client_test.go ├── siemhttpdestination └── client_test.go ├── usagedailysnapshot ├── client_test.go └── client.go ├── userlifecyclerule └── client_test.go ├── usersftpclientuse ├── client_test.go └── client.go ├── emailincomingmessage ├── client_test.go └── client.go ├── exavaultapirequestlog ├── client_test.go └── client.go ├── outboundconnectionlog ├── client_test.go └── client.go ├── actionnotificationexport ├── client_test.go └── client.go ├── messagecommentreaction └── client_test.go ├── publichostingrequestlog ├── client_test.go └── client.go ├── remotebandwidthsnapshot ├── client_test.go └── client.go ├── childsitemanagementpolicy └── client_test.go ├── lib ├── isdir.go ├── string.go ├── default-string.go ├── anyerror.go ├── direction │ └── main.go ├── pointers.go ├── map.go ├── logpath │ └── log.go ├── signal.go ├── keyvalue │ └── keyvalue.go ├── partsize_test.go ├── expandtilde.go ├── atomicvalue.go ├── required_test.go ├── urljoinnoexcape.go ├── progresswriter.go ├── keyedmutex.go ├── copyat.go ├── concurrencymanager.go ├── s3-error.go ├── pathspec_test.go ├── normalizeforcomparison_test.go ├── errorwithoriginalresponse.go ├── queue.go ├── iterchan.go ├── test │ └── createconfig.go ├── partsize.go ├── readerctx.go ├── connection-stats.go ├── required.go ├── path.go ├── normalizeforcomparison.go ├── logger.go └── params_test.go ├── remoteserverconfigurationfile ├── client.go └── client_test.go ├── .gitignore ├── actionnotificationexportresult ├── client_test.go └── client.go ├── file ├── status │ ├── log.go │ └── change.go ├── tmpdownloadpath_nondarwin.go ├── file_test.go ├── jobparams.go ├── tmpdownloadpath_darwin.go ├── fixtures │ ├── TestClient_ListForRecursive_Error.yaml │ ├── TestClient_ListForRecursive_Root.yaml │ └── TestClient_DownloadToFile_No_files.yaml ├── downloaduri.go ├── file.go ├── tmpdownloadpath.go ├── remotefs_test.go ├── tmpdownloadpath_nondarwin_test.go ├── tmpdownloadpath_darwin_test.go └── download.go ├── Dockerfile ├── directory └── main.go ├── fsmount ├── internal │ ├── shell │ │ └── notify.go │ ├── log │ │ └── log.go │ ├── sync │ │ ├── pool.go │ │ └── path.go │ └── cache │ │ ├── stats.go │ │ ├── mem │ │ └── mem_opt.go │ │ ├── disk │ │ └── disk_opt.go │ │ └── ready.go ├── debug_off.go ├── fsmount_windows_test.go ├── templates │ └── debug.tmpl ├── fsmount_linux.go ├── events │ └── events.go └── localfs_linux.go ├── ignore └── data │ ├── common.gitignore │ ├── Windows.gitignore │ ├── Linux.gitignore │ └── macOS.gitignore ├── CONTRIBUTORS ├── user_test.go ├── direntry.go ├── shared ├── header_test_data.json └── url_test_data.json ├── session ├── client_test.go ├── fixtures │ └── Delete.yaml └── client.go ├── SECURITY.md ├── environment.go ├── auto.go ├── LICENSE ├── image.go ├── listquery └── build.go ├── errors.go ├── bundlepath.go ├── fileaction.go ├── holidayregion.go ├── priority.go ├── sharegroupmember.go ├── usagebytopleveldir.go ├── folder ├── client_test.go └── client.go ├── dnsrecord.go ├── preview.go ├── paymentlineitem.go ├── publicipaddress.go ├── ipaddress.go ├── status.go ├── filemigration ├── fixtures │ └── TestClient_Wait.yaml └── client.go ├── project.go ├── style.go ├── usersftpclientuse.go ├── user └── fixtures │ └── TestClient_Create.yaml ├── formfield.go └── filecommentreaction.go /_VERSION: -------------------------------------------------------------------------------- 1 | 3.3.16 2 | -------------------------------------------------------------------------------- /auto/client.go: -------------------------------------------------------------------------------- 1 | package auto 2 | -------------------------------------------------------------------------------- /image/client.go: -------------------------------------------------------------------------------- 1 | package image 2 | -------------------------------------------------------------------------------- /action/client.go: -------------------------------------------------------------------------------- 1 | package action 2 | -------------------------------------------------------------------------------- /app/client_test.go: -------------------------------------------------------------------------------- 1 | package app 2 | -------------------------------------------------------------------------------- /auto/client_test.go: -------------------------------------------------------------------------------- 1 | package auto 2 | -------------------------------------------------------------------------------- /errors/client.go: -------------------------------------------------------------------------------- 1 | package errors 2 | -------------------------------------------------------------------------------- /group/client_test.go: -------------------------------------------------------------------------------- 1 | package group 2 | -------------------------------------------------------------------------------- /image/client_test.go: -------------------------------------------------------------------------------- 1 | package image 2 | -------------------------------------------------------------------------------- /lock/client_test.go: -------------------------------------------------------------------------------- 1 | package lock 2 | -------------------------------------------------------------------------------- /preview/client.go: -------------------------------------------------------------------------------- 1 | package preview 2 | -------------------------------------------------------------------------------- /site/client_test.go: -------------------------------------------------------------------------------- 1 | package site 2 | -------------------------------------------------------------------------------- /status/client.go: -------------------------------------------------------------------------------- 1 | package status 2 | -------------------------------------------------------------------------------- /style/client_test.go: -------------------------------------------------------------------------------- 1 | package style 2 | -------------------------------------------------------------------------------- /sync/client_test.go: -------------------------------------------------------------------------------- 1 | package sync 2 | -------------------------------------------------------------------------------- /action/client_test.go: -------------------------------------------------------------------------------- 1 | package action 2 | -------------------------------------------------------------------------------- /apikey/client_test.go: -------------------------------------------------------------------------------- 1 | package api_key 2 | -------------------------------------------------------------------------------- /bundle/client_test.go: -------------------------------------------------------------------------------- 1 | package bundle 2 | -------------------------------------------------------------------------------- /errors/client_test.go: -------------------------------------------------------------------------------- 1 | package errors 2 | -------------------------------------------------------------------------------- /formfield/client.go: -------------------------------------------------------------------------------- 1 | package form_field 2 | -------------------------------------------------------------------------------- /gpgkey/client_test.go: -------------------------------------------------------------------------------- 1 | package gpg_key 2 | -------------------------------------------------------------------------------- /history/client_test.go: -------------------------------------------------------------------------------- 1 | package history 2 | -------------------------------------------------------------------------------- /invoice/client_test.go: -------------------------------------------------------------------------------- 1 | package invoice 2 | -------------------------------------------------------------------------------- /message/client_test.go: -------------------------------------------------------------------------------- 1 | package message 2 | -------------------------------------------------------------------------------- /partner/client_test.go: -------------------------------------------------------------------------------- 1 | package partner 2 | -------------------------------------------------------------------------------- /payment/client_test.go: -------------------------------------------------------------------------------- 1 | package payment 2 | -------------------------------------------------------------------------------- /preview/client_test.go: -------------------------------------------------------------------------------- 1 | package preview 2 | -------------------------------------------------------------------------------- /project/client_test.go: -------------------------------------------------------------------------------- 1 | package project 2 | -------------------------------------------------------------------------------- /request/client_test.go: -------------------------------------------------------------------------------- 1 | package request 2 | -------------------------------------------------------------------------------- /restore/client_test.go: -------------------------------------------------------------------------------- 1 | package restore 2 | -------------------------------------------------------------------------------- /scimlog/client_test.go: -------------------------------------------------------------------------------- 1 | package scim_log 2 | -------------------------------------------------------------------------------- /status/client_test.go: -------------------------------------------------------------------------------- 1 | package status 2 | -------------------------------------------------------------------------------- /synclog/client_test.go: -------------------------------------------------------------------------------- 1 | package sync_log 2 | -------------------------------------------------------------------------------- /syncrun/client_test.go: -------------------------------------------------------------------------------- 1 | package sync_run 2 | -------------------------------------------------------------------------------- /automation/client_test.go: -------------------------------------------------------------------------------- 1 | package automation 2 | -------------------------------------------------------------------------------- /behavior/client_test.go: -------------------------------------------------------------------------------- 1 | package behavior 2 | -------------------------------------------------------------------------------- /bundlepath/client.go: -------------------------------------------------------------------------------- 1 | package bundle_path 2 | -------------------------------------------------------------------------------- /clickwrap/client_test.go: -------------------------------------------------------------------------------- 1 | package clickwrap 2 | -------------------------------------------------------------------------------- /dnsrecord/client_test.go: -------------------------------------------------------------------------------- 1 | package dns_record 2 | -------------------------------------------------------------------------------- /emaillog/client_test.go: -------------------------------------------------------------------------------- 1 | package email_log 2 | -------------------------------------------------------------------------------- /fileaction/client.go: -------------------------------------------------------------------------------- 1 | package file_action 2 | -------------------------------------------------------------------------------- /formfield/client_test.go: -------------------------------------------------------------------------------- 1 | package form_field 2 | -------------------------------------------------------------------------------- /groupuser/client_test.go: -------------------------------------------------------------------------------- 1 | package group_user 2 | -------------------------------------------------------------------------------- /ipaddress/client_test.go: -------------------------------------------------------------------------------- 1 | package ip_address 2 | -------------------------------------------------------------------------------- /permission/client_test.go: -------------------------------------------------------------------------------- 1 | package permission 2 | -------------------------------------------------------------------------------- /priority/client_test.go: -------------------------------------------------------------------------------- 1 | package priority 2 | -------------------------------------------------------------------------------- /publickey/client_test.go: -------------------------------------------------------------------------------- 1 | package public_key 2 | -------------------------------------------------------------------------------- /snapshot/client_test.go: -------------------------------------------------------------------------------- 1 | package snapshot 2 | -------------------------------------------------------------------------------- /as2partner/client_test.go: -------------------------------------------------------------------------------- 1 | package as2_partner 2 | -------------------------------------------------------------------------------- /as2station/client_test.go: -------------------------------------------------------------------------------- 1 | package as2_station 2 | -------------------------------------------------------------------------------- /bundleaction/client_test.go: -------------------------------------------------------------------------------- 1 | package bundle_action 2 | -------------------------------------------------------------------------------- /bundlepath/client_test.go: -------------------------------------------------------------------------------- 1 | package bundle_path 2 | -------------------------------------------------------------------------------- /fileaction/client_test.go: -------------------------------------------------------------------------------- 1 | package file_action 2 | -------------------------------------------------------------------------------- /filecomment/client_test.go: -------------------------------------------------------------------------------- 1 | package file_comment 2 | -------------------------------------------------------------------------------- /fileuploadpart/client.go: -------------------------------------------------------------------------------- 1 | package file_upload_part 2 | -------------------------------------------------------------------------------- /inboxupload/client_test.go: -------------------------------------------------------------------------------- 1 | package inbox_upload 2 | -------------------------------------------------------------------------------- /notification/client_test.go: -------------------------------------------------------------------------------- 1 | package notification 2 | -------------------------------------------------------------------------------- /remoteserver/client_test.go: -------------------------------------------------------------------------------- 1 | package remote_server 2 | -------------------------------------------------------------------------------- /sftphostkey/client_test.go: -------------------------------------------------------------------------------- 1 | package sftp_host_key 2 | -------------------------------------------------------------------------------- /sharegroup/client_test.go: -------------------------------------------------------------------------------- 1 | package share_group 2 | -------------------------------------------------------------------------------- /ssostrategy/client_test.go: -------------------------------------------------------------------------------- 1 | package sso_strategy 2 | -------------------------------------------------------------------------------- /userrequest/client_test.go: -------------------------------------------------------------------------------- 1 | package user_request 2 | -------------------------------------------------------------------------------- /webhooktest/client_test.go: -------------------------------------------------------------------------------- 1 | package webhooktest 2 | -------------------------------------------------------------------------------- /accountlineitem/client.go: -------------------------------------------------------------------------------- 1 | package account_line_item 2 | -------------------------------------------------------------------------------- /apirequestlog/client_test.go: -------------------------------------------------------------------------------- 1 | package api_request_log 2 | -------------------------------------------------------------------------------- /automationlog/client_test.go: -------------------------------------------------------------------------------- 1 | package automation_log 2 | -------------------------------------------------------------------------------- /automationrun/client_test.go: -------------------------------------------------------------------------------- 1 | package automation_run 2 | -------------------------------------------------------------------------------- /bundledownload/client_test.go: -------------------------------------------------------------------------------- 1 | package bundle_download 2 | -------------------------------------------------------------------------------- /externalevent/client_test.go: -------------------------------------------------------------------------------- 1 | package external_event 2 | -------------------------------------------------------------------------------- /fileuploadpart/client_test.go: -------------------------------------------------------------------------------- 1 | package file_upload_part 2 | -------------------------------------------------------------------------------- /formfieldset/client_test.go: -------------------------------------------------------------------------------- 1 | package form_field_set 2 | -------------------------------------------------------------------------------- /ftpactionlog/client_test.go: -------------------------------------------------------------------------------- 1 | package ftp_action_log 2 | -------------------------------------------------------------------------------- /historyexport/client_test.go: -------------------------------------------------------------------------------- 1 | package history_export 2 | -------------------------------------------------------------------------------- /holidayregion/client_test.go: -------------------------------------------------------------------------------- 1 | package holiday_region 2 | -------------------------------------------------------------------------------- /inbounds3log/client_test.go: -------------------------------------------------------------------------------- 1 | package inbound_s3_log 2 | -------------------------------------------------------------------------------- /inboxrecipient/client_test.go: -------------------------------------------------------------------------------- 1 | package inbox_recipient 2 | -------------------------------------------------------------------------------- /invoicelineitem/client.go: -------------------------------------------------------------------------------- 1 | package invoice_line_item 2 | -------------------------------------------------------------------------------- /messagecomment/client_test.go: -------------------------------------------------------------------------------- 1 | package message_comment 2 | -------------------------------------------------------------------------------- /paymentlineitem/client.go: -------------------------------------------------------------------------------- 1 | package payment_line_item 2 | -------------------------------------------------------------------------------- /publicipaddress/client.go: -------------------------------------------------------------------------------- 1 | package public_ip_address 2 | -------------------------------------------------------------------------------- /settingschange/client_test.go: -------------------------------------------------------------------------------- 1 | package settings_change 2 | -------------------------------------------------------------------------------- /sftpactionlog/client_test.go: -------------------------------------------------------------------------------- 1 | package sftp_action_log 2 | -------------------------------------------------------------------------------- /sharegroupmember/client.go: -------------------------------------------------------------------------------- 1 | package share_group_member 2 | -------------------------------------------------------------------------------- /usagesnapshot/client_test.go: -------------------------------------------------------------------------------- 1 | package usage_snapshot 2 | -------------------------------------------------------------------------------- /usercipheruse/client_test.go: -------------------------------------------------------------------------------- 1 | package user_cipher_use 2 | -------------------------------------------------------------------------------- /accountlineitem/client_test.go: -------------------------------------------------------------------------------- 1 | package account_line_item 2 | -------------------------------------------------------------------------------- /bandwidthsnapshot/client_test.go: -------------------------------------------------------------------------------- 1 | package bandwidth_snapshot 2 | -------------------------------------------------------------------------------- /bundlerecipient/client_test.go: -------------------------------------------------------------------------------- 1 | package bundle_recipient 2 | -------------------------------------------------------------------------------- /filemigrationlog/client_test.go: -------------------------------------------------------------------------------- 1 | package file_migration_log 2 | -------------------------------------------------------------------------------- /inboxregistration/client_test.go: -------------------------------------------------------------------------------- 1 | package inbox_registration 2 | -------------------------------------------------------------------------------- /invoicelineitem/client_test.go: -------------------------------------------------------------------------------- 1 | package invoice_line_item 2 | -------------------------------------------------------------------------------- /messagereaction/client_test.go: -------------------------------------------------------------------------------- 1 | package message_reaction 2 | -------------------------------------------------------------------------------- /paymentlineitem/client_test.go: -------------------------------------------------------------------------------- 1 | package payment_line_item 2 | -------------------------------------------------------------------------------- /publicipaddress/client_test.go: -------------------------------------------------------------------------------- 1 | package public_ip_address 2 | -------------------------------------------------------------------------------- /sharegroupmember/client_test.go: -------------------------------------------------------------------------------- 1 | package share_group_member 2 | -------------------------------------------------------------------------------- /usagebytopleveldir/client.go: -------------------------------------------------------------------------------- 1 | package usage_by_top_level_dir 2 | -------------------------------------------------------------------------------- /webdavactionlog/client_test.go: -------------------------------------------------------------------------------- 1 | package web_dav_action_log 2 | -------------------------------------------------------------------------------- /as2incomingmessage/client_test.go: -------------------------------------------------------------------------------- 1 | package as2_incoming_message 2 | -------------------------------------------------------------------------------- /as2outgoingmessage/client_test.go: -------------------------------------------------------------------------------- 1 | package as2_outgoing_message 2 | -------------------------------------------------------------------------------- /bundlenotification/client_test.go: -------------------------------------------------------------------------------- 1 | package bundle_notification 2 | -------------------------------------------------------------------------------- /bundleregistration/client_test.go: -------------------------------------------------------------------------------- 1 | package bundle_registration 2 | -------------------------------------------------------------------------------- /filecommentreaction/client_test.go: -------------------------------------------------------------------------------- 1 | package file_comment_reaction 2 | -------------------------------------------------------------------------------- /historyexportresult/client_test.go: -------------------------------------------------------------------------------- 1 | package history_export_result 2 | -------------------------------------------------------------------------------- /remotemountbackend/client_test.go: -------------------------------------------------------------------------------- 1 | package remote_mount_backend 2 | -------------------------------------------------------------------------------- /siemhttpdestination/client_test.go: -------------------------------------------------------------------------------- 1 | package siem_http_destination 2 | -------------------------------------------------------------------------------- /usagebytopleveldir/client_test.go: -------------------------------------------------------------------------------- 1 | package usage_by_top_level_dir 2 | -------------------------------------------------------------------------------- /usagedailysnapshot/client_test.go: -------------------------------------------------------------------------------- 1 | package usage_daily_snapshot 2 | -------------------------------------------------------------------------------- /userlifecyclerule/client_test.go: -------------------------------------------------------------------------------- 1 | package user_lifecycle_rule 2 | -------------------------------------------------------------------------------- /usersftpclientuse/client_test.go: -------------------------------------------------------------------------------- 1 | package user_sftp_client_use 2 | -------------------------------------------------------------------------------- /emailincomingmessage/client_test.go: -------------------------------------------------------------------------------- 1 | package email_incoming_message 2 | -------------------------------------------------------------------------------- /exavaultapirequestlog/client_test.go: -------------------------------------------------------------------------------- 1 | package exavault_api_request_log 2 | -------------------------------------------------------------------------------- /outboundconnectionlog/client_test.go: -------------------------------------------------------------------------------- 1 | package outbound_connection_log 2 | -------------------------------------------------------------------------------- /actionnotificationexport/client_test.go: -------------------------------------------------------------------------------- 1 | package action_notification_export 2 | -------------------------------------------------------------------------------- /messagecommentreaction/client_test.go: -------------------------------------------------------------------------------- 1 | package message_comment_reaction 2 | -------------------------------------------------------------------------------- /publichostingrequestlog/client_test.go: -------------------------------------------------------------------------------- 1 | package public_hosting_request_log 2 | -------------------------------------------------------------------------------- /remotebandwidthsnapshot/client_test.go: -------------------------------------------------------------------------------- 1 | package remote_bandwidth_snapshot 2 | -------------------------------------------------------------------------------- /childsitemanagementpolicy/client_test.go: -------------------------------------------------------------------------------- 1 | package child_site_management_policy 2 | -------------------------------------------------------------------------------- /lib/isdir.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | type IsDir interface { 4 | IsDir() bool 5 | } 6 | -------------------------------------------------------------------------------- /remoteserverconfigurationfile/client.go: -------------------------------------------------------------------------------- 1 | package remote_server_configuration_file 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | go.work 2 | go.work.sum 3 | test.sh 4 | setup.sh 5 | build.sh 6 | release.sh 7 | -------------------------------------------------------------------------------- /actionnotificationexportresult/client_test.go: -------------------------------------------------------------------------------- 1 | package action_notification_export_result 2 | -------------------------------------------------------------------------------- /remoteserverconfigurationfile/client_test.go: -------------------------------------------------------------------------------- 1 | package remote_server_configuration_file 2 | -------------------------------------------------------------------------------- /lib/string.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | func String(string string) *string { 4 | return &string 5 | } 6 | -------------------------------------------------------------------------------- /file/status/log.go: -------------------------------------------------------------------------------- 1 | package status 2 | 3 | type Log struct { 4 | Path string 5 | Action string 6 | } 7 | -------------------------------------------------------------------------------- /lib/default-string.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | func DefaultString(a, b string) string { 4 | if a != "" { 5 | return a 6 | } 7 | return b 8 | } 9 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.17.3 2 | 3 | COPY go.mod go.sum /app/ 4 | WORKDIR /app 5 | 6 | ENV CGO_ENABLED=0 7 | ENV GOPATH=/go 8 | 9 | RUN go mod download 10 | 11 | 12 | -------------------------------------------------------------------------------- /directory/main.go: -------------------------------------------------------------------------------- 1 | package directory 2 | 3 | type Type string 4 | 5 | var ( 6 | Dir = Type("directory") 7 | File = Type("file") 8 | Files = Type("files") 9 | ) 10 | -------------------------------------------------------------------------------- /fsmount/internal/shell/notify.go: -------------------------------------------------------------------------------- 1 | //go:build !windows 2 | 3 | package shell 4 | 5 | // NotifyUpdatedDir is a no-op on non-Windows platforms. 6 | func NotifyUpdatedDir(path string) error { 7 | return nil 8 | } 9 | -------------------------------------------------------------------------------- /lib/anyerror.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | func AnyError(callback func(error), functions ...func() error) { 4 | for _, f := range functions { 5 | err := f() 6 | if err != nil { 7 | callback(err) 8 | return 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ignore/data/common.gitignore: -------------------------------------------------------------------------------- 1 | # These are unfinished download generated by the downloader 2 | *.download 3 | 4 | # Browser-generated download files in progress 5 | *.crdownload 6 | *.part 7 | 8 | # Common temporary and lock files 9 | *~$ 10 | *~.* 11 | ._~$* 12 | *.swap 13 | *.swp 14 | *.lck 15 | *.idlk 16 | DBTmp* 17 | -------------------------------------------------------------------------------- /lib/direction/main.go: -------------------------------------------------------------------------------- 1 | package direction 2 | 3 | type Direction struct { 4 | name string 5 | Symbol string 6 | } 7 | 8 | var ( 9 | DownloadType = Direction{name: "download", Symbol: "⬆"} 10 | UploadType = Direction{name: "upload", Symbol: "⬆"} 11 | ) 12 | 13 | func (t *Direction) Name() string { 14 | return t.name 15 | } 16 | -------------------------------------------------------------------------------- /fsmount/debug_off.go: -------------------------------------------------------------------------------- 1 | //go:build !filescomfs_debug 2 | // +build !filescomfs_debug 3 | 4 | package fsmount 5 | 6 | func (fs *mountRegistry) startPprof() { 7 | // no-op if not built with the filescomfs_debug build tag 8 | } 9 | 10 | func (reg *mountRegistry) stopPprof() { 11 | // no-op if not built with the filescomfs_debug build tag 12 | } 13 | -------------------------------------------------------------------------------- /file/status/change.go: -------------------------------------------------------------------------------- 1 | package status 2 | 3 | import "time" 4 | 5 | type Change struct { 6 | Status 7 | time.Time 8 | Err error 9 | } 10 | 11 | type Changes []Change 12 | 13 | func (c Changes) Count(s Status) (count int) { 14 | for _, change := range c { 15 | if change.Is(s) { 16 | count += 1 17 | } 18 | } 19 | 20 | return count 21 | } 22 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Daniel Cowgill 2 | Dustin Zeisler 3 | Jesse Harris 4 | Kevin Bombino 5 | Kevin Killingsworth 6 | Martyn Garcia 7 | Rommel Santor 8 | Sam Harrison 9 | -------------------------------------------------------------------------------- /ignore/data/Windows.gitignore: -------------------------------------------------------------------------------- 1 | # Windows thumbnail cache files 2 | Thumbs.db 3 | Thumbs.db:encryptable 4 | ehthumbs.db 5 | ehthumbs_vista.db 6 | 7 | # Dump file 8 | *.stackdump 9 | 10 | # Folder config file 11 | [Dd]esktop.ini 12 | 13 | # Recycle Bin used on file shares 14 | $RECYCLE.BIN/ 15 | 16 | # Windows shortcuts 17 | *.lnk 18 | 19 | # Microsoft Office Owner files 20 | ~\$* 21 | -------------------------------------------------------------------------------- /ignore/data/Linux.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | 3 | # temporary files which can be created if a process still has a handle open of a deleted file 4 | .fuse_hidden* 5 | 6 | # KDE directory preferences 7 | .directory 8 | 9 | # Linux trash folder which might appear on any partition or disk 10 | .Trash-* 11 | 12 | # .nfs files are created when an open file is removed but is still being accessed 13 | .nfs* 14 | -------------------------------------------------------------------------------- /lib/pointers.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "time" 4 | 5 | func Bool(bool bool) *bool { 6 | return &bool 7 | } 8 | 9 | func UnWrapBool(b *bool) bool { 10 | if b == nil { 11 | return false 12 | } 13 | 14 | return *b 15 | } 16 | 17 | func Time(t time.Time) *time.Time { 18 | return &t 19 | } 20 | 21 | func Int64(i int64) *int64 { 22 | return &i 23 | } 24 | 25 | func Ptr[T any](t T) *T { 26 | return &t 27 | } 28 | -------------------------------------------------------------------------------- /file/tmpdownloadpath_nondarwin.go: -------------------------------------------------------------------------------- 1 | //go:build !darwin 2 | 3 | package file 4 | 5 | import ( 6 | "os" 7 | ) 8 | 9 | func tmpDownloadPathOnNotExist(originalPath, tmpPath string) (string, error) { 10 | return tmpPath, nil 11 | } 12 | 13 | func finalizeTmpDownload(tmpName string, finalPath string) error { 14 | return os.Rename(tmpName, finalPath) 15 | } 16 | 17 | func removeTmpDownload(tmpName string) error { 18 | return os.Remove(tmpName) 19 | } 20 | -------------------------------------------------------------------------------- /lib/map.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "sync" 4 | 5 | type Map[T any] struct { 6 | sync.Map 7 | } 8 | 9 | func (m *Map[T]) Load(key any) (value T, ok bool) { 10 | var v interface{} 11 | v, ok = m.Map.Load(key) 12 | if ok { 13 | return v.(T), ok 14 | } 15 | return 16 | } 17 | 18 | func (m *Map[T]) Store(key any, value T) { 19 | m.Map.Store(key, value) 20 | } 21 | 22 | func (m *Map[T]) Delete(key any) { 23 | m.LoadAndDelete(key) 24 | } 25 | -------------------------------------------------------------------------------- /lib/logpath/log.go: -------------------------------------------------------------------------------- 1 | package logpath 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/Files-com/files-sdk-go/v3/lib/keyvalue" 7 | ) 8 | 9 | func New(path string, args map[string]interface{}) string { 10 | return LogPath{Path: path, Args: args}.String() 11 | } 12 | 13 | type LogPath struct { 14 | Path string 15 | Args map[string]interface{} 16 | } 17 | 18 | func (l LogPath) String() string { 19 | return fmt.Sprintf("%v - %v", l.Path, keyvalue.New(l.Args)) 20 | } 21 | -------------------------------------------------------------------------------- /lib/signal.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | type Signal struct { 4 | C chan bool 5 | } 6 | 7 | func (s *Signal) Init() *Signal { 8 | s.C = make(chan bool) 9 | return s 10 | } 11 | 12 | func (s *Signal) Called() bool { 13 | select { 14 | case <-s.C: 15 | return true 16 | default: 17 | return false 18 | } 19 | } 20 | 21 | func (s *Signal) Call() { 22 | select { 23 | case <-s.C: 24 | default: 25 | close(s.C) 26 | } 27 | } 28 | 29 | func (s *Signal) Clear() { 30 | s.Init() 31 | } 32 | -------------------------------------------------------------------------------- /lib/keyvalue/keyvalue.go: -------------------------------------------------------------------------------- 1 | package keyvalue 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func New(args map[string]interface{}) string { 9 | return KeyValue{Args: args}.String() 10 | } 11 | 12 | type KeyValue struct { 13 | Args map[string]interface{} 14 | } 15 | 16 | func (a KeyValue) String() string { 17 | var argStr []string 18 | for k, v := range a.Args { 19 | argStr = append(argStr, fmt.Sprintf("%v: %v", k, v)) 20 | } 21 | 22 | return strings.Join(argStr, ", ") 23 | } 24 | -------------------------------------------------------------------------------- /lib/partsize_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func Test_PartSize(t *testing.T) { 11 | assert := assert.New(t) 12 | s := PartSizes 13 | testSize := int64(0) 14 | for _, b := range s { 15 | testSize += b 16 | } 17 | 18 | assert.Equal("4.59", fmt.Sprintf("%.2f", float64(testSize)/1024/1024/1024/1024)) 19 | assert.Equal(len(s), 10_000) 20 | assert.LessOrEqual(testSize, int64(1024*1024*1024*1024*5)) 21 | } 22 | -------------------------------------------------------------------------------- /lib/expandtilde.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "strings" 7 | ) 8 | 9 | func ExpandTilde(path string) string { 10 | dirname, err := os.UserHomeDir() 11 | if err == nil { 12 | if path == "~" { 13 | // In case of "~", which won't be caught by the "else if" 14 | path = dirname 15 | } else if strings.HasPrefix(path, "~/") { 16 | // Use strings.HasPrefix so we don't match paths like 17 | // "/something/~/something/" 18 | path = filepath.Join(dirname, path[2:]) 19 | } 20 | } 21 | 22 | return path 23 | } 24 | -------------------------------------------------------------------------------- /file/file_test.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "encoding/json" 5 | "testing" 6 | 7 | files_sdk "github.com/Files-com/files-sdk-go/v3" 8 | "github.com/Files-com/files-sdk-go/v3/file/status" 9 | "github.com/stretchr/testify/assert" 10 | ) 11 | 12 | func TestJobFile_JSONMarshal(t *testing.T) { 13 | assert := assert.New(t) 14 | file := JobFile{ 15 | Status: status.Errored, 16 | Err: MashableError{files_sdk.ResponseError{Title: "error"}}, 17 | } 18 | data, err := json.Marshal(file) 19 | assert.Nil(err) 20 | assert.Contains(string(data), "error") 21 | } 22 | -------------------------------------------------------------------------------- /lib/atomicvalue.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | type AtomicValue[T comparable] struct { 8 | v T 9 | sync.RWMutex 10 | } 11 | 12 | func (av *AtomicValue[T]) Load() T { 13 | av.RLock() 14 | defer av.RUnlock() 15 | return av.v 16 | } 17 | 18 | func (av *AtomicValue[T]) Store(val T) { 19 | av.Lock() 20 | defer av.Unlock() 21 | av.v = val 22 | } 23 | 24 | func (av *AtomicValue[T]) CompareAndUpdate(cmpValue T, updateFunc func() T) { 25 | av.Lock() 26 | defer av.Unlock() 27 | if av.v == cmpValue { 28 | av.v = updateFunc() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /user_test.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestUser_UnmarshalJSON(t *testing.T) { 10 | json := `{"admin_group_ids": [1, 2, 3]}` 11 | 12 | user := User{} 13 | 14 | err := user.UnmarshalJSON([]byte(json)) 15 | assert.NoError(t, err) 16 | assert.Equal(t, []int64{1, 2, 3}, user.AdminGroupIds) 17 | 18 | json = `{"admin_group_ids": []}` 19 | 20 | user = User{} 21 | 22 | err = user.UnmarshalJSON([]byte(json)) 23 | assert.NoError(t, err) 24 | assert.Equal(t, []int64{}, user.AdminGroupIds) 25 | } 26 | -------------------------------------------------------------------------------- /ignore/data/macOS.gitignore: -------------------------------------------------------------------------------- 1 | # General 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | # Thumbnails 10 | ._* 11 | 12 | # Files that might appear in the root of a volume 13 | .DocumentRevisions-V100 14 | .fseventsd 15 | .Spotlight-V100 16 | .TemporaryItems 17 | .Trashes 18 | .VolumeIcon.icns 19 | .com.apple.timemachine.donotpresent 20 | 21 | # Directories potentially created on remote AFP share 22 | .AppleDB 23 | .AppleDesktop 24 | Network Trash Folder 25 | Temporary Items 26 | .apdisk 27 | 28 | # Files marked as "nosync" by cloud storage services like iCloud Drive 29 | .dat.nosync* 30 | -------------------------------------------------------------------------------- /lib/required_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | type A struct { 10 | Name string `url:"name" required:"true"` 11 | Age int `url:"age" required:"false"` 12 | } 13 | 14 | func TestCheckRequired_Valid(t *testing.T) { 15 | assert := assert.New(t) 16 | a := A{Name: "Dustin", Age: 90} 17 | 18 | err := CheckRequired(a) 19 | assert.Equal(err, nil) 20 | } 21 | 22 | func TestCheckRequired_Invalid(t *testing.T) { 23 | assert := assert.New(t) 24 | a := A{Age: 90} 25 | 26 | err := CheckRequired(a) 27 | assert.EqualError(err, "missing required field: A{}.Name") 28 | } 29 | -------------------------------------------------------------------------------- /fsmount/internal/log/log.go: -------------------------------------------------------------------------------- 1 | // Package log provides logging interfaces and implementations for Files.com FUSE mount. 2 | package log 3 | 4 | type Logger interface { 5 | Debug(format string, v ...any) 6 | Error(format string, v ...any) 7 | Info(format string, v ...any) 8 | Trace(format string, v ...any) 9 | Warn(format string, v ...any) 10 | } 11 | 12 | type NoOpLogger struct{} 13 | 14 | func (l *NoOpLogger) Debug(format string, v ...any) {} 15 | func (l *NoOpLogger) Error(format string, v ...any) {} 16 | func (l *NoOpLogger) Info(format string, v ...any) {} 17 | func (l *NoOpLogger) Trace(format string, v ...any) {} 18 | func (l *NoOpLogger) Warn(format string, v ...any) {} 19 | -------------------------------------------------------------------------------- /fsmount/internal/sync/pool.go: -------------------------------------------------------------------------------- 1 | package sync 2 | 3 | import "sync" 4 | 5 | // Pool is a generic wrapper around sync.Pool for type-safe pooling 6 | type Pool[T any] struct { 7 | pool sync.Pool 8 | } 9 | 10 | // NewPool creates a new type-safe pool with the given constructor function 11 | func NewPool[T any](newFn func() T) *Pool[T] { 12 | return &Pool[T]{ 13 | pool: sync.Pool{ 14 | New: func() any { 15 | return newFn() 16 | }, 17 | }, 18 | } 19 | } 20 | 21 | // Get retrieves an item from the pool 22 | func (p *Pool[T]) Get() T { 23 | return p.pool.Get().(T) 24 | } 25 | 26 | // Put returns an item to the pool 27 | func (p *Pool[T]) Put(x T) { 28 | p.pool.Put(x) 29 | } 30 | -------------------------------------------------------------------------------- /fsmount/fsmount_windows_test.go: -------------------------------------------------------------------------------- 1 | package fsmount 2 | 3 | import "testing" 4 | 5 | func TestValidMountPoint(t *testing.T) { 6 | tests := []struct { 7 | mountPoint string 8 | valid bool 9 | }{ 10 | {"", true}, 11 | {"C:", true}, 12 | {"Z:", true}, 13 | {"A:", true}, 14 | {"1:", false}, 15 | {"C", false}, 16 | {"CC:", false}, 17 | {"C::", false}, 18 | {"C:/", false}, 19 | {"C:\\", false}, 20 | {"C:extra", false}, 21 | } 22 | 23 | for _, test := range tests { 24 | err := validateMountPoint(test.mountPoint) 25 | if (err == nil) != test.valid { 26 | t.Errorf("validateMountPoint(%q) = %v; want valid=%v", test.mountPoint, err, test.valid) 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/urljoinnoexcape.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "strings" 4 | 5 | func UrlJoinNoEscape(paths ...string) string { 6 | var newPaths []string 7 | for _, p := range paths { 8 | if p == "" { 9 | continue 10 | } 11 | newPaths = append(newPaths, strings.TrimPrefix(strings.TrimSuffix(p, "/"), "/")) 12 | } 13 | 14 | return strings.Join(newPaths, "/") 15 | } 16 | 17 | func UrlLastSegment(path string) (rest string, lastSegment string) { 18 | segments := strings.Split( 19 | UrlJoinNoEscape(strings.Split(path, "/")...), 20 | "/", 21 | ) 22 | if len(segments) == 0 { 23 | return "", "" 24 | } 25 | return UrlJoinNoEscape(segments[:len(segments)-1]...), segments[len(segments)-1] 26 | } 27 | -------------------------------------------------------------------------------- /lib/progresswriter.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "io" 4 | 5 | type WriterAndAt interface { 6 | io.WriterAt 7 | io.Writer 8 | io.Closer 9 | } 10 | 11 | type ProgressWriter struct { 12 | WriterAndAt 13 | ProgressWatcher func(int64) 14 | } 15 | 16 | func (w ProgressWriter) WriteAt(p []byte, off int64) (n int, err error) { 17 | n, err = w.WriterAndAt.WriteAt(p, off) 18 | 19 | w.ProgressWatcher(int64(n)) 20 | return n, err 21 | } 22 | 23 | func (w ProgressWriter) Write(p []byte) (n int, err error) { 24 | n, err = w.WriterAndAt.Write(p) 25 | 26 | w.ProgressWatcher(int64(n)) 27 | return n, err 28 | } 29 | 30 | func (w ProgressWriter) Close() error { 31 | return w.WriterAndAt.Close() 32 | } 33 | -------------------------------------------------------------------------------- /lib/keyedmutex.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | type KeyedMutex struct { 8 | m *sync.Map 9 | } 10 | 11 | func NewKeyedMutex() KeyedMutex { 12 | m := sync.Map{} 13 | return KeyedMutex{&m} 14 | } 15 | 16 | func (s KeyedMutex) Unlock(key interface{}) { 17 | l, exist := s.m.Load(key) 18 | if !exist { 19 | panic("KeyedMutex: unlock of unlocked mutex") 20 | } 21 | l_ := l.(*sync.Mutex) 22 | s.m.Delete(key) 23 | l_.Unlock() 24 | } 25 | 26 | func (s KeyedMutex) Lock(key interface{}) { 27 | m := sync.Mutex{} 28 | m_, _ := s.m.LoadOrStore(key, &m) 29 | mm := m_.(*sync.Mutex) 30 | mm.Lock() 31 | if mm != &m { 32 | mm.Unlock() 33 | s.Lock(key) 34 | return 35 | } 36 | return 37 | } 38 | -------------------------------------------------------------------------------- /direntry.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "io/fs" 5 | "time" 6 | ) 7 | 8 | type DirEntry struct { 9 | File 10 | } 11 | 12 | func (f DirEntry) Mode() fs.FileMode { 13 | return fs.ModePerm 14 | } 15 | 16 | func (f DirEntry) ModTime() time.Time { 17 | if f.File.Mtime == nil { 18 | return time.Time{} 19 | } 20 | return *f.File.Mtime 21 | } 22 | 23 | func (f DirEntry) Sys() any { 24 | return f.File 25 | } 26 | 27 | func (f DirEntry) Type() fs.FileMode { 28 | return fs.ModePerm 29 | } 30 | 31 | func (f DirEntry) Name() string { 32 | return f.DisplayName 33 | } 34 | 35 | func (f DirEntry) Info() (fs.FileInfo, error) { 36 | return f, nil 37 | } 38 | 39 | func (f DirEntry) Size() int64 { 40 | return f.File.Size 41 | } 42 | -------------------------------------------------------------------------------- /shared/header_test_data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "headers": {}, 4 | "result": null 5 | }, 6 | { 7 | "headers": { 8 | "Retry-After": ["aaaaaa"] 9 | }, 10 | "result": null 11 | }, 12 | { 13 | "headers": { 14 | "Retry-After": ["5"] 15 | }, 16 | "result": 5 17 | }, 18 | { 19 | "headers": { 20 | "Retry-After": ["60"] 21 | }, 22 | "result": null 23 | }, 24 | { 25 | "headers": { 26 | "Retry-After": ["5", "10"] 27 | }, 28 | "result": 5 29 | }, 30 | { 31 | "headers": { 32 | "Retry-After": ["5", "aaaaaa"] 33 | }, 34 | "result": 5 35 | }, 36 | { 37 | "headers": { 38 | "Retry-After": ["%s"] 39 | }, 40 | "result": 8 41 | } 42 | ] -------------------------------------------------------------------------------- /webhooktest/client.go: -------------------------------------------------------------------------------- 1 | package webhooktest 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | ) 7 | 8 | type Client struct { 9 | files_sdk.Config 10 | } 11 | 12 | func (c *Client) Create(params files_sdk.WebhookTestCreateParams, opts ...files_sdk.RequestResponseOption) (webhookTest files_sdk.WebhookTest, err error) { 13 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/webhook_tests", Params: params, Entity: &webhookTest}, opts...) 14 | return 15 | } 16 | 17 | func Create(params files_sdk.WebhookTestCreateParams, opts ...files_sdk.RequestResponseOption) (webhookTest files_sdk.WebhookTest, err error) { 18 | return (&Client{}).Create(params, opts...) 19 | } 20 | -------------------------------------------------------------------------------- /lib/copyat.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | ) 7 | 8 | func CopyAt(dst io.WriterAt, writeOff int64, src io.Reader) (written int64, err error) { 9 | size := int64(32 * 1024) 10 | buf := make([]byte, size) 11 | for { 12 | nr, er := src.Read(buf) 13 | if nr > 0 { 14 | nw, ew := dst.WriteAt(buf[0:nr], writeOff+written) 15 | if nw < 0 || nr < nw { 16 | nw = 0 17 | if ew == nil { 18 | ew = errors.New("invalid write result") 19 | } 20 | } 21 | written += int64(nw) 22 | if ew != nil { 23 | err = ew 24 | break 25 | } 26 | if nr != nw { 27 | err = io.ErrShortWrite 28 | break 29 | } 30 | } 31 | if er != nil { 32 | if er != io.EOF { 33 | err = er 34 | } 35 | break 36 | } 37 | } 38 | 39 | return 40 | } 41 | -------------------------------------------------------------------------------- /fsmount/templates/debug.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Files.com FUSE Debug

4 | 7 | 19 | 20 | -------------------------------------------------------------------------------- /lib/concurrencymanager.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "context" 4 | 5 | type ConcurrencyManager interface { 6 | // Wait until a slot is available for the new goroutine. 7 | Wait() 8 | 9 | // Done Mark a goroutine as finished 10 | Done() 11 | 12 | // WaitAllDone Wait for all goroutines are done 13 | WaitAllDone() 14 | 15 | // RunningCount Returns the number of goroutines which are running 16 | RunningCount() int 17 | 18 | // WaitWithContext Acquires a semaphore to allow a new goroutine to run or returns false if the context is done 19 | WaitWithContext(ctx context.Context) bool 20 | 21 | // WaitForADone Blocks until at least one goroutine has completed. 22 | WaitForADone() bool 23 | } 24 | 25 | type ConcurrencyManagerWithSubWorker interface { 26 | ConcurrencyManager 27 | NewSubWorker() ConcurrencyManager 28 | } 29 | -------------------------------------------------------------------------------- /session/client_test.go: -------------------------------------------------------------------------------- 1 | package session 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/Files-com/files-sdk-go/v3/lib/test" 8 | recorder "github.com/dnaeon/go-vcr/recorder" 9 | "github.com/stretchr/testify/assert" 10 | ) 11 | 12 | func CreateClient(fixture string) (client *Client, r *recorder.Recorder, err error) { 13 | client = &Client{} 14 | client.Config, r, err = test.CreateConfig(fixture) 15 | 16 | return client, r, err 17 | } 18 | 19 | func TestClient_Delete(t *testing.T) { 20 | client, r, err := CreateClient("Delete") 21 | if err != nil { 22 | t.Fatal(err) 23 | } 24 | defer r.Stop() 25 | assert := assert.New(t) 26 | os.Unsetenv("FILES_API_KEY") 27 | client.Config.SessionId = "9f799aff7f518514a0b6b5cfd1047e73dddd5cf5" 28 | err = client.Delete() 29 | assert.Nil(err, "logout returns success") 30 | } 31 | -------------------------------------------------------------------------------- /lib/s3-error.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "encoding/xml" 5 | "errors" 6 | "fmt" 7 | ) 8 | 9 | type S3Error struct { 10 | XMLName xml.Name `xml:"Error"` 11 | Code string `xml:"Code"` 12 | Message string `xml:"Message"` 13 | HostId string `xml:"HostId"` 14 | RequestId string `xml:"RequestId"` 15 | } 16 | 17 | func S3ErrorIsRequestHasExpired(err error) bool { 18 | var s3Error S3Error 19 | return errors.As(err, &s3Error) && s3Error.Message == "Request has expired" 20 | } 21 | 22 | func S3ErrorIsRequestTimeout(err error) bool { 23 | var s3Error S3Error 24 | return errors.As(err, &s3Error) && s3Error.Code == "RequestTimeout" 25 | } 26 | 27 | func (s S3Error) Error() string { 28 | return fmt.Sprintf("%v - %v", s.Code, s.Message) 29 | } 30 | 31 | func (s S3Error) Empty() bool { 32 | return s.Message == "" && s.Code == "" 33 | } 34 | -------------------------------------------------------------------------------- /fsmount/fsmount_linux.go: -------------------------------------------------------------------------------- 1 | //go:build linux 2 | 3 | package fsmount 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | ) 9 | 10 | func mountPoint(mountPoint string, _ bool) (string, error) { 11 | // TODO: build a path to the mount point that is OS specific 12 | // for now, require that the mount point is provided and 13 | // exists. 14 | if mountPoint == "" { 15 | return "", fmt.Errorf("mount point cannot be empty") 16 | } 17 | if _, err := os.Stat(mountPoint); os.IsNotExist(err) { 18 | return "", fmt.Errorf("mount point does not exist: %w", err) 19 | } 20 | return mountPoint, nil 21 | } 22 | 23 | func mountOpts(params MountParams) []string { 24 | opts := defaultMountOpts(params) 25 | return opts 26 | } 27 | 28 | // LibreOffice lock files 29 | // .~lock.*# 30 | func additionalIgnorePatterns() []string { 31 | return []string{ 32 | ".~lock.*#", 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /fsmount/internal/sync/path.go: -------------------------------------------------------------------------------- 1 | package sync 2 | 3 | import "sync" 4 | 5 | // PathMutex provides per-path locking to allow concurrent operations on different paths 6 | type PathMutex struct { 7 | mu sync.Mutex 8 | locks map[string]*sync.Mutex 9 | } 10 | 11 | // NewPathMutex creates a new path mutex 12 | func NewPathMutex() *PathMutex { 13 | return &PathMutex{ 14 | locks: make(map[string]*sync.Mutex), 15 | } 16 | } 17 | 18 | // Lock acquires a lock for the given path 19 | func (pm *PathMutex) Lock(path string) { 20 | pm.mu.Lock() 21 | mu, ok := pm.locks[path] 22 | if !ok { 23 | mu = &sync.Mutex{} 24 | pm.locks[path] = mu 25 | } 26 | pm.mu.Unlock() 27 | mu.Lock() 28 | } 29 | 30 | // Unlock releases the lock for the given path 31 | func (pm *PathMutex) Unlock(path string) { 32 | pm.mu.Lock() 33 | mu, ok := pm.locks[path] 34 | pm.mu.Unlock() 35 | if ok { 36 | mu.Unlock() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/pathspec_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "os/exec" 5 | "sync" 6 | "testing" 7 | ) 8 | 9 | func TestRsync(t *testing.T) { 10 | _, err := exec.LookPath("rsync") 11 | if err != nil { 12 | t.Log(err) 13 | return 14 | } 15 | 16 | destinationFs := ReadWriteFs(LocalFileSystem{}) 17 | sourceFs := ReadWriteFs(LocalFileSystem{}) 18 | 19 | t.Run("rsync", func(t *testing.T) { 20 | mutex := &sync.Mutex{} 21 | for _, tt := range PathSpec(t, sourceFs.PathSeparator(), destinationFs.PathSeparator()) { 22 | t.Run(tt.Name, func(t *testing.T) { 23 | BuildPathSpecTest(t, mutex, tt, sourceFs, destinationFs, func(args PathSpecArgs) Cmd { 24 | if args.PreserveTimes { 25 | return ExeCmd{Cmd: exec.Command("rsync", "-av", "--times", args.Src, args.Dest)} 26 | } 27 | return ExeCmd{Cmd: exec.Command("rsync", "-av", args.Src, args.Dest)} 28 | }) 29 | }) 30 | } 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /session/fixtures/Delete.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 1 3 | interactions: 4 | - request: 5 | body: "" 6 | form: {} 7 | headers: 8 | User-Agent: 9 | - Files.com Go SDK 10 | X-Filesapi-Auth: 11 | - 9f799aff7f518514a0b6b5cfd1047e73dddd5cf5 12 | url: https://app.files.com/api/rest/v1/sessions 13 | method: DELETE 14 | response: 15 | body: '{}' 16 | headers: 17 | Cache-Control: 18 | - no-cache, no-store, max-age=0, must-revalidate 19 | Content-Length: 20 | - "2" 21 | Content-Type: 22 | - application/json 23 | Date: 24 | - Mon, 22 Feb 2021 20:17:07 GMT 25 | Expires: 26 | - Fri, 01 Jan 1990 00:00:00 GMT 27 | Pragma: 28 | - no-cache 29 | Server: 30 | - nginx 31 | X-Request-Id: 32 | - 6f039747-8282-46d6-ac50-93fd35af1b85 33 | status: 204 No Content 34 | code: 204 35 | duration: "" 36 | -------------------------------------------------------------------------------- /file/jobparams.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "io/fs" 5 | 6 | "github.com/Files-com/files-sdk-go/v3/lib/direction" 7 | "github.com/hashicorp/go-retryablehttp" 8 | ) 9 | 10 | func SetJobParams(r *Job, d direction.Direction, params interface{}, logger retryablehttp.Logger, remoteFs fs.FS) { 11 | r.Params = params 12 | r.Direction = d 13 | r.Logger = logger 14 | r.RemoteFs = remoteFs 15 | switch d { 16 | case direction.DownloadType: 17 | p := params.(DownloaderParams) 18 | r.SetManager(p.Manager) 19 | r.SetEventsReporter(p.EventsReporter) 20 | r.RetryPolicy = p.RetryPolicy 21 | r.LocalPath = p.LocalPath 22 | r.RemotePath = p.RemotePath 23 | r.Sync = p.Sync 24 | case direction.UploadType: 25 | p := params.(UploaderParams) 26 | r.SetManager(p.Manager) 27 | r.SetEventsReporter(p.EventsReporter) 28 | r.RetryPolicy = p.RetryPolicy 29 | r.LocalPath = p.LocalPath 30 | r.RemotePath = p.RemotePath 31 | r.Sync = p.Sync 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /file/tmpdownloadpath_darwin.go: -------------------------------------------------------------------------------- 1 | //go:build darwin 2 | 3 | package file 4 | 5 | import ( 6 | "os" 7 | "path/filepath" 8 | ) 9 | 10 | // tmpDownloadPathOnNotExist create .download folder a common pattern on macOS 11 | func tmpDownloadPathOnNotExist(originalPath, tmpPath string) (string, error) { 12 | if err := os.MkdirAll(tmpPath, 0755); err != nil { 13 | return "", err 14 | } 15 | _, fileName := filepath.Split(originalPath) 16 | return filepath.Join(tmpPath, fileName), nil 17 | } 18 | 19 | func finalizeTmpDownload(tmpName string, finalPath string) error { 20 | err := os.Rename(tmpName, finalPath) 21 | if err != nil { 22 | return err 23 | } 24 | downloadPackage, _ := filepath.Split(tmpName) 25 | return os.Remove(downloadPackage) 26 | } 27 | 28 | func removeTmpDownload(tmpName string) error { 29 | err := os.Remove(tmpName) 30 | if err != nil { 31 | return err 32 | } 33 | downloadPackage, _ := filepath.Split(tmpName) 34 | return os.Remove(downloadPackage) 35 | } 36 | -------------------------------------------------------------------------------- /lib/normalizeforcomparison_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestNormalizeForComparison(t *testing.T) { 8 | testCases := []struct { 9 | input string 10 | expected string 11 | }{ 12 | {"filename.txt", "filename.txt"}, 13 | {"FiLeNaMe.TxT", "filename.txt"}, 14 | {"FILENAME.TXT", "filename.txt"}, 15 | {"FÎŁĘÑÂMÉ.TXT", "filename.txt"}, 16 | {"Fïłèńämê.Txt", "filename.txt"}, 17 | {"a/b/c.txt", "a/b/c.txt"}, 18 | {"A\\B\\C.TXT", "a/b/c.txt"}, 19 | {"A/B\\C.TXT", "a/b/c.txt"}, 20 | {"//a/b//c.txt", "a/b/c.txt"}, 21 | {"a/b/c.txt ", "a/b/c.txt"}, 22 | {"a/b/c.txt\t", "a/b/c.txt"}, 23 | {"a/b/c.txt\n", "a/b/c.txt"}, 24 | {"a/b/c.txt\r", "a/b/c.txt"}, 25 | } 26 | 27 | for _, tc := range testCases { 28 | t.Run(tc.input, func(t *testing.T) { 29 | output := NormalizeForComparison(tc.input) 30 | if output != tc.expected { 31 | t.Errorf("Expected %s but got %s", tc.expected, output) 32 | } 33 | }) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | Thank you for your interest in Files.com security. We recognize that your data is very personal and sensitive and we work hard to keep it protected. 4 | 5 | 6 | ## Supported Versions 7 | 8 | Only the latest version will be supported with security updates. 9 | 10 | 11 | ## Reporting a Vulnerability 12 | 13 | Here at Files.com, we celebrate security and we encourage independent security researchers to help us keep our products secure. 14 | 15 | We offer a Security Bug Bounty Program to create an incentive and reward structure so that researchers are able to devote resources to working on Files.com. 16 | 17 | We offer our Bug Bounty Program on HackerOne at https://hackerone.com/files 18 | 19 | We prefer to receive reports of vulnerabilities there. 20 | 21 | If you do not wish to use HackerOne, alternate submission instructions are available at: 22 | https://www.files.com/legal/security-bounty/ 23 | 24 | Thank you for helping keep the Files.com community secure! 25 | -------------------------------------------------------------------------------- /environment.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | type Environment int64 4 | 5 | const ( 6 | Production Environment = iota 7 | Staging 8 | Development 9 | ) 10 | 11 | func NewEnvironment(env string) Environment { 12 | switch env { 13 | case "staging": 14 | return Staging 15 | case "development": 16 | return Development 17 | default: 18 | return Production 19 | } 20 | } 21 | 22 | func (e Environment) String() string { 23 | switch e { 24 | case Staging: 25 | return "staging" 26 | case Development: 27 | return "development" 28 | default: 29 | return "production" 30 | } 31 | } 32 | 33 | const ( 34 | ProductionEndpoint = "https://{{SUBDOMAIN}}.files.com" 35 | developmentEndpoint = "https://{{SUBDOMAIN}}.filesrails.test" 36 | stagingEndpoint = "https://{{SUBDOMAIN}}.filesstaging.av" 37 | ) 38 | 39 | func (e Environment) Endpoint() string { 40 | switch e { 41 | case Staging: 42 | return stagingEndpoint 43 | case Development: 44 | return developmentEndpoint 45 | default: 46 | return ProductionEndpoint 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/errorwithoriginalresponse.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | ) 7 | 8 | type ErrorWithOriginalResponse struct { 9 | error 10 | originalResponse interface{} 11 | } 12 | 13 | func (u ErrorWithOriginalResponse) OriginalResponse() interface{} { 14 | return u.originalResponse 15 | } 16 | 17 | func (u ErrorWithOriginalResponse) ProcessError(data []byte, err error, t interface{}) error { 18 | var unmarshalError *json.UnmarshalTypeError 19 | ok := errors.As(err, &unmarshalError) 20 | 21 | if ok { 22 | ignoreErr := json.Unmarshal(data, &t) 23 | if ignoreErr == nil { 24 | return ErrorWithOriginalResponse{error: unmarshalError, originalResponse: t} 25 | } 26 | } 27 | var errorWithOriginalResponse ErrorWithOriginalResponse 28 | ok = errors.As(err, &errorWithOriginalResponse) 29 | if ok { 30 | ignoreErr := json.Unmarshal(data, &t) 31 | if ignoreErr == nil { 32 | return ErrorWithOriginalResponse{error: errorWithOriginalResponse.error, originalResponse: t} 33 | } 34 | } 35 | return err 36 | } 37 | -------------------------------------------------------------------------------- /session/client.go: -------------------------------------------------------------------------------- 1 | package session 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | ) 7 | 8 | type Client struct { 9 | files_sdk.Config 10 | } 11 | 12 | func (c *Client) Create(params files_sdk.SessionCreateParams, opts ...files_sdk.RequestResponseOption) (session files_sdk.Session, err error) { 13 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/sessions", Params: params, Entity: &session}, opts...) 14 | return 15 | } 16 | 17 | func Create(params files_sdk.SessionCreateParams, opts ...files_sdk.RequestResponseOption) (session files_sdk.Session, err error) { 18 | return (&Client{}).Create(params, opts...) 19 | } 20 | 21 | func (c *Client) Delete(opts ...files_sdk.RequestResponseOption) (err error) { 22 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "DELETE", Path: "/sessions", Entity: nil}, opts...) 23 | return 24 | } 25 | 26 | func Delete(opts ...files_sdk.RequestResponseOption) (err error) { 27 | return (&Client{}).Delete(opts...) 28 | } 29 | -------------------------------------------------------------------------------- /lib/queue.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import "sync" 4 | 5 | type queue[T any] []T 6 | 7 | func (q *queue[T]) Push(x T) { 8 | *q = append(*q, x) 9 | } 10 | 11 | func (q *queue[T]) Pop() T { 12 | h := *q 13 | var el T 14 | l := len(h) 15 | if l == 0 { 16 | return el 17 | } 18 | el, *q = h[0], h[1:l] 19 | return el 20 | } 21 | 22 | func (q *queue[T]) Clear() { 23 | *q = queue[T]{} 24 | } 25 | 26 | type Queue[T any] struct { 27 | queue queue[T] 28 | *sync.RWMutex 29 | } 30 | 31 | func (q *Queue[T]) Init(size int) *Queue[T] { 32 | q.RWMutex = &sync.RWMutex{} 33 | q.queue = make(queue[T], 0, size) 34 | return q 35 | } 36 | 37 | func (q *Queue[T]) Len() int { 38 | q.RLock() 39 | defer q.RUnlock() 40 | return len(q.queue) 41 | } 42 | 43 | func (q *Queue[T]) Push(item T) { 44 | q.Lock() 45 | defer q.Unlock() 46 | q.queue.Push(item) 47 | } 48 | 49 | func (q *Queue[T]) Pop() T { 50 | q.Lock() 51 | defer q.Unlock() 52 | return q.queue.Pop() 53 | } 54 | 55 | func (q *Queue[T]) Clear() { 56 | q.Lock() 57 | defer q.Unlock() 58 | *q = Queue[T]{} 59 | } 60 | -------------------------------------------------------------------------------- /lib/iterchan.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "context" 5 | "sync/atomic" 6 | ) 7 | 8 | type IterChan[T any] struct { 9 | Send chan T 10 | SendError chan error 11 | current atomic.Value 12 | Error atomic.Value 13 | Start func(*IterChan[T]) 14 | context.Context 15 | Stop context.CancelFunc 16 | } 17 | 18 | func (i *IterChan[T]) Init(ctx context.Context) *IterChan[T] { 19 | i.Send = make(chan T) 20 | i.SendError = make(chan error) 21 | i.Context, i.Stop = context.WithCancel(ctx) 22 | return i 23 | } 24 | 25 | func (i *IterChan[T]) Next() bool { 26 | select { 27 | case current := <-i.Send: 28 | i.current.Store(current) 29 | case err := <-i.SendError: 30 | i.Error.Store(err) 31 | case <-i.Done(): 32 | return false 33 | } 34 | 35 | return true 36 | } 37 | 38 | func (i *IterChan[T]) Current() interface{} { 39 | return i.current.Load() 40 | } 41 | 42 | func (i *IterChan[T]) Resource() T { 43 | return i.current.Load().(T) 44 | } 45 | 46 | func (i *IterChan[T]) Err() error { 47 | err := i.Error.Load() 48 | if err != nil { 49 | return err.(error) 50 | } 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /fsmount/internal/cache/stats.go: -------------------------------------------------------------------------------- 1 | //go:build !filescomfs_debug 2 | // +build !filescomfs_debug 3 | 4 | package cache 5 | 6 | import ( 7 | "sync/atomic" 8 | "time" 9 | ) 10 | 11 | // Stats maintains statistics about cache usage. 12 | // In non-debug builds, this type exists but has no methods for retrieving statistics. 13 | type Stats struct { 14 | CapacityBytes int64 15 | CapacityBytesRemaining int64 16 | MaxFileCount int64 17 | FileCountRemaining int64 18 | FileCount atomic.Int64 19 | ReadBytes atomic.Int64 20 | ReadCount atomic.Int64 21 | SizeBytes atomic.Int64 22 | WriteBytes atomic.Int64 23 | WriteCount atomic.Int64 24 | LoadDuration time.Duration 25 | LruCount int 26 | PinnedCount int 27 | PinnedPaths map[string]int 28 | LruKeys []string 29 | } 30 | 31 | // ResetCounters sets "counter" type stats to zero. 32 | func (st *Stats) ResetCounters() { 33 | st.ReadBytes.Store(0) 34 | st.ReadCount.Store(0) 35 | st.WriteBytes.Store(0) 36 | st.WriteCount.Store(0) 37 | } 38 | -------------------------------------------------------------------------------- /auto.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type Auto struct { 10 | Dynamic interface{} `json:"dynamic,omitempty" path:"dynamic,omitempty" url:"dynamic,omitempty"` 11 | } 12 | 13 | // Identifier no path or id 14 | 15 | type AutoCollection []Auto 16 | 17 | func (a *Auto) UnmarshalJSON(data []byte) error { 18 | type auto Auto 19 | var v auto 20 | if err := json.Unmarshal(data, &v); err != nil { 21 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 22 | } 23 | 24 | *a = Auto(v) 25 | return nil 26 | } 27 | 28 | func (a *AutoCollection) UnmarshalJSON(data []byte) error { 29 | type autos AutoCollection 30 | var v autos 31 | if err := json.Unmarshal(data, &v); err != nil { 32 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 33 | } 34 | 35 | *a = AutoCollection(v) 36 | return nil 37 | } 38 | 39 | func (a *AutoCollection) ToSlice() *[]interface{} { 40 | ret := make([]interface{}, len(*a)) 41 | for i, v := range *a { 42 | ret[i] = v 43 | } 44 | 45 | return &ret 46 | } 47 | -------------------------------------------------------------------------------- /fsmount/events/events.go: -------------------------------------------------------------------------------- 1 | // Package events provides event types and publishing interfaces for filesystem mount operations. 2 | // 3 | // This package defines a common event system for tracking and responding to mount-related 4 | // events such as authentication failures. Events implement the MountEvent interface and can 5 | // be published through an EventPublisher implementation. 6 | package events 7 | 8 | // MountEvent is the marker interface that all mount events implement. 9 | type MountEvent interface { 10 | isMountEvent() 11 | } 12 | 13 | // EventPublisher defines the interface for publishing mount events. 14 | type EventPublisher interface { 15 | Publish(MountEvent) 16 | } 17 | 18 | // NoOpEventPublisher is an EventPublisher that does nothing. 19 | type NoOpEventPublisher struct{} 20 | 21 | // Publish implements the EventPublisher interface but performs no action. 22 | func (p *NoOpEventPublisher) Publish(ev MountEvent) {} 23 | 24 | // AuthenticationFailedEvent represents an authentication failure during mount operations. 25 | type AuthenticationFailedEvent struct { 26 | Reason string 27 | } 28 | 29 | func (e AuthenticationFailedEvent) isMountEvent() {} 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2019- Action Verb, LLC (https://www.files.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/client.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) App() files_sdk.App { 23 | return i.Current().(files_sdk.App) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.AppListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/apps", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.AppCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.AppListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /fsmount/internal/cache/mem/mem_opt.go: -------------------------------------------------------------------------------- 1 | package mem 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/Files-com/files-sdk-go/v3/fsmount/internal/log" 7 | ) 8 | 9 | // Option configures a MemoryCache. 10 | type Option func(*MemoryCache) 11 | 12 | // WithCapacityBytes sets the maximum total size (in bytes) for the cache. 13 | func WithCapacityBytes(n int64) Option { 14 | return func(dc *MemoryCache) { 15 | dc.Capacity = n 16 | } 17 | } 18 | 19 | // WithMaxAge sets the maximum age for cache files. 20 | func WithMaxAge(d time.Duration) Option { 21 | return func(dc *MemoryCache) { 22 | dc.MaxAge = d 23 | } 24 | } 25 | 26 | // WithMaxFileCount sets the maximum number of files for the cache. 27 | func WithMaxFileCount(n int64) Option { 28 | return func(dc *MemoryCache) { 29 | dc.MaxFileCount = n 30 | } 31 | } 32 | 33 | // WithMaintenanceInterval sets the interval for cache maintenance operations. 34 | func WithMaintenanceInterval(d time.Duration) Option { 35 | return func(dc *MemoryCache) { 36 | dc.MaintenanceInterval = d 37 | } 38 | } 39 | 40 | // WithLogger sets the logger for the cache. 41 | func WithLogger(logger log.Logger) Option { 42 | return func(dc *MemoryCache) { 43 | dc.log = logger 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /image.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type Image struct { 10 | Name string `json:"name,omitempty" path:"name,omitempty" url:"name,omitempty"` 11 | Uri string `json:"uri,omitempty" path:"uri,omitempty" url:"uri,omitempty"` 12 | } 13 | 14 | // Identifier no path or id 15 | 16 | type ImageCollection []Image 17 | 18 | func (i *Image) UnmarshalJSON(data []byte) error { 19 | type image Image 20 | var v image 21 | if err := json.Unmarshal(data, &v); err != nil { 22 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 23 | } 24 | 25 | *i = Image(v) 26 | return nil 27 | } 28 | 29 | func (i *ImageCollection) UnmarshalJSON(data []byte) error { 30 | type images ImageCollection 31 | var v images 32 | if err := json.Unmarshal(data, &v); err != nil { 33 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 34 | } 35 | 36 | *i = ImageCollection(v) 37 | return nil 38 | } 39 | 40 | func (i *ImageCollection) ToSlice() *[]interface{} { 41 | ret := make([]interface{}, len(*i)) 42 | for i, v := range *i { 43 | ret[i] = v 44 | } 45 | 46 | return &ret 47 | } 48 | -------------------------------------------------------------------------------- /synclog/client.go: -------------------------------------------------------------------------------- 1 | package sync_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) SyncLog() files_sdk.SyncLog { 23 | return i.Current().(files_sdk.SyncLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.SyncLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/sync_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.SyncLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.SyncLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /emaillog/client.go: -------------------------------------------------------------------------------- 1 | package email_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) EmailLog() files_sdk.EmailLog { 23 | return i.Current().(files_sdk.EmailLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.EmailLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/email_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.EmailLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.EmailLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /file/fixtures/TestClient_ListForRecursive_Error.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 1 3 | interactions: 4 | - request: 5 | body: "" 6 | form: {} 7 | headers: 8 | Connection: 9 | - close 10 | User-Agent: 11 | - Files.com Go SDK 2.0.0-beta 12 | url: https://app.files.com/api/rest/v1/file_actions/metadata/TestClient_ListForRecursive-Not-Found 13 | method: GET 14 | response: 15 | body: '{"error":"Unauthorized. The API key or Session token is either missing 16 | or invalid.","http-code":401,"instance":"546cbc80-ac15-4cc3-b464-eac84198ac3a","title":"Authentication 17 | Required","type":"not-authenticated/authentication-required"}' 18 | headers: 19 | Cache-Control: 20 | - no-cache, no-store, max-age=0, must-revalidate 21 | Content-Length: 22 | - "235" 23 | Content-Type: 24 | - application/json 25 | Date: 26 | - Tue, 04 Oct 2022 22:36:27 GMT 27 | Expires: 28 | - Fri, 01 Jan 1990 00:00:00 GMT 29 | Pragma: 30 | - no-cache 31 | Server: 32 | - nginx 33 | X-Request-Id: 34 | - 546cbc80-ac15-4cc3-b464-eac84198ac3a 35 | - de9be1d3ef7f82baa80cb5b060de6559 36 | status: 401 Unauthorized 37 | code: 401 38 | duration: "" 39 | -------------------------------------------------------------------------------- /priority/client.go: -------------------------------------------------------------------------------- 1 | package priority 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) Priority() files_sdk.Priority { 23 | return i.Current().(files_sdk.Priority) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.PriorityListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/priorities", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.PriorityCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.PriorityListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /dnsrecord/client.go: -------------------------------------------------------------------------------- 1 | package dns_record 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) DnsRecord() files_sdk.DnsRecord { 23 | return i.Current().(files_sdk.DnsRecord) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.DnsRecordListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/dns_records", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.DnsRecordCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.DnsRecordListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /file/downloaduri.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "net/url" 5 | "time" 6 | ) 7 | 8 | var ( 9 | timeDateFormat = "20060102T150405Z" 10 | ) 11 | 12 | type DownloadUri string 13 | 14 | type DownloadUriValid struct { 15 | *url.URL 16 | time.Time 17 | Remaining time.Duration 18 | } 19 | 20 | func (d DownloadUri) ToUrl() (u *url.URL, err error) { 21 | u, err = url.Parse(string(d)) 22 | return 23 | } 24 | 25 | func (d DownloadUri) ToTime() (t time.Time, err error) { 26 | var u *url.URL 27 | u, err = d.ToUrl() 28 | if err != nil { 29 | return t, err 30 | } 31 | expires := u.Query().Get("X-Amz-Date") 32 | t, err = time.Parse(timeDateFormat, expires) 33 | if err == nil { 34 | return t, err 35 | } 36 | expires = u.Query().Get("X-Files-Date") 37 | t, err = time.Parse(timeDateFormat, expires) 38 | if err == nil { 39 | return t, err 40 | } 41 | expires = u.Query().Get("X-Goog-Date") 42 | t, err = time.Parse(timeDateFormat, expires) 43 | return 44 | } 45 | 46 | func (d DownloadUri) Valid(within time.Duration) (s DownloadUriValid, valid bool, err error) { 47 | s.URL, err = d.ToUrl() 48 | s.Time, err = d.ToTime() 49 | if err != nil { 50 | return 51 | } 52 | s.Remaining = s.Time.Sub(time.Now()) 53 | return s, s.Remaining < within, err 54 | } 55 | -------------------------------------------------------------------------------- /listquery/build.go: -------------------------------------------------------------------------------- 1 | package listquery 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | "github.com/Files-com/files-sdk-go/v3/lib" 6 | ) 7 | 8 | type List interface { 9 | UnmarshalJSON(data []byte) error 10 | ToSlice() *[]interface{} 11 | } 12 | 13 | func Build(config files_sdk.Config, path string, list List, opts ...files_sdk.RequestResponseOption) func(params lib.Values, laterOpts ...files_sdk.RequestResponseOption) (*[]interface{}, string, error) { 14 | return func(params lib.Values, laterOpts ...files_sdk.RequestResponseOption) (*[]interface{}, string, error) { 15 | defaultValue := make([]interface{}, 0) 16 | data, res, err := files_sdk.Call("GET", config, path, params, append(opts, laterOpts...)...) 17 | defer func() { 18 | if res != nil && res.Body != nil { 19 | res.Body.Close() 20 | } 21 | }() 22 | if err != nil { 23 | return &defaultValue, "", err 24 | } 25 | 26 | if err := lib.ResponseErrors(res, lib.NonOkError, lib.NonJSONError); err != nil { 27 | return &defaultValue, "", err 28 | } 29 | 30 | if err := list.UnmarshalJSON(*data); err != nil { 31 | return &defaultValue, res.Header.Get("X-Files-Cursor"), err 32 | } 33 | return list.ToSlice(), res.Header.Get("X-Files-Cursor"), nil 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/test/createconfig.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "net/http" 7 | "os" 8 | "path/filepath" 9 | 10 | files_sdk "github.com/Files-com/files-sdk-go/v3" 11 | "github.com/dnaeon/go-vcr/cassette" 12 | "github.com/dnaeon/go-vcr/recorder" 13 | ) 14 | 15 | func CreateConfig(fixture string) (files_sdk.Config, *recorder.Recorder, error) { 16 | var r *recorder.Recorder 17 | var err error 18 | if os.Getenv("GITLAB") != "" { 19 | fmt.Println("using ModeReplaying") 20 | r, err = recorder.NewAsMode(filepath.Join("fixtures", fixture), recorder.ModeReplaying, nil) 21 | } else { 22 | r, err = recorder.New(filepath.Join("fixtures", fixture)) 23 | } 24 | if err != nil { 25 | return files_sdk.Config{}, r, err 26 | } 27 | 28 | config := files_sdk.Config{}.Init().SetCustomClient(&http.Client{ 29 | Transport: r, 30 | }) 31 | 32 | r.AddFilter(func(i *cassette.Interaction) error { 33 | delete(i.Request.Headers, "X-Filesapi-Key") 34 | return nil 35 | }) 36 | r.SetMatcher(func(r *http.Request, i cassette.Request) bool { 37 | if cassette.DefaultMatcher(r, i) { 38 | if r.Body != nil { 39 | io.ReadAll(r.Body) 40 | r.Body.Close() 41 | } 42 | 43 | return true 44 | } 45 | return false 46 | }) 47 | return config, r, nil 48 | } 49 | -------------------------------------------------------------------------------- /errors.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type Errors struct { 10 | Fields []string `json:"fields,omitempty" path:"fields,omitempty" url:"fields,omitempty"` 11 | Messages []string `json:"messages,omitempty" path:"messages,omitempty" url:"messages,omitempty"` 12 | } 13 | 14 | // Identifier no path or id 15 | 16 | type ErrorsCollection []Errors 17 | 18 | func (e *Errors) UnmarshalJSON(data []byte) error { 19 | type errors Errors 20 | var v errors 21 | if err := json.Unmarshal(data, &v); err != nil { 22 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 23 | } 24 | 25 | *e = Errors(v) 26 | return nil 27 | } 28 | 29 | func (e *ErrorsCollection) UnmarshalJSON(data []byte) error { 30 | type errorss ErrorsCollection 31 | var v errorss 32 | if err := json.Unmarshal(data, &v); err != nil { 33 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 34 | } 35 | 36 | *e = ErrorsCollection(v) 37 | return nil 38 | } 39 | 40 | func (e *ErrorsCollection) ToSlice() *[]interface{} { 41 | ret := make([]interface{}, len(*e)) 42 | for i, v := range *e { 43 | ret[i] = v 44 | } 45 | 46 | return &ret 47 | } 48 | -------------------------------------------------------------------------------- /inboxupload/client.go: -------------------------------------------------------------------------------- 1 | package inbox_upload 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) InboxUpload() files_sdk.InboxUpload { 23 | return i.Current().(files_sdk.InboxUpload) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.InboxUploadListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/inbox_uploads", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.InboxUploadCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.InboxUploadListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /bundleaction/client.go: -------------------------------------------------------------------------------- 1 | package bundle_action 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) BundleAction() files_sdk.BundleAction { 23 | return i.Current().(files_sdk.BundleAction) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.BundleActionListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/bundle_actions", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.BundleActionCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.BundleActionListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /ftpactionlog/client.go: -------------------------------------------------------------------------------- 1 | package ftp_action_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) FtpActionLog() files_sdk.FtpActionLog { 23 | return i.Current().(files_sdk.FtpActionLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.FtpActionLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/ftp_action_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.FtpActionLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.FtpActionLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /inbounds3log/client.go: -------------------------------------------------------------------------------- 1 | package inbound_s3_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) InboundS3Log() files_sdk.InboundS3Log { 23 | return i.Current().(files_sdk.InboundS3Log) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.InboundS3LogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/inbound_s3_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.InboundS3LogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.InboundS3LogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /apirequestlog/client.go: -------------------------------------------------------------------------------- 1 | package api_request_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) ApiRequestLog() files_sdk.ApiRequestLog { 23 | return i.Current().(files_sdk.ApiRequestLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.ApiRequestLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/api_request_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.ApiRequestLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.ApiRequestLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /automationlog/client.go: -------------------------------------------------------------------------------- 1 | package automation_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) AutomationLog() files_sdk.AutomationLog { 23 | return i.Current().(files_sdk.AutomationLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.AutomationLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/automation_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.AutomationLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.AutomationLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /file/file.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "encoding/json" 5 | "sync" 6 | "time" 7 | 8 | filesSDK "github.com/Files-com/files-sdk-go/v3" 9 | "github.com/Files-com/files-sdk-go/v3/file/status" 10 | ) 11 | 12 | type JobFile struct { 13 | StatusName string `json:"status"` 14 | TransferBytes int64 `json:"transferred_bytes"` 15 | Size int64 `json:"size_bytes"` 16 | LocalPath string `json:"local_path"` 17 | RemotePath string `json:"remote_path"` 18 | EndedAt time.Time `json:"completed_at"` 19 | StartedAt time.Time `json:"started_at"` 20 | Err error `json:"error"` 21 | Id string `json:"-"` 22 | Attempts int `json:"attempts"` 23 | Mutex *sync.RWMutex `json:"-"` 24 | status.Status `json:"-"` 25 | filesSDK.File `json:"-"` 26 | *Job `json:"-"` 27 | } 28 | 29 | type MashableError struct { 30 | error 31 | } 32 | 33 | func (m MashableError) MarshalJSON() ([]byte, error) { 34 | return json.Marshal(m.error) 35 | } 36 | 37 | func (m MashableError) Err() error { 38 | if m.error == nil { 39 | return nil 40 | } 41 | 42 | return m 43 | } 44 | 45 | func (m MashableError) Unwrap() error { 46 | return m.error 47 | } 48 | 49 | type Reporter func(JobFile) 50 | -------------------------------------------------------------------------------- /sftpactionlog/client.go: -------------------------------------------------------------------------------- 1 | package sftp_action_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) SftpActionLog() files_sdk.SftpActionLog { 23 | return i.Current().(files_sdk.SftpActionLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.SftpActionLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/sftp_action_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.SftpActionLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.SftpActionLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /usagesnapshot/client.go: -------------------------------------------------------------------------------- 1 | package usage_snapshot 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) UsageSnapshot() files_sdk.UsageSnapshot { 23 | return i.Current().(files_sdk.UsageSnapshot) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.UsageSnapshotListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/usage_snapshots", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.UsageSnapshotCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.UsageSnapshotListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /usercipheruse/client.go: -------------------------------------------------------------------------------- 1 | package user_cipher_use 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) UserCipherUse() files_sdk.UserCipherUse { 23 | return i.Current().(files_sdk.UserCipherUse) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.UserCipherUseListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/user_cipher_uses", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.UserCipherUseCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.UserCipherUseListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /bundledownload/client.go: -------------------------------------------------------------------------------- 1 | package bundle_download 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) BundleDownload() files_sdk.BundleDownload { 23 | return i.Current().(files_sdk.BundleDownload) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.BundleDownloadListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/bundle_downloads", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.BundleDownloadCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.BundleDownloadListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /settingschange/client.go: -------------------------------------------------------------------------------- 1 | package settings_change 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) SettingsChange() files_sdk.SettingsChange { 23 | return i.Current().(files_sdk.SettingsChange) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.SettingsChangeListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/settings_changes", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.SettingsChangeCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.SettingsChangeListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /historyexport/client.go: -------------------------------------------------------------------------------- 1 | package history_export 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | ) 7 | 8 | type Client struct { 9 | files_sdk.Config 10 | } 11 | 12 | func (c *Client) Find(params files_sdk.HistoryExportFindParams, opts ...files_sdk.RequestResponseOption) (historyExport files_sdk.HistoryExport, err error) { 13 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/history_exports/{id}", Params: params, Entity: &historyExport}, opts...) 14 | return 15 | } 16 | 17 | func Find(params files_sdk.HistoryExportFindParams, opts ...files_sdk.RequestResponseOption) (historyExport files_sdk.HistoryExport, err error) { 18 | return (&Client{}).Find(params, opts...) 19 | } 20 | 21 | func (c *Client) Create(params files_sdk.HistoryExportCreateParams, opts ...files_sdk.RequestResponseOption) (historyExport files_sdk.HistoryExport, err error) { 22 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/history_exports", Params: params, Entity: &historyExport}, opts...) 23 | return 24 | } 25 | 26 | func Create(params files_sdk.HistoryExportCreateParams, opts ...files_sdk.RequestResponseOption) (historyExport files_sdk.HistoryExport, err error) { 27 | return (&Client{}).Create(params, opts...) 28 | } 29 | -------------------------------------------------------------------------------- /filecommentreaction/client.go: -------------------------------------------------------------------------------- 1 | package file_comment_reaction 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | ) 7 | 8 | type Client struct { 9 | files_sdk.Config 10 | } 11 | 12 | func (c *Client) Create(params files_sdk.FileCommentReactionCreateParams, opts ...files_sdk.RequestResponseOption) (fileCommentReaction files_sdk.FileCommentReaction, err error) { 13 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/file_comment_reactions", Params: params, Entity: &fileCommentReaction}, opts...) 14 | return 15 | } 16 | 17 | func Create(params files_sdk.FileCommentReactionCreateParams, opts ...files_sdk.RequestResponseOption) (fileCommentReaction files_sdk.FileCommentReaction, err error) { 18 | return (&Client{}).Create(params, opts...) 19 | } 20 | 21 | func (c *Client) Delete(params files_sdk.FileCommentReactionDeleteParams, opts ...files_sdk.RequestResponseOption) (err error) { 22 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "DELETE", Path: "/file_comment_reactions/{id}", Params: params, Entity: nil}, opts...) 23 | return 24 | } 25 | 26 | func Delete(params files_sdk.FileCommentReactionDeleteParams, opts ...files_sdk.RequestResponseOption) (err error) { 27 | return (&Client{}).Delete(params, opts...) 28 | } 29 | -------------------------------------------------------------------------------- /lib/partsize.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | const ( 4 | BasePart = int64(1024 * 1024 * 5) 5 | ) 6 | 7 | // PartSizes return 10k parts that add up to 4.9 TB 8 | var PartSizes = partSizes() 9 | 10 | func partSizes() []int64 { 11 | maxSize := int64(1024 * 1024 * 1024 * 1024 * 5) 12 | totalParts := 10_000 13 | totalSize := int64(0) 14 | var parts []int64 15 | partSize := BasePart 16 | var iter []int 17 | iter = append(iter, 0) 18 | iter = append(iter, 100) 19 | f := fibonacci() 20 | f() // 0 - skip first two rounds of fib 21 | f() // 100 22 | for len(parts) < totalParts { 23 | perIt := f() * 100 24 | for i := 0; i < perIt; i++ { 25 | if len(parts) == totalParts { 26 | break 27 | } 28 | 29 | remaining := maxSize - totalSize 30 | if remaining >= partSize { 31 | parts = append(parts, partSize) 32 | totalSize += partSize 33 | } else if remaining > 0 { 34 | parts = append(parts, remaining) 35 | totalSize += remaining 36 | } else { 37 | break 38 | } 39 | } 40 | 41 | if maxSize-totalSize == 0 { 42 | break 43 | } 44 | partSize = partSize + partSize 45 | } 46 | return parts 47 | } 48 | 49 | func fibonacci() func() int { 50 | first, second := 0, 1 51 | return func() int { 52 | ret := first 53 | first, second = second, first+second 54 | return ret 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /webdavactionlog/client.go: -------------------------------------------------------------------------------- 1 | package web_dav_action_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) WebDavActionLog() files_sdk.WebDavActionLog { 23 | return i.Current().(files_sdk.WebDavActionLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.WebDavActionLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/web_dav_action_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.WebDavActionLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.WebDavActionLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /filemigrationlog/client.go: -------------------------------------------------------------------------------- 1 | package file_migration_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) FileMigrationLog() files_sdk.FileMigrationLog { 23 | return i.Current().(files_sdk.FileMigrationLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.FileMigrationLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/file_migration_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.FileMigrationLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.FileMigrationLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /bandwidthsnapshot/client.go: -------------------------------------------------------------------------------- 1 | package bandwidth_snapshot 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) BandwidthSnapshot() files_sdk.BandwidthSnapshot { 23 | return i.Current().(files_sdk.BandwidthSnapshot) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.BandwidthSnapshotListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/bandwidth_snapshots", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.BandwidthSnapshotCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.BandwidthSnapshotListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /inboxregistration/client.go: -------------------------------------------------------------------------------- 1 | package inbox_registration 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) InboxRegistration() files_sdk.InboxRegistration { 23 | return i.Current().(files_sdk.InboxRegistration) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.InboxRegistrationListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/inbox_registrations", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.InboxRegistrationCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.InboxRegistrationListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /usersftpclientuse/client.go: -------------------------------------------------------------------------------- 1 | package user_sftp_client_use 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) UserSftpClientUse() files_sdk.UserSftpClientUse { 23 | return i.Current().(files_sdk.UserSftpClientUse) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.UserSftpClientUseListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/user_sftp_client_uses", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.UserSftpClientUseCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.UserSftpClientUseListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /as2incomingmessage/client.go: -------------------------------------------------------------------------------- 1 | package as2_incoming_message 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) As2IncomingMessage() files_sdk.As2IncomingMessage { 23 | return i.Current().(files_sdk.As2IncomingMessage) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.As2IncomingMessageListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/as2_incoming_messages", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.As2IncomingMessageCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.As2IncomingMessageListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /as2outgoingmessage/client.go: -------------------------------------------------------------------------------- 1 | package as2_outgoing_message 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) As2OutgoingMessage() files_sdk.As2OutgoingMessage { 23 | return i.Current().(files_sdk.As2OutgoingMessage) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.As2OutgoingMessageListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/as2_outgoing_messages", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.As2OutgoingMessageCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.As2OutgoingMessageListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /bundleregistration/client.go: -------------------------------------------------------------------------------- 1 | package bundle_registration 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) BundleRegistration() files_sdk.BundleRegistration { 23 | return i.Current().(files_sdk.BundleRegistration) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.BundleRegistrationListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/bundle_registrations", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.BundleRegistrationCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.BundleRegistrationListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /usagedailysnapshot/client.go: -------------------------------------------------------------------------------- 1 | package usage_daily_snapshot 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) UsageDailySnapshot() files_sdk.UsageDailySnapshot { 23 | return i.Current().(files_sdk.UsageDailySnapshot) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.UsageDailySnapshotListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/usage_daily_snapshots", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.UsageDailySnapshotCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.UsageDailySnapshotListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /holidayregion/client.go: -------------------------------------------------------------------------------- 1 | package holiday_region 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) HolidayRegion() files_sdk.HolidayRegion { 23 | return i.Current().(files_sdk.HolidayRegion) 24 | } 25 | 26 | func (c *Client) GetSupported(params files_sdk.HolidayRegionGetSupportedParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/holiday_regions/supported", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.HolidayRegionCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func GetSupported(params files_sdk.HolidayRegionGetSupportedParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).GetSupported(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /historyexportresult/client.go: -------------------------------------------------------------------------------- 1 | package history_export_result 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) HistoryExportResult() files_sdk.HistoryExportResult { 23 | return i.Current().(files_sdk.HistoryExportResult) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.HistoryExportResultListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/history_export_results", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.HistoryExportResultCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.HistoryExportResultListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /emailincomingmessage/client.go: -------------------------------------------------------------------------------- 1 | package email_incoming_message 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) EmailIncomingMessage() files_sdk.EmailIncomingMessage { 23 | return i.Current().(files_sdk.EmailIncomingMessage) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.EmailIncomingMessageListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/email_incoming_messages", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.EmailIncomingMessageCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.EmailIncomingMessageListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /exavaultapirequestlog/client.go: -------------------------------------------------------------------------------- 1 | package exavault_api_request_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) ExavaultApiRequestLog() files_sdk.ExavaultApiRequestLog { 23 | return i.Current().(files_sdk.ExavaultApiRequestLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.ExavaultApiRequestLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/exavault_api_request_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.ExavaultApiRequestLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.ExavaultApiRequestLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /outboundconnectionlog/client.go: -------------------------------------------------------------------------------- 1 | package outbound_connection_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) OutboundConnectionLog() files_sdk.OutboundConnectionLog { 23 | return i.Current().(files_sdk.OutboundConnectionLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.OutboundConnectionLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/outbound_connection_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.OutboundConnectionLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.OutboundConnectionLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /bundlepath.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type BundlePath struct { 10 | Recursive *bool `json:"recursive,omitempty" path:"recursive,omitempty" url:"recursive,omitempty"` 11 | Path string `json:"path,omitempty" path:"path,omitempty" url:"path,omitempty"` 12 | } 13 | 14 | func (b BundlePath) Identifier() interface{} { 15 | return b.Path 16 | } 17 | 18 | type BundlePathCollection []BundlePath 19 | 20 | func (b *BundlePath) UnmarshalJSON(data []byte) error { 21 | type bundlePath BundlePath 22 | var v bundlePath 23 | if err := json.Unmarshal(data, &v); err != nil { 24 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 25 | } 26 | 27 | *b = BundlePath(v) 28 | return nil 29 | } 30 | 31 | func (b *BundlePathCollection) UnmarshalJSON(data []byte) error { 32 | type bundlePaths BundlePathCollection 33 | var v bundlePaths 34 | if err := json.Unmarshal(data, &v); err != nil { 35 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 36 | } 37 | 38 | *b = BundlePathCollection(v) 39 | return nil 40 | } 41 | 42 | func (b *BundlePathCollection) ToSlice() *[]interface{} { 43 | ret := make([]interface{}, len(*b)) 44 | for i, v := range *b { 45 | ret[i] = v 46 | } 47 | 48 | return &ret 49 | } 50 | -------------------------------------------------------------------------------- /fileaction.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type FileAction struct { 10 | Status string `json:"status,omitempty" path:"status,omitempty" url:"status,omitempty"` 11 | FileMigrationId int64 `json:"file_migration_id,omitempty" path:"file_migration_id,omitempty" url:"file_migration_id,omitempty"` 12 | } 13 | 14 | // Identifier no path or id 15 | 16 | type FileActionCollection []FileAction 17 | 18 | func (f *FileAction) UnmarshalJSON(data []byte) error { 19 | type fileAction FileAction 20 | var v fileAction 21 | if err := json.Unmarshal(data, &v); err != nil { 22 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 23 | } 24 | 25 | *f = FileAction(v) 26 | return nil 27 | } 28 | 29 | func (f *FileActionCollection) UnmarshalJSON(data []byte) error { 30 | type fileActions FileActionCollection 31 | var v fileActions 32 | if err := json.Unmarshal(data, &v); err != nil { 33 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 34 | } 35 | 36 | *f = FileActionCollection(v) 37 | return nil 38 | } 39 | 40 | func (f *FileActionCollection) ToSlice() *[]interface{} { 41 | ret := make([]interface{}, len(*f)) 42 | for i, v := range *f { 43 | ret[i] = v 44 | } 45 | 46 | return &ret 47 | } 48 | -------------------------------------------------------------------------------- /remotebandwidthsnapshot/client.go: -------------------------------------------------------------------------------- 1 | package remote_bandwidth_snapshot 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) RemoteBandwidthSnapshot() files_sdk.RemoteBandwidthSnapshot { 23 | return i.Current().(files_sdk.RemoteBandwidthSnapshot) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.RemoteBandwidthSnapshotListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/remote_bandwidth_snapshots", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.RemoteBandwidthSnapshotCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.RemoteBandwidthSnapshotListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /publichostingrequestlog/client.go: -------------------------------------------------------------------------------- 1 | package public_hosting_request_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) PublicHostingRequestLog() files_sdk.PublicHostingRequestLog { 23 | return i.Current().(files_sdk.PublicHostingRequestLog) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.PublicHostingRequestLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/public_hosting_request_logs", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.PublicHostingRequestLogCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.PublicHostingRequestLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /holidayregion.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type HolidayRegion struct { 10 | Code string `json:"code,omitempty" path:"code,omitempty" url:"code,omitempty"` 11 | Name string `json:"name,omitempty" path:"name,omitempty" url:"name,omitempty"` 12 | } 13 | 14 | // Identifier no path or id 15 | 16 | type HolidayRegionCollection []HolidayRegion 17 | 18 | type HolidayRegionGetSupportedParams struct { 19 | ListParams 20 | } 21 | 22 | func (h *HolidayRegion) UnmarshalJSON(data []byte) error { 23 | type holidayRegion HolidayRegion 24 | var v holidayRegion 25 | if err := json.Unmarshal(data, &v); err != nil { 26 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 27 | } 28 | 29 | *h = HolidayRegion(v) 30 | return nil 31 | } 32 | 33 | func (h *HolidayRegionCollection) UnmarshalJSON(data []byte) error { 34 | type holidayRegions HolidayRegionCollection 35 | var v holidayRegions 36 | if err := json.Unmarshal(data, &v); err != nil { 37 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 38 | } 39 | 40 | *h = HolidayRegionCollection(v) 41 | return nil 42 | } 43 | 44 | func (h *HolidayRegionCollection) ToSlice() *[]interface{} { 45 | ret := make([]interface{}, len(*h)) 46 | for i, v := range *h { 47 | ret[i] = v 48 | } 49 | 50 | return &ret 51 | } 52 | -------------------------------------------------------------------------------- /file/fixtures/TestClient_ListForRecursive_Root.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 1 3 | interactions: 4 | - request: 5 | body: "" 6 | form: {} 7 | headers: 8 | Connection: 9 | - close 10 | User-Agent: 11 | - Files.com Go SDK 2.0.0-beta 12 | url: https://app.files.com/api/rest/v1/folders/ 13 | method: GET 14 | response: 15 | body: '[{"path":"aws-sftp","display_name":"aws-sftp","type":"directory","size":null,"created_at":"2022-02-07T19:13:01Z","mtime":"2022-02-07T19:13:01Z","provided_mtime":null,"crc32":null,"md5":null,"permissions":"lrwd","subfolders_locked?":false,"is_locked":false},{"path":"azure","display_name":"azure","type":"directory","size":null,"created_at":null,"mtime":"2023-01-02T19:03:42Z","provided_mtime":null,"crc32":null,"md5":null,"permissions":"lrwd","subfolders_locked?":false,"is_locked":false}]' 16 | headers: 17 | Cache-Control: 18 | - no-cache, no-store, max-age=0, must-revalidate 19 | Content-Type: 20 | - application/json 21 | Date: 22 | - Fri, 21 Apr 2023 21:35:23 GMT 23 | Expires: 24 | - Fri, 01 Jan 1990 00:00:00 GMT 25 | Pragma: 26 | - no-cache 27 | Server: 28 | - files.com 29 | X-Files-Cached-Response: 30 | - "1682112627" 31 | X-Request-Id: 32 | - eb894677-c3cf-4166-846b-0fdfb795edae 33 | - 4f8308feaab7e31ffc1fb18c8c7ef5d8 34 | status: 200 OK 35 | code: 200 36 | duration: "" 37 | -------------------------------------------------------------------------------- /actionnotificationexportresult/client.go: -------------------------------------------------------------------------------- 1 | package action_notification_export_result 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) ActionNotificationExportResult() files_sdk.ActionNotificationExportResult { 23 | return i.Current().(files_sdk.ActionNotificationExportResult) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.ActionNotificationExportResultListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/action_notification_export_results", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.ActionNotificationExportResultCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.ActionNotificationExportResultListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | -------------------------------------------------------------------------------- /priority.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type Priority struct { 10 | Path string `json:"path,omitempty" path:"path,omitempty" url:"path,omitempty"` 11 | Color string `json:"color,omitempty" path:"color,omitempty" url:"color,omitempty"` 12 | } 13 | 14 | func (p Priority) Identifier() interface{} { 15 | return p.Path 16 | } 17 | 18 | type PriorityCollection []Priority 19 | 20 | type PriorityListParams struct { 21 | Path string `url:"path" json:"path" path:"path"` 22 | ListParams 23 | } 24 | 25 | func (p *Priority) UnmarshalJSON(data []byte) error { 26 | type priority Priority 27 | var v priority 28 | if err := json.Unmarshal(data, &v); err != nil { 29 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 30 | } 31 | 32 | *p = Priority(v) 33 | return nil 34 | } 35 | 36 | func (p *PriorityCollection) UnmarshalJSON(data []byte) error { 37 | type prioritys PriorityCollection 38 | var v prioritys 39 | if err := json.Unmarshal(data, &v); err != nil { 40 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 41 | } 42 | 43 | *p = PriorityCollection(v) 44 | return nil 45 | } 46 | 47 | func (p *PriorityCollection) ToSlice() *[]interface{} { 48 | ret := make([]interface{}, len(*p)) 49 | for i, v := range *p { 50 | ret[i] = v 51 | } 52 | 53 | return &ret 54 | } 55 | -------------------------------------------------------------------------------- /file/tmpdownloadpath.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "os" 7 | "path/filepath" 8 | "time" 9 | ) 10 | 11 | const TempDownloadExtension = "download" 12 | 13 | // tmpDownloadPath Generates a unique temporary download path for a given file path by appending a ".download" extension and, if necessary, additional identifiers to avoid name conflicts. 14 | func tmpDownloadPath(path string, tempPath string) (string, error) { 15 | var index int 16 | randGenerator := rand.New(rand.NewSource(time.Now().UnixNano())) 17 | 18 | if tempPath != "" { 19 | _, fileName := filepath.Split(path) 20 | path = filepath.Join(tempPath, fileName) 21 | } 22 | 23 | for { 24 | var tempPath, uniqueness string 25 | if index == 0 { 26 | tempPath = fmt.Sprintf("%v.%v", path, TempDownloadExtension) 27 | } else if index > 25 { 28 | return "", fmt.Errorf("unable to create a unique temporary path after 25 attempts, consider deleting existing .%v files; attempted path: %v", TempDownloadExtension, path) 29 | } else { 30 | if index > 10 { 31 | for i := 0; i < 4; i++ { 32 | uniqueness += string(rune(randGenerator.Intn(26) + 'a')) 33 | } 34 | } else { 35 | uniqueness = fmt.Sprintf("%v", index) 36 | } 37 | tempPath = fmt.Sprintf("%v (%v).%v", path, uniqueness, TempDownloadExtension) 38 | } 39 | 40 | if _, err := os.Stat(tempPath); os.IsNotExist(err) { 41 | return tmpDownloadPathOnNotExist(path, tempPath) 42 | } 43 | index++ 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sharegroupmember.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type ShareGroupMember struct { 10 | Name string `json:"name,omitempty" path:"name,omitempty" url:"name,omitempty"` 11 | Company string `json:"company,omitempty" path:"company,omitempty" url:"company,omitempty"` 12 | Email string `json:"email,omitempty" path:"email,omitempty" url:"email,omitempty"` 13 | } 14 | 15 | // Identifier no path or id 16 | 17 | type ShareGroupMemberCollection []ShareGroupMember 18 | 19 | func (s *ShareGroupMember) UnmarshalJSON(data []byte) error { 20 | type shareGroupMember ShareGroupMember 21 | var v shareGroupMember 22 | if err := json.Unmarshal(data, &v); err != nil { 23 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 24 | } 25 | 26 | *s = ShareGroupMember(v) 27 | return nil 28 | } 29 | 30 | func (s *ShareGroupMemberCollection) UnmarshalJSON(data []byte) error { 31 | type shareGroupMembers ShareGroupMemberCollection 32 | var v shareGroupMembers 33 | if err := json.Unmarshal(data, &v); err != nil { 34 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 35 | } 36 | 37 | *s = ShareGroupMemberCollection(v) 38 | return nil 39 | } 40 | 41 | func (s *ShareGroupMemberCollection) ToSlice() *[]interface{} { 42 | ret := make([]interface{}, len(*s)) 43 | for i, v := range *s { 44 | ret[i] = v 45 | } 46 | 47 | return &ret 48 | } 49 | -------------------------------------------------------------------------------- /actionnotificationexport/client.go: -------------------------------------------------------------------------------- 1 | package action_notification_export 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | ) 7 | 8 | type Client struct { 9 | files_sdk.Config 10 | } 11 | 12 | func (c *Client) Find(params files_sdk.ActionNotificationExportFindParams, opts ...files_sdk.RequestResponseOption) (actionNotificationExport files_sdk.ActionNotificationExport, err error) { 13 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/action_notification_exports/{id}", Params: params, Entity: &actionNotificationExport}, opts...) 14 | return 15 | } 16 | 17 | func Find(params files_sdk.ActionNotificationExportFindParams, opts ...files_sdk.RequestResponseOption) (actionNotificationExport files_sdk.ActionNotificationExport, err error) { 18 | return (&Client{}).Find(params, opts...) 19 | } 20 | 21 | func (c *Client) Create(params files_sdk.ActionNotificationExportCreateParams, opts ...files_sdk.RequestResponseOption) (actionNotificationExport files_sdk.ActionNotificationExport, err error) { 22 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/action_notification_exports", Params: params, Entity: &actionNotificationExport}, opts...) 23 | return 24 | } 25 | 26 | func Create(params files_sdk.ActionNotificationExportCreateParams, opts ...files_sdk.RequestResponseOption) (actionNotificationExport files_sdk.ActionNotificationExport, err error) { 27 | return (&Client{}).Create(params, opts...) 28 | } 29 | -------------------------------------------------------------------------------- /usagebytopleveldir.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type UsageByTopLevelDir struct { 10 | Dir string `json:"dir,omitempty" path:"dir,omitempty" url:"dir,omitempty"` 11 | Size int64 `json:"size,omitempty" path:"size,omitempty" url:"size,omitempty"` 12 | Count int64 `json:"count,omitempty" path:"count,omitempty" url:"count,omitempty"` 13 | } 14 | 15 | // Identifier no path or id 16 | 17 | type UsageByTopLevelDirCollection []UsageByTopLevelDir 18 | 19 | func (u *UsageByTopLevelDir) UnmarshalJSON(data []byte) error { 20 | type usageByTopLevelDir UsageByTopLevelDir 21 | var v usageByTopLevelDir 22 | if err := json.Unmarshal(data, &v); err != nil { 23 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 24 | } 25 | 26 | *u = UsageByTopLevelDir(v) 27 | return nil 28 | } 29 | 30 | func (u *UsageByTopLevelDirCollection) UnmarshalJSON(data []byte) error { 31 | type usageByTopLevelDirs UsageByTopLevelDirCollection 32 | var v usageByTopLevelDirs 33 | if err := json.Unmarshal(data, &v); err != nil { 34 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 35 | } 36 | 37 | *u = UsageByTopLevelDirCollection(v) 38 | return nil 39 | } 40 | 41 | func (u *UsageByTopLevelDirCollection) ToSlice() *[]interface{} { 42 | ret := make([]interface{}, len(*u)) 43 | for i, v := range *u { 44 | ret[i] = v 45 | } 46 | 47 | return &ret 48 | } 49 | -------------------------------------------------------------------------------- /lib/readerctx.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "context" 5 | "io" 6 | ) 7 | 8 | type readerAtCtx struct { 9 | ctx context.Context 10 | r io.ReaderAt 11 | } 12 | 13 | type readerCtx struct { 14 | ctx context.Context 15 | io.ReadCloser 16 | } 17 | 18 | type WithContextReaderAt interface { 19 | WithContext(context.Context) interface{} 20 | io.ReaderAt 21 | } 22 | 23 | type WithContextReader interface { 24 | WithContext(context.Context) interface{} 25 | io.Reader 26 | } 27 | 28 | type ReaderAtCloser interface { 29 | io.ReaderAt 30 | io.ReadCloser 31 | } 32 | 33 | func (r *readerAtCtx) ReadAt(p []byte, off int64) (n int, err error) { 34 | if err := r.ctx.Err(); err != nil { 35 | return 0, err 36 | } 37 | 38 | withContext, ok := r.r.(WithContextReader) 39 | if ok { 40 | r.r = withContext.WithContext(r.ctx).(io.ReaderAt) 41 | } 42 | return r.r.ReadAt(p, off) 43 | } 44 | 45 | func (r *readerCtx) Read(p []byte) (n int, err error) { 46 | if err := r.ctx.Err(); err != nil { 47 | return 0, err 48 | } 49 | 50 | withContext, ok := r.ReadCloser.(WithContextReader) 51 | if ok { 52 | r.ReadCloser = withContext.WithContext(r.ctx).(io.ReadCloser) 53 | } 54 | return r.ReadCloser.Read(p) 55 | } 56 | 57 | // NewReader gets a context-aware io.Reader. 58 | func NewReaderAt(ctx context.Context, r io.ReaderAt) io.ReaderAt { 59 | return &readerAtCtx{ctx: ctx, r: r} 60 | } 61 | 62 | // NewReader gets a context-aware io.Reader. 63 | func NewReader(ctx context.Context, r io.ReadCloser) io.ReadCloser { 64 | return &readerCtx{ctx: ctx, ReadCloser: r} 65 | } 66 | -------------------------------------------------------------------------------- /folder/client_test.go: -------------------------------------------------------------------------------- 1 | package folder 2 | 3 | import ( 4 | "bytes" 5 | "log" 6 | "testing" 7 | 8 | files_sdk "github.com/Files-com/files-sdk-go/v3" 9 | "github.com/Files-com/files-sdk-go/v3/lib" 10 | "github.com/stretchr/testify/assert" 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | func TestClient_ListFor(t *testing.T) { 15 | type args struct { 16 | params files_sdk.FolderListForParams 17 | opts []files_sdk.RequestResponseOption 18 | } 19 | tests := []struct { 20 | name string 21 | files_sdk.Config 22 | args args 23 | debugOutput string 24 | }{ 25 | { 26 | "without path it send fields", 27 | files_sdk.Config{}.Init(), 28 | args{params: files_sdk.FolderListForParams{WithPreviews: lib.Bool(true)}, opts: []files_sdk.RequestResponseOption{}}, 29 | "with_preview", 30 | }, 31 | { 32 | "with path it send fields", 33 | files_sdk.Config{}.Init(), 34 | args{params: files_sdk.FolderListForParams{Path: "anything", WithPreviews: lib.Bool(true)}, opts: []files_sdk.RequestResponseOption{}}, 35 | "with_preview", 36 | }, 37 | } 38 | for _, tt := range tests { 39 | t.Run(tt.name, func(t *testing.T) { 40 | tt.Config.Debug = true 41 | var buf bytes.Buffer 42 | logger := log.New(&buf, "InMemoryLogger: ", log.LstdFlags) 43 | 44 | tt.Config.Logger = logger 45 | c := &Client{ 46 | Config: tt.Config, 47 | } 48 | 49 | it, err := c.ListFor(tt.args.params, tt.args.opts...) 50 | require.NoError(t, err) 51 | it.GetPage() 52 | assert.Contains(t, buf.String(), tt.debugOutput) 53 | }) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /shared/url_test_data.json: -------------------------------------------------------------------------------- 1 | { 2 | "substitute_urls": [ 3 | "https://storage.googleapis.com/example-bucket/cat.jpeg?X-Goog-Date=%s&X-Goog-Expires=%s&X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-SignedHeaders=host", 4 | "https://s3.amazonaws.com/test.example.com/metadata/1234/00000000-0000-0000-0001-00000000?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=%s&X-Amz-Expires=%s", 5 | "https://filescomtests.blob.core.windows.net/testazureremote/ntie3buw/file-to-download.txt?sp=se=%s" 6 | ], 7 | "error_urls": [ 8 | "https://storage.googleapis.com/example-bucket/cat.jpeg?X-Goog-Date=20220101T120000Z", 9 | "https://storage.googleapis.com/example-bucket/cat.jpeg?X-Goog-Date=20220101T120000Z&X-Goog-Date=20220202T120000Z", 10 | "https://storage.googleapis.com/example-bucket/cat.jpeg?X-Goog-Expires=900&X-Goog-Expires=600", 11 | "https://filescomtests.blob.core.windows.net/testazureremote/ntie3buw/file-to-download.txt?sp=se=20220101T120000Z&sp=se=20220202T120000Z", 12 | "https://filescomtests.blob.core.windows.net/testazureremote/ntie3buw/file-to-download.txt?sp=20220101T120000Z", 13 | "https://storage.googleapis.com/example-bucket/cat.jpeg?X-Goog-Date=20220101&X-Goog-Expires=900", 14 | "https://storage.googleapis.com/example-bucket/cat.jpeg?X-Goog-Date=asdf&X-Goog-Expires=900", 15 | "https://storage.googleapis.com/example-bucket/cat.jpeg?X-Goog-Date=20220101T120000Z&&X-Goog-Expires=900", 16 | "https://s3.amazonaws.com/test.example.com/metadata/1234/00000000-0000-0000-0001-00000000?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=asdf&X-Amz-Expires=900" 17 | ] 18 | } -------------------------------------------------------------------------------- /dnsrecord.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type DnsRecord struct { 10 | Id string `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"` 11 | Domain string `json:"domain,omitempty" path:"domain,omitempty" url:"domain,omitempty"` 12 | Rrtype string `json:"rrtype,omitempty" path:"rrtype,omitempty" url:"rrtype,omitempty"` 13 | Value string `json:"value,omitempty" path:"value,omitempty" url:"value,omitempty"` 14 | } 15 | 16 | func (d DnsRecord) Identifier() interface{} { 17 | return d.Id 18 | } 19 | 20 | type DnsRecordCollection []DnsRecord 21 | 22 | type DnsRecordListParams struct { 23 | ListParams 24 | } 25 | 26 | func (d *DnsRecord) UnmarshalJSON(data []byte) error { 27 | type dnsRecord DnsRecord 28 | var v dnsRecord 29 | if err := json.Unmarshal(data, &v); err != nil { 30 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 31 | } 32 | 33 | *d = DnsRecord(v) 34 | return nil 35 | } 36 | 37 | func (d *DnsRecordCollection) UnmarshalJSON(data []byte) error { 38 | type dnsRecords DnsRecordCollection 39 | var v dnsRecords 40 | if err := json.Unmarshal(data, &v); err != nil { 41 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 42 | } 43 | 44 | *d = DnsRecordCollection(v) 45 | return nil 46 | } 47 | 48 | func (d *DnsRecordCollection) ToSlice() *[]interface{} { 49 | ret := make([]interface{}, len(*d)) 50 | for i, v := range *d { 51 | ret[i] = v 52 | } 53 | 54 | return &ret 55 | } 56 | -------------------------------------------------------------------------------- /file/remotefs_test.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "context" 5 | "path/filepath" 6 | "strings" 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | 11 | "github.com/stretchr/testify/assert" 12 | ) 13 | 14 | func TestFS_Open(t *testing.T) { 15 | client, r, err := CreateClient("TestFS_Open") 16 | if err != nil { 17 | t.Fatal(err) 18 | } 19 | defer r.Stop() 20 | 21 | assert := assert.New(t) 22 | client.Upload( 23 | UploadWithReader(strings.NewReader("testing 3")), 24 | UploadWithSize(9), 25 | UploadWithDestinationPath(filepath.Join("remotefs_test", "1.text")), 26 | ) 27 | 28 | fs := (&FS{}).Init(client.Config, true) 29 | fs = fs.WithContext(context.TODO()).(*FS) 30 | f, err := fs.Open("remotefs_test") 31 | assert.NoError(err) 32 | rf, ok := f.(*ReadDirFile) 33 | assert.True(ok) 34 | entry, err := rf.ReadDir(0) 35 | assert.NoError(err) 36 | assert.Equal(1, len(entry)) 37 | assert.False(entry[0].IsDir()) 38 | info, err := entry[0].Info() 39 | assert.NoError(err) 40 | assert.Equal("1.text", info.Name()) 41 | fsFile, ok := entry[0].(*File) 42 | assert.True(ok) 43 | buf := make([]byte, 8) 44 | _, err = fsFile.Read(buf) 45 | assert.NoError(err) 46 | err = fsFile.Close() 47 | assert.NoError(err) 48 | assert.Equal("testing ", string(buf)) 49 | 50 | buf = make([]byte, 9) 51 | _, err = fsFile.Read(buf) 52 | assert.NoError(err) 53 | err = fsFile.Close() 54 | assert.NoError(err) 55 | 56 | assert.Equal("testing 3", string(buf)) 57 | 58 | _, err = fs.ReadDir(".") 59 | require.NoError(t, err) 60 | 61 | _, err = fs.Open(".") 62 | require.NoError(t, err) 63 | } 64 | -------------------------------------------------------------------------------- /preview.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type Preview struct { 10 | Id int64 `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"` 11 | Status string `json:"status,omitempty" path:"status,omitempty" url:"status,omitempty"` 12 | DownloadUri string `json:"download_uri,omitempty" path:"download_uri,omitempty" url:"download_uri,omitempty"` 13 | Type string `json:"type,omitempty" path:"type,omitempty" url:"type,omitempty"` 14 | Size string `json:"size,omitempty" path:"size,omitempty" url:"size,omitempty"` 15 | } 16 | 17 | func (p Preview) Identifier() interface{} { 18 | return p.Id 19 | } 20 | 21 | type PreviewCollection []Preview 22 | 23 | func (p *Preview) UnmarshalJSON(data []byte) error { 24 | type preview Preview 25 | var v preview 26 | if err := json.Unmarshal(data, &v); err != nil { 27 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 28 | } 29 | 30 | *p = Preview(v) 31 | return nil 32 | } 33 | 34 | func (p *PreviewCollection) UnmarshalJSON(data []byte) error { 35 | type previews PreviewCollection 36 | var v previews 37 | if err := json.Unmarshal(data, &v); err != nil { 38 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 39 | } 40 | 41 | *p = PreviewCollection(v) 42 | return nil 43 | } 44 | 45 | func (p *PreviewCollection) ToSlice() *[]interface{} { 46 | ret := make([]interface{}, len(*p)) 47 | for i, v := range *p { 48 | ret[i] = v 49 | } 50 | 51 | return &ret 52 | } 53 | -------------------------------------------------------------------------------- /lib/connection-stats.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "context" 5 | "net" 6 | "net/http" 7 | "sync" 8 | "sync/atomic" 9 | ) 10 | 11 | type Transport struct { 12 | *http.Transport 13 | *net.Dialer 14 | connections map[string]*int32 15 | mu sync.RWMutex 16 | } 17 | 18 | func (t *Transport) GetConnectionStats() map[string]int { 19 | t.mu.RLock() 20 | defer t.mu.RUnlock() // Keep the read lock for the entire function 21 | 22 | copiedMap := make(map[string]int) 23 | for key, value := range t.connections { 24 | copiedMap[key] = int(atomic.LoadInt32(value)) 25 | } 26 | return copiedMap 27 | } 28 | 29 | func (t *Transport) DialContext(ctx context.Context, network, address string) (net.Conn, error) { 30 | conn, err := t.Dialer.DialContext(ctx, network, address) 31 | 32 | if err == nil { 33 | t.mu.Lock() 34 | counter, ok := t.connections[address] 35 | if !ok { 36 | intCounter := int32(0) 37 | counter = &intCounter 38 | t.connections[address] = counter 39 | } 40 | t.mu.Unlock() 41 | atomic.AddInt32(counter, 1) 42 | return &Conn{Conn: conn, counter: counter}, err 43 | } 44 | 45 | return conn, err 46 | } 47 | 48 | type Conn struct { 49 | net.Conn 50 | counter *int32 51 | sync.Once 52 | } 53 | 54 | func (c *Conn) Close() (err error) { 55 | err = c.Conn.Close() 56 | c.Do(func() { atomic.AddInt32(c.counter, -1) }) 57 | 58 | return 59 | } 60 | 61 | func GetConnectionStatsFromClient(client *http.Client) (map[string]int, bool) { 62 | transport, ok := client.Transport.(*Transport) 63 | if !ok { 64 | return nil, false 65 | } 66 | return transport.GetConnectionStats(), true 67 | } 68 | -------------------------------------------------------------------------------- /fsmount/internal/cache/disk/disk_opt.go: -------------------------------------------------------------------------------- 1 | package disk 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/Files-com/files-sdk-go/v3/fsmount/internal/log" 7 | ) 8 | 9 | // Option configures a DiskCache. 10 | type Option func(*DiskCache) 11 | 12 | // WithCapacityBytes sets the maximum total size (in bytes) for the cache. 13 | func WithCapacityBytes(n int64) Option { 14 | return func(dc *DiskCache) { 15 | dc.Capacity = n 16 | } 17 | } 18 | 19 | // WithDisabled disables the cache (no I/O, no directory creation). 20 | func WithDisabled(disabled bool) Option { 21 | return func(dc *DiskCache) { 22 | dc.Disabled = disabled 23 | } 24 | } 25 | 26 | // WithMaxAge sets the maximum age for cache files. 27 | func WithMaxAge(d time.Duration) Option { 28 | return func(dc *DiskCache) { 29 | dc.MaxAge = d 30 | } 31 | } 32 | 33 | // WithMaxFileCount sets the maximum number of files for the cache. 34 | func WithMaxFileCount(n int64) Option { 35 | return func(dc *DiskCache) { 36 | dc.MaxFileCount = n 37 | } 38 | } 39 | 40 | // WithMaintenanceInterval sets the interval for cache maintenance operations. 41 | func WithMaintenanceInterval(d time.Duration) Option { 42 | return func(dc *DiskCache) { 43 | dc.MaintenanceInterval = d 44 | } 45 | } 46 | 47 | // WithLruFlushInterval sets the interval for cache maintenance operations. 48 | func WithLruFlushInterval(d time.Duration) Option { 49 | return func(dc *DiskCache) { 50 | dc.LruFlushInterval = d 51 | } 52 | } 53 | 54 | // WithLogger sets the logger for the cache. 55 | func WithLogger(logger log.Logger) Option { 56 | return func(dc *DiskCache) { 57 | dc.log = logger 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /paymentlineitem.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | "time" 6 | 7 | lib "github.com/Files-com/files-sdk-go/v3/lib" 8 | ) 9 | 10 | type PaymentLineItem struct { 11 | Amount string `json:"amount,omitempty" path:"amount,omitempty" url:"amount,omitempty"` 12 | CreatedAt *time.Time `json:"created_at,omitempty" path:"created_at,omitempty" url:"created_at,omitempty"` 13 | InvoiceId int64 `json:"invoice_id,omitempty" path:"invoice_id,omitempty" url:"invoice_id,omitempty"` 14 | PaymentId int64 `json:"payment_id,omitempty" path:"payment_id,omitempty" url:"payment_id,omitempty"` 15 | } 16 | 17 | // Identifier no path or id 18 | 19 | type PaymentLineItemCollection []PaymentLineItem 20 | 21 | func (p *PaymentLineItem) UnmarshalJSON(data []byte) error { 22 | type paymentLineItem PaymentLineItem 23 | var v paymentLineItem 24 | if err := json.Unmarshal(data, &v); err != nil { 25 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 26 | } 27 | 28 | *p = PaymentLineItem(v) 29 | return nil 30 | } 31 | 32 | func (p *PaymentLineItemCollection) UnmarshalJSON(data []byte) error { 33 | type paymentLineItems PaymentLineItemCollection 34 | var v paymentLineItems 35 | if err := json.Unmarshal(data, &v); err != nil { 36 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 37 | } 38 | 39 | *p = PaymentLineItemCollection(v) 40 | return nil 41 | } 42 | 43 | func (p *PaymentLineItemCollection) ToSlice() *[]interface{} { 44 | ret := make([]interface{}, len(*p)) 45 | for i, v := range *p { 46 | ret[i] = v 47 | } 48 | 49 | return &ret 50 | } 51 | -------------------------------------------------------------------------------- /publicipaddress.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type PublicIpAddress struct { 10 | IpAddress string `json:"ip_address,omitempty" path:"ip_address,omitempty" url:"ip_address,omitempty"` 11 | ServerName string `json:"server_name,omitempty" path:"server_name,omitempty" url:"server_name,omitempty"` 12 | FtpEnabled *bool `json:"ftp_enabled,omitempty" path:"ftp_enabled,omitempty" url:"ftp_enabled,omitempty"` 13 | SftpEnabled *bool `json:"sftp_enabled,omitempty" path:"sftp_enabled,omitempty" url:"sftp_enabled,omitempty"` 14 | } 15 | 16 | // Identifier no path or id 17 | 18 | type PublicIpAddressCollection []PublicIpAddress 19 | 20 | func (p *PublicIpAddress) UnmarshalJSON(data []byte) error { 21 | type publicIpAddress PublicIpAddress 22 | var v publicIpAddress 23 | if err := json.Unmarshal(data, &v); err != nil { 24 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 25 | } 26 | 27 | *p = PublicIpAddress(v) 28 | return nil 29 | } 30 | 31 | func (p *PublicIpAddressCollection) UnmarshalJSON(data []byte) error { 32 | type publicIpAddresss PublicIpAddressCollection 33 | var v publicIpAddresss 34 | if err := json.Unmarshal(data, &v); err != nil { 35 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 36 | } 37 | 38 | *p = PublicIpAddressCollection(v) 39 | return nil 40 | } 41 | 42 | func (p *PublicIpAddressCollection) ToSlice() *[]interface{} { 43 | ret := make([]interface{}, len(*p)) 44 | for i, v := range *p { 45 | ret[i] = v 46 | } 47 | 48 | return &ret 49 | } 50 | -------------------------------------------------------------------------------- /restore/client.go: -------------------------------------------------------------------------------- 1 | package restore 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) Restore() files_sdk.Restore { 23 | return i.Current().(files_sdk.Restore) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.RestoreListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/restores", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.RestoreCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.RestoreListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | 42 | func (c *Client) Create(params files_sdk.RestoreCreateParams, opts ...files_sdk.RequestResponseOption) (restore files_sdk.Restore, err error) { 43 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/restores", Params: params, Entity: &restore}, opts...) 44 | return 45 | } 46 | 47 | func Create(params files_sdk.RestoreCreateParams, opts ...files_sdk.RequestResponseOption) (restore files_sdk.Restore, err error) { 48 | return (&Client{}).Create(params, opts...) 49 | } 50 | -------------------------------------------------------------------------------- /lib/required.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "reflect" 7 | "strings" 8 | ) 9 | 10 | func CheckRequired(iStruct interface{}) error { 11 | var errors = make([]string, 0) 12 | val := reflect.ValueOf(iStruct) 13 | for val.Kind() == reflect.Ptr { 14 | if val.IsNil() { 15 | return nil 16 | } 17 | val = val.Elem() 18 | } 19 | 20 | if iStruct == nil { 21 | return nil 22 | } 23 | 24 | if val.Kind() == reflect.Map { 25 | return nil 26 | } 27 | 28 | if val.Kind() != reflect.Struct { 29 | return fmt.Errorf("CheckRequired expects struct input. Got %v", val.Kind()) 30 | } 31 | 32 | typ := val.Type() 33 | for i := 0; i < typ.NumField(); i++ { 34 | sf := typ.Field(i) 35 | if sf.PkgPath != "" && !sf.Anonymous { // unexported 36 | continue 37 | } 38 | tag := sf.Tag.Get("required") 39 | value := val.FieldByName(sf.Name) 40 | jsonValue, err := json.Marshal(value.Interface()) 41 | if err != nil { 42 | return err 43 | } 44 | 45 | if tag == "true" && (string(jsonValue) == "null" || string(jsonValue) == JSONEmptyValue(sf.Type)) { 46 | errors = append( 47 | errors, 48 | CreateError(iStruct, sf.Name).Error(), 49 | ) 50 | } 51 | } 52 | if len(errors) != 0 { 53 | return fmt.Errorf(strings.Join(errors, "\n")) 54 | } 55 | return nil 56 | } 57 | 58 | func CreateError(i interface{}, name string) error { 59 | structName := reflect.TypeOf(i).Name() 60 | return fmt.Errorf("missing required field: %v{}.%v", structName, name) 61 | } 62 | 63 | func JSONEmptyValue(v reflect.Type) string { 64 | switch v.Kind() { 65 | case reflect.Map, reflect.Struct: 66 | return "{}" 67 | case reflect.Slice: 68 | return "[]" 69 | case reflect.Int, reflect.Int64: 70 | return "0" 71 | case reflect.String: 72 | return `""` 73 | default: 74 | return "" 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /inboxrecipient/client.go: -------------------------------------------------------------------------------- 1 | package inbox_recipient 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) InboxRecipient() files_sdk.InboxRecipient { 23 | return i.Current().(files_sdk.InboxRecipient) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.InboxRecipientListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/inbox_recipients", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.InboxRecipientCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.InboxRecipientListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | 42 | func (c *Client) Create(params files_sdk.InboxRecipientCreateParams, opts ...files_sdk.RequestResponseOption) (inboxRecipient files_sdk.InboxRecipient, err error) { 43 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/inbox_recipients", Params: params, Entity: &inboxRecipient}, opts...) 44 | return 45 | } 46 | 47 | func Create(params files_sdk.InboxRecipientCreateParams, opts ...files_sdk.RequestResponseOption) (inboxRecipient files_sdk.InboxRecipient, err error) { 48 | return (&Client{}).Create(params, opts...) 49 | } 50 | -------------------------------------------------------------------------------- /bundlerecipient/client.go: -------------------------------------------------------------------------------- 1 | package bundle_recipient 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) BundleRecipient() files_sdk.BundleRecipient { 23 | return i.Current().(files_sdk.BundleRecipient) 24 | } 25 | 26 | func (c *Client) List(params files_sdk.BundleRecipientListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 27 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 28 | path, err := lib.BuildPath("/bundle_recipients", params) 29 | if err != nil { 30 | return i, err 31 | } 32 | i.ListParams = ¶ms 33 | list := files_sdk.BundleRecipientCollection{} 34 | i.Query = listquery.Build(c.Config, path, &list, opts...) 35 | return i, nil 36 | } 37 | 38 | func List(params files_sdk.BundleRecipientListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 39 | return (&Client{}).List(params, opts...) 40 | } 41 | 42 | func (c *Client) Create(params files_sdk.BundleRecipientCreateParams, opts ...files_sdk.RequestResponseOption) (bundleRecipient files_sdk.BundleRecipient, err error) { 43 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/bundle_recipients", Params: params, Entity: &bundleRecipient}, opts...) 44 | return 45 | } 46 | 47 | func Create(params files_sdk.BundleRecipientCreateParams, opts ...files_sdk.RequestResponseOption) (bundleRecipient files_sdk.BundleRecipient, err error) { 48 | return (&Client{}).Create(params, opts...) 49 | } 50 | -------------------------------------------------------------------------------- /ipaddress.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type IpAddress struct { 10 | Id string `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"` 11 | AssociatedWith string `json:"associated_with,omitempty" path:"associated_with,omitempty" url:"associated_with,omitempty"` 12 | GroupId int64 `json:"group_id,omitempty" path:"group_id,omitempty" url:"group_id,omitempty"` 13 | IpAddresses []string `json:"ip_addresses,omitempty" path:"ip_addresses,omitempty" url:"ip_addresses,omitempty"` 14 | } 15 | 16 | func (i IpAddress) Identifier() interface{} { 17 | return i.Id 18 | } 19 | 20 | type IpAddressCollection []IpAddress 21 | 22 | type IpAddressListParams struct { 23 | ListParams 24 | } 25 | 26 | type IpAddressGetSmartfileReservedParams struct { 27 | ListParams 28 | } 29 | 30 | type IpAddressGetExavaultReservedParams struct { 31 | ListParams 32 | } 33 | 34 | type IpAddressGetReservedParams struct { 35 | ListParams 36 | } 37 | 38 | func (i *IpAddress) UnmarshalJSON(data []byte) error { 39 | type ipAddress IpAddress 40 | var v ipAddress 41 | if err := json.Unmarshal(data, &v); err != nil { 42 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 43 | } 44 | 45 | *i = IpAddress(v) 46 | return nil 47 | } 48 | 49 | func (i *IpAddressCollection) UnmarshalJSON(data []byte) error { 50 | type ipAddresss IpAddressCollection 51 | var v ipAddresss 52 | if err := json.Unmarshal(data, &v); err != nil { 53 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 54 | } 55 | 56 | *i = IpAddressCollection(v) 57 | return nil 58 | } 59 | 60 | func (i *IpAddressCollection) ToSlice() *[]interface{} { 61 | ret := make([]interface{}, len(*i)) 62 | for i, v := range *i { 63 | ret[i] = v 64 | } 65 | 66 | return &ret 67 | } 68 | -------------------------------------------------------------------------------- /lib/path.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "strings" 7 | ) 8 | 9 | type Path struct { 10 | Path string 11 | Separator string 12 | } 13 | 14 | const ( 15 | URLPathSeparator = "/" 16 | ) 17 | 18 | func (p Path) PathSeparator() string { 19 | if p.Separator == "" { 20 | return string(os.PathSeparator) 21 | } 22 | 23 | return p.Separator 24 | } 25 | 26 | func (p Path) Pop() string { 27 | _, last := filepath.Split(strings.TrimSuffix(p.Path, p.PathSeparator())) 28 | return last 29 | } 30 | 31 | func (p Path) EndingSlash() bool { 32 | if p.Path == "" { 33 | return false 34 | } 35 | return p.Path[len(p.Path)-1:] == p.PathSeparator() 36 | } 37 | 38 | func (p Path) PruneStartingSlash() Path { 39 | if p.Path == "" { 40 | return p 41 | } 42 | 43 | if p.Path[0:1] == p.PathSeparator() { 44 | return Path{Path: p.Path[1:]} 45 | } 46 | return p 47 | } 48 | 49 | func (p Path) PruneEndingSlash() Path { 50 | if !p.EndingSlash() { 51 | return Path{Path: p.Path} 52 | } 53 | 54 | return Path{Path: p.Path[0 : len(p.Path)-1]} 55 | } 56 | 57 | func (p Path) ConvertEmptyToRoot() Path { 58 | if p.Path == "" { 59 | return Path{Path: "."} 60 | } 61 | 62 | return p 63 | } 64 | 65 | func (p Path) Join(str ...string) Path { 66 | return Path{Path: filepath.Join(p.String(), filepath.Join(str...))} 67 | } 68 | 69 | func (p Path) String() string { 70 | return p.Path 71 | } 72 | 73 | func (p Path) NormalizePathSystemForAPI() Path { 74 | return NewUrlPath(UrlJoinNoEscape(strings.Split(filepath.Clean(p.Path), p.PathSeparator())...)).PruneStartingSlash() 75 | } 76 | 77 | func (p Path) SwitchPathSeparator(separator string) Path { 78 | return Path{Path: strings.Join(strings.Split(p.Path, p.PathSeparator()), separator), Separator: separator} 79 | } 80 | 81 | func NewUrlPath(path string) Path { 82 | return Path{ 83 | Path: path, 84 | Separator: URLPathSeparator, 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /status.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type Status struct { 10 | Code int64 `json:"code,omitempty" path:"code,omitempty" url:"code,omitempty"` 11 | Message string `json:"message,omitempty" path:"message,omitempty" url:"message,omitempty"` 12 | Status string `json:"status,omitempty" path:"status,omitempty" url:"status,omitempty"` 13 | Data Auto `json:"data,omitempty" path:"data,omitempty" url:"data,omitempty"` 14 | Errors []map[string]interface{} `json:"errors,omitempty" path:"errors,omitempty" url:"errors,omitempty"` 15 | ClickwrapId int64 `json:"clickwrap_id,omitempty" path:"clickwrap_id,omitempty" url:"clickwrap_id,omitempty"` 16 | ClickwrapBody string `json:"clickwrap_body,omitempty" path:"clickwrap_body,omitempty" url:"clickwrap_body,omitempty"` 17 | } 18 | 19 | // Identifier no path or id 20 | 21 | type StatusCollection []Status 22 | 23 | func (s *Status) UnmarshalJSON(data []byte) error { 24 | type status Status 25 | var v status 26 | if err := json.Unmarshal(data, &v); err != nil { 27 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 28 | } 29 | 30 | *s = Status(v) 31 | return nil 32 | } 33 | 34 | func (s *StatusCollection) UnmarshalJSON(data []byte) error { 35 | type statuss StatusCollection 36 | var v statuss 37 | if err := json.Unmarshal(data, &v); err != nil { 38 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 39 | } 40 | 41 | *s = StatusCollection(v) 42 | return nil 43 | } 44 | 45 | func (s *StatusCollection) ToSlice() *[]interface{} { 46 | ret := make([]interface{}, len(*s)) 47 | for i, v := range *s { 48 | ret[i] = v 49 | } 50 | 51 | return &ret 52 | } 53 | -------------------------------------------------------------------------------- /filemigration/fixtures/TestClient_Wait.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 1 3 | interactions: 4 | - request: 5 | headers: 6 | url: https://app.files.com/api/rest/v1/file_migrations/11 7 | method: GET 8 | response: 9 | body: '{"error":"Not Found","http-code":404,"instance":"3501f0de-daec-4ee2-b152-416e1637ec91","title":"Not 10 | Found","type":"not-found"}' 11 | headers: 12 | Content-Type: 13 | - application/json 14 | status: 404 Not Found 15 | code: 404 16 | - request: 17 | headers: 18 | url: https://app.files.com/api/rest/v1/file_migrations/12 19 | method: GET 20 | response: 21 | body: '{"id":12,"path":"video.mp4","dest_path":"video-2.mp4","operation":"copy","status":"completed"}' 22 | headers: 23 | Content-Type: 24 | - application/json 25 | status: 200 Ok 26 | code: 200 27 | - request: 28 | headers: 29 | url: https://app.files.com/api/rest/v1/file_migrations/14 30 | method: GET 31 | response: 32 | body: '{"id":14,"path":"video.mp4","dest_path":"video-2.mp4","operation":"copy","status":"failed"}' 33 | headers: 34 | Content-Type: 35 | - application/json 36 | status: 200 Ok 37 | code: 200 38 | - request: 39 | headers: 40 | url: https://app.files.com/api/rest/v1/file_migrations/15 41 | method: GET 42 | response: 43 | body: '{"id":15,"path":"video.mp4","dest_path":"video-2.mp4","operation":"copy","status":"in_progress"}' 44 | headers: 45 | Content-Type: 46 | - application/json 47 | status: 200 Ok 48 | code: 200 49 | - request: 50 | headers: 51 | url: https://app.files.com/api/rest/v1/file_migrations/15 52 | method: GET 53 | response: 54 | body: '{"id":15,"path":"video.mp4","dest_path":"video-2.mp4","operation":"copy","status":"completed"}' 55 | headers: 56 | Content-Type: 57 | - application/json 58 | status: 200 Ok 59 | code: 200 60 | 61 | -------------------------------------------------------------------------------- /lib/normalizeforcomparison.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "strings" 5 | "unicode" 6 | 7 | "golang.org/x/text/unicode/norm" 8 | ) 9 | 10 | var transliterationMap map[rune]string 11 | 12 | func init() { 13 | transliterationMapString := "ÀA,ÁA,ÂA,ÃA,ÄA,ÅA,ÆAE,ÇC,ÈE,ÉE,ÊE,ËE,ÌI,ÍI,ÎI,ÏI,ÐD,ÑN,ÒO,ÓO,ÔO,ÕO,ÖO,ØO,ÙU,ÚU,ÛU,ÜU,ÝY,ßss,àa,áa,âa,ãa,äa,åa,æae,çc,èe,ée,êe,ëe,ìi,íi,îi,ïi,ðd,ñn,òo,óo,ôo,õo,öo,øo,ùu,úu,ûu,üu,ýy,ÿy,ĀA,āa,ĂA,ăa,ĄA,ąa,ĆC,ćc,ĈC,ĉc,ĊC,ċc,ČC,čc,ĎD,ďd,ĐD,đd,ĒE,ēe,ĔE,ĕe,ĖE,ėe,ĘE,ęe,ĚE,ěe,ĜG,ĝg,ĞG,ğg,ĠG,ġg,ĢG,ģg,ĤH,ĥh,ĦH,ħh,ĨI,ĩi,ĪI,īi,ĬI,ĭi,ĮI,įi,İI,IJIJ,ijij,ĴJ,ĵj,ĶK,ķk,ĹL,ĺl,ĻL,ļl,ĽL,ľl,ŁL,łl,ŃN,ńn,ŅN,ņn,ŇN,ňn,ʼn'n,ŌO,ōo,ŎO,ŏo,ŐO,őo,ŒOE,œoe,ŔR,ŕr,ŖR,ŗr,ŘR,řr,ŚS,śs,ŜS,ŝs,ŞS,şs,ŠS,šs,ŢT,ţt,ŤT,ťt,ŨU,ũu,ŪU,ūu,ŬU,ŭu,ŮU,ůu,ŰU,űu,ŲU,ųu,ŴW,ŵw,ŶY,ŷy,ŸY,ŹZ,źz,ŻZ,żz,ŽZ,žz" 14 | transliterationMap = make(map[rune]string) 15 | pairs := strings.Split(transliterationMapString, ",") 16 | 17 | for _, pair := range pairs { 18 | runes := []rune(pair) 19 | transliterationMap[runes[0]] = string(runes[1:]) 20 | } 21 | } 22 | 23 | func transliterate(r rune, transliterationMap map[rune]string) string { 24 | if result, ok := transliterationMap[r]; ok { 25 | return result 26 | } 27 | return string(r) 28 | } 29 | 30 | func NormalizeForComparison(path string) string { 31 | // Normalize Algorithm 32 | path = strings.ReplaceAll(path, "\x00", "") 33 | path = strings.ReplaceAll(path, "\\", "/") 34 | path = strings.Trim(path, "/") 35 | path = strings.Join(strings.FieldsFunc(path, func(r rune) bool { return r == '/' }), "/") 36 | 37 | // Normalize For Comparison Algorithm 38 | path = norm.NFKC.String(path) 39 | 40 | var transliteratedPath strings.Builder 41 | for _, r := range path { 42 | transliteratedPath.WriteString(transliterate(r, transliterationMap)) 43 | } 44 | path = strings.Map(unicode.ToLower, transliteratedPath.String()) 45 | 46 | path = strings.TrimRightFunc(path, unicode.IsSpace) 47 | 48 | return path 49 | } 50 | -------------------------------------------------------------------------------- /file/tmpdownloadpath_nondarwin_test.go: -------------------------------------------------------------------------------- 1 | //go:build !darwin 2 | 3 | package file 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "path/filepath" 9 | "testing" 10 | 11 | "github.com/stretchr/testify/assert" 12 | "github.com/stretchr/testify/require" 13 | ) 14 | 15 | func Test_tmpDownloadPath(t *testing.T) { 16 | t.Run("base case", func(t *testing.T) { 17 | dir := t.TempDir() 18 | path, err := tmpDownloadPath(filepath.Join(dir, "you-wont-find-me"), "") 19 | require.NoError(t, err) 20 | assert.Equal(t, filepath.Join(dir, "you-wont-find-me.download"), path) 21 | }) 22 | 23 | t.Run("it increments a number", func(t *testing.T) { 24 | dir := t.TempDir() 25 | file, err := os.Create(filepath.Join(dir, "find-me.download")) 26 | _, err = file.Write([]byte("hello")) 27 | require.NoError(t, err) 28 | err = file.Close() 29 | if err != nil { 30 | panic(err) 31 | } 32 | path, err := tmpDownloadPath(filepath.Join(dir, "find-me"), "") 33 | require.NoError(t, err) 34 | assert.Equal(t, fmt.Sprintf(filepath.Join(dir, "find-me (1).download")), path, "it increments a number") 35 | }) 36 | 37 | t.Run("it increments a number lots of times", func(t *testing.T) { 38 | dir := t.TempDir() 39 | for i := 0; i < 11; i++ { 40 | path, err := tmpDownloadPath(filepath.Join(dir, "find-me"), "") 41 | require.NoError(t, err) 42 | file, err := os.Create(path) 43 | require.NoError(t, err) 44 | file.Close() 45 | } 46 | 47 | path, err := tmpDownloadPath(filepath.Join(dir, "find-me"), "") 48 | require.NoError(t, err) 49 | assert.NotEqual(t, fmt.Sprintf(filepath.Join(dir, "find-me (11).download")), path) 50 | }) 51 | 52 | t.Run("it supports a temp path", func(t *testing.T) { 53 | dir := t.TempDir() 54 | tempDir := t.TempDir() 55 | path, err := tmpDownloadPath(filepath.Join(dir, "find-me"), tempDir) 56 | require.NoError(t, err) 57 | assert.Equal(t, fmt.Sprintf(filepath.Join(tempDir, "find-me.download")), path) 58 | }) 59 | } 60 | -------------------------------------------------------------------------------- /lib/logger.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type NullLogger struct{} 8 | 9 | func (n NullLogger) Printf(_ string, _ ...any) {} 10 | 11 | type Logger interface { 12 | Printf(string, ...any) 13 | } 14 | 15 | type LeveledLogger interface { 16 | Error(string, ...any) 17 | Warn(string, ...any) 18 | Info(string, ...any) 19 | Debug(string, ...any) 20 | Trace(string, ...any) 21 | } 22 | 23 | type loggerWrapper struct { 24 | Logger 25 | } 26 | 27 | func NewLeveledLogger(logger Logger) LeveledLogger { 28 | return &loggerWrapper{logger} 29 | } 30 | 31 | func (l *loggerWrapper) Error(format string, args ...any) { 32 | l.logWithLevel("ERROR", format, args...) 33 | } 34 | 35 | func (l *loggerWrapper) Warn(format string, args ...any) { 36 | l.logWithLevel("WARN", format, args...) 37 | } 38 | 39 | func (l *loggerWrapper) Info(format string, args ...any) { 40 | l.logWithLevel("INFO", format, args...) 41 | } 42 | 43 | func (l *loggerWrapper) Debug(format string, args ...any) { 44 | l.logWithLevel("DEBUG", format, args...) 45 | } 46 | 47 | func (l *loggerWrapper) Trace(format string, args ...any) { 48 | l.logWithLevel("TRACE", format, args...) 49 | } 50 | 51 | func (l *loggerWrapper) logWithLevel(level string, format string, args ...any) { 52 | if levelLogger, ok := l.Logger.(LeveledLogger); ok { 53 | switch level { 54 | case "ERROR": 55 | levelLogger.Error(format, args...) 56 | case "WARN": 57 | levelLogger.Warn(format, args...) 58 | case "INFO": 59 | levelLogger.Info(format, args...) 60 | case "DEBUG": 61 | levelLogger.Debug(format, args...) 62 | case "TRACE": 63 | levelLogger.Trace(format, args...) 64 | default: 65 | l.log(level, format, args...) 66 | } 67 | return 68 | } 69 | 70 | l.log(level, format, args...) 71 | } 72 | 73 | func (l *loggerWrapper) log(level string, format string, args ...any) { 74 | format = fmt.Sprintf("[%v] %v", level, format) 75 | l.Printf(format, args...) 76 | } 77 | -------------------------------------------------------------------------------- /file/fixtures/TestClient_DownloadToFile_No_files.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 1 3 | interactions: 4 | - request: 5 | body: '{}' 6 | form: {} 7 | headers: 8 | Content-Type: 9 | - application/json 10 | User-Agent: 11 | - Files.com Go SDK 12 | url: https://app.files.com/api/rest/v1/folders/empty%20folder 13 | method: POST 14 | response: 15 | body: '{"error":"The destination exists.","http-code":422,"instance":"cae19bec-1c87-4818-b269-139ed215848c","title":"Destination 16 | Exists","type":"processing-failure/destination-exists"}' 17 | headers: 18 | Cache-Control: 19 | - no-cache, no-store, max-age=0, must-revalidate 20 | Content-Length: 21 | - "177" 22 | Content-Type: 23 | - application/json 24 | Date: 25 | - Thu, 27 May 2021 15:57:15 GMT 26 | Expires: 27 | - Fri, 01 Jan 1990 00:00:00 GMT 28 | Pragma: 29 | - no-cache 30 | Server: 31 | - nginx 32 | X-Request-Id: 33 | - cae19bec-1c87-4818-b269-139ed215848c 34 | status: 422 Unprocessable Entity 35 | code: 422 36 | duration: "" 37 | - request: 38 | body: "" 39 | form: {} 40 | headers: 41 | User-Agent: 42 | - Files.com Go SDK 43 | url: https://app.files.com/api/rest/v1/folders/empty%20folder 44 | method: GET 45 | response: 46 | body: '[]' 47 | headers: 48 | Cache-Control: 49 | - no-cache, no-store, max-age=0, must-revalidate 50 | Content-Length: 51 | - "2" 52 | Content-Type: 53 | - application/json 54 | Date: 55 | - Thu, 27 May 2021 15:57:15 GMT 56 | Expires: 57 | - Fri, 01 Jan 1990 00:00:00 GMT 58 | Pragma: 59 | - no-cache 60 | Server: 61 | - nginx 62 | X-Files-Cached-Response: 63 | - "1622129278" 64 | X-Request-Id: 65 | - ea1c89fd-9193-4255-ac40-f84901437d2c 66 | status: 200 OK 67 | code: 200 68 | duration: "" 69 | -------------------------------------------------------------------------------- /fsmount/internal/cache/ready.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "context" 5 | "io" 6 | "sync" 7 | ) 8 | 9 | // ReadyGate manages blocking cache consumers until the requested data is available. 10 | type ReadyGate struct { 11 | mu sync.Mutex 12 | cond *sync.Cond 13 | available int64 // bytes [0, available) present contiguously 14 | total int64 // -1 unknown 15 | err error 16 | done bool 17 | waiters int 18 | Cancel context.CancelFunc 19 | } 20 | 21 | func NewReadyGate() *ReadyGate { 22 | gate := &ReadyGate{total: -1} 23 | gate.cond = sync.NewCond(&gate.mu) 24 | return gate 25 | } 26 | 27 | func (gate *ReadyGate) Add() { 28 | gate.mu.Lock() 29 | gate.waiters++ 30 | gate.mu.Unlock() 31 | } 32 | 33 | func (gate *ReadyGate) Done() { 34 | gate.mu.Lock() 35 | if gate.waiters > 0 { 36 | gate.waiters-- 37 | } 38 | gate.mu.Unlock() 39 | } 40 | 41 | func (gate *ReadyGate) SetAvailable(x int64) { 42 | gate.mu.Lock() 43 | if x > gate.available { 44 | gate.available = x 45 | } 46 | gate.cond.Broadcast() 47 | gate.mu.Unlock() 48 | } 49 | 50 | func (gate *ReadyGate) SetCancel(cancel context.CancelFunc) { 51 | gate.mu.Lock() 52 | gate.Cancel = cancel 53 | gate.mu.Unlock() 54 | } 55 | 56 | func (gate *ReadyGate) Finish(err error, total int64) { 57 | gate.mu.Lock() 58 | gate.err, gate.done = err, true 59 | if total >= 0 { 60 | gate.total = total 61 | } 62 | gate.cond.Broadcast() 63 | gate.mu.Unlock() 64 | } 65 | 66 | func (gate *ReadyGate) WaitFor(end int64) error { 67 | gate.mu.Lock() 68 | defer gate.mu.Unlock() 69 | for { 70 | if gate.available >= end { 71 | return nil 72 | } 73 | if gate.done { 74 | if gate.err != nil { 75 | return gate.err 76 | } 77 | return io.EOF // smaller than requested 78 | } 79 | gate.cond.Wait() 80 | } 81 | } 82 | 83 | func (gate *ReadyGate) Available() int64 { 84 | gate.mu.Lock() 85 | defer gate.mu.Unlock() 86 | return gate.available 87 | } 88 | -------------------------------------------------------------------------------- /filemigration/client.go: -------------------------------------------------------------------------------- 1 | package file_migration 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | files_sdk "github.com/Files-com/files-sdk-go/v3" 8 | lib "github.com/Files-com/files-sdk-go/v3/lib" 9 | ) 10 | 11 | type Client struct { 12 | files_sdk.Config 13 | } 14 | 15 | func (c *Client) Find(params files_sdk.FileMigrationFindParams, opts ...files_sdk.RequestResponseOption) (fileMigration files_sdk.FileMigration, err error) { 16 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/file_migrations/{id}", Params: params, Entity: &fileMigration}, opts...) 17 | return 18 | } 19 | 20 | func Find(params files_sdk.FileMigrationFindParams, opts ...files_sdk.RequestResponseOption) (fileMigration files_sdk.FileMigration, err error) { 21 | return (&Client{}).Find(params, opts...) 22 | } 23 | 24 | func (c *Client) Wait(fileAction files_sdk.FileAction, status func(files_sdk.FileMigration), opts ...files_sdk.RequestResponseOption) (files_sdk.FileMigration, error) { 25 | var err error 26 | var migration files_sdk.FileMigration 27 | migration.Status = fileAction.Status 28 | migration.Id = fileAction.FileMigrationId 29 | ctx := files_sdk.ContextOption(opts) 30 | 31 | if migration.Status == "completed" || migration.Status == "failed" || err != nil { 32 | return migration, nil 33 | } 34 | for { 35 | migration, err = c.Find(files_sdk.FileMigrationFindParams{Id: fileAction.FileMigrationId}, opts...) 36 | if err == nil { 37 | status(migration) 38 | } 39 | if migration.Status == "completed" || migration.Status == "failed" || err != nil { 40 | return migration, err 41 | } 42 | select { 43 | case <-ctx.Done(): 44 | return migration, ctx.Err() 45 | case <-time.After(time.Second * 1): 46 | default: 47 | } 48 | } 49 | } 50 | 51 | func (c *Client) LogIterator(ctx context.Context, f files_sdk.FileMigration) files_sdk.IterI { 52 | return files_sdk.FilesMigrationLogIter{FileMigration: f, Context: ctx, Config: c.Config}.Init() 53 | } 54 | -------------------------------------------------------------------------------- /site/client.go: -------------------------------------------------------------------------------- 1 | package site 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | ) 7 | 8 | type Client struct { 9 | files_sdk.Config 10 | } 11 | 12 | func (c *Client) Get(opts ...files_sdk.RequestResponseOption) (site files_sdk.Site, err error) { 13 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/site", Entity: &site}, opts...) 14 | return 15 | } 16 | 17 | func Get(opts ...files_sdk.RequestResponseOption) (site files_sdk.Site, err error) { 18 | return (&Client{}).Get(opts...) 19 | } 20 | 21 | func (c *Client) GetUsage(opts ...files_sdk.RequestResponseOption) (usageSnapshot files_sdk.UsageSnapshot, err error) { 22 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/site/usage", Entity: &usageSnapshot}, opts...) 23 | return 24 | } 25 | 26 | func GetUsage(opts ...files_sdk.RequestResponseOption) (usageSnapshot files_sdk.UsageSnapshot, err error) { 27 | return (&Client{}).GetUsage(opts...) 28 | } 29 | 30 | func (c *Client) Update(params files_sdk.SiteUpdateParams, opts ...files_sdk.RequestResponseOption) (site files_sdk.Site, err error) { 31 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "PATCH", Path: "/site", Params: params, Entity: &site}, opts...) 32 | return 33 | } 34 | 35 | func Update(params files_sdk.SiteUpdateParams, opts ...files_sdk.RequestResponseOption) (site files_sdk.Site, err error) { 36 | return (&Client{}).Update(params, opts...) 37 | } 38 | 39 | func (c *Client) UpdateWithMap(params map[string]interface{}, opts ...files_sdk.RequestResponseOption) (site files_sdk.Site, err error) { 40 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "PATCH", Path: "/site", Params: params, Entity: &site}, opts...) 41 | return 42 | } 43 | 44 | func UpdateWithMap(params map[string]interface{}, opts ...files_sdk.RequestResponseOption) (site files_sdk.Site, err error) { 45 | return (&Client{}).UpdateWithMap(params, opts...) 46 | } 47 | -------------------------------------------------------------------------------- /file/tmpdownloadpath_darwin_test.go: -------------------------------------------------------------------------------- 1 | //go:build darwin 2 | 3 | package file 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "path/filepath" 9 | "testing" 10 | 11 | "github.com/stretchr/testify/assert" 12 | "github.com/stretchr/testify/require" 13 | ) 14 | 15 | func Test_tmpDownloadPath(t *testing.T) { 16 | t.Run("base case", func(t *testing.T) { 17 | dir := t.TempDir() 18 | path, err := tmpDownloadPath(filepath.Join(dir, "you-wont-find-me"), "") 19 | require.NoError(t, err) 20 | assert.Equal(t, filepath.Join(dir, "you-wont-find-me.download/you-wont-find-me"), path) 21 | }) 22 | 23 | t.Run("it increments a number", func(t *testing.T) { 24 | dir := t.TempDir() 25 | file, err := os.Create(filepath.Join(dir, "find-me.download")) 26 | _, err = file.Write([]byte("hello")) 27 | require.NoError(t, err) 28 | err = file.Close() 29 | if err != nil { 30 | panic(err) 31 | } 32 | path, err := tmpDownloadPath(filepath.Join(dir, "find-me"), "") 33 | require.NoError(t, err) 34 | assert.Equal(t, fmt.Sprintf(filepath.Join(dir, "find-me (1).download/find-me")), path, "it increments a number") 35 | }) 36 | 37 | t.Run("it increments a number lots of times", func(t *testing.T) { 38 | dir := t.TempDir() 39 | for i := 0; i < 11; i++ { 40 | path, err := tmpDownloadPath(filepath.Join(dir, "find-me"), "") 41 | require.NoError(t, err) 42 | file, err := os.Create(path) 43 | require.NoError(t, err) 44 | file.Close() 45 | } 46 | 47 | path, err := tmpDownloadPath(filepath.Join(dir, "find-me"), "") 48 | require.NoError(t, err) 49 | assert.NotEqual(t, fmt.Sprintf(filepath.Join(dir, "find-me (11).download/find-me")), path) 50 | }) 51 | 52 | t.Run("it supports a temp path", func(t *testing.T) { 53 | dir := t.TempDir() 54 | tempDir := t.TempDir() 55 | path, err := tmpDownloadPath(filepath.Join(dir, "find-me"), tempDir) 56 | require.NoError(t, err) 57 | assert.Equal(t, fmt.Sprintf(filepath.Join(tempDir, "find-me.download/find-me")), path) 58 | }) 59 | } 60 | -------------------------------------------------------------------------------- /project.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type Project struct { 10 | Id int64 `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"` 11 | GlobalAccess string `json:"global_access,omitempty" path:"global_access,omitempty" url:"global_access,omitempty"` 12 | } 13 | 14 | func (p Project) Identifier() interface{} { 15 | return p.Id 16 | } 17 | 18 | type ProjectCollection []Project 19 | 20 | type ProjectListParams struct { 21 | ListParams 22 | } 23 | 24 | type ProjectFindParams struct { 25 | Id int64 `url:"-,omitempty" json:"-,omitempty" path:"id"` 26 | } 27 | 28 | type ProjectCreateParams struct { 29 | GlobalAccess string `url:"global_access" json:"global_access" path:"global_access"` 30 | } 31 | 32 | type ProjectUpdateParams struct { 33 | Id int64 `url:"-,omitempty" json:"-,omitempty" path:"id"` 34 | GlobalAccess string `url:"global_access" json:"global_access" path:"global_access"` 35 | } 36 | 37 | type ProjectDeleteParams struct { 38 | Id int64 `url:"-,omitempty" json:"-,omitempty" path:"id"` 39 | } 40 | 41 | func (p *Project) UnmarshalJSON(data []byte) error { 42 | type project Project 43 | var v project 44 | if err := json.Unmarshal(data, &v); err != nil { 45 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 46 | } 47 | 48 | *p = Project(v) 49 | return nil 50 | } 51 | 52 | func (p *ProjectCollection) UnmarshalJSON(data []byte) error { 53 | type projects ProjectCollection 54 | var v projects 55 | if err := json.Unmarshal(data, &v); err != nil { 56 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 57 | } 58 | 59 | *p = ProjectCollection(v) 60 | return nil 61 | } 62 | 63 | func (p *ProjectCollection) ToSlice() *[]interface{} { 64 | ret := make([]interface{}, len(*p)) 65 | for i, v := range *p { 66 | ret[i] = v 67 | } 68 | 69 | return &ret 70 | } 71 | -------------------------------------------------------------------------------- /style.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | 7 | lib "github.com/Files-com/files-sdk-go/v3/lib" 8 | ) 9 | 10 | type Style struct { 11 | Id int64 `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"` 12 | Path string `json:"path,omitempty" path:"path,omitempty" url:"path,omitempty"` 13 | Logo Image `json:"logo,omitempty" path:"logo,omitempty" url:"logo,omitempty"` 14 | Thumbnail Image `json:"thumbnail,omitempty" path:"thumbnail,omitempty" url:"thumbnail,omitempty"` 15 | File io.Reader `json:"file,omitempty" path:"file,omitempty" url:"file,omitempty"` 16 | } 17 | 18 | func (s Style) Identifier() interface{} { 19 | return s.Id 20 | } 21 | 22 | type StyleCollection []Style 23 | 24 | type StyleFindParams struct { 25 | Path string `url:"-,omitempty" json:"-,omitempty" path:"path"` 26 | } 27 | 28 | type StyleUpdateParams struct { 29 | Path string `url:"-,omitempty" json:"-,omitempty" path:"path"` 30 | File io.Writer `url:"file" json:"file" path:"file"` 31 | } 32 | 33 | type StyleDeleteParams struct { 34 | Path string `url:"-,omitempty" json:"-,omitempty" path:"path"` 35 | } 36 | 37 | func (s *Style) UnmarshalJSON(data []byte) error { 38 | type style Style 39 | var v style 40 | if err := json.Unmarshal(data, &v); err != nil { 41 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 42 | } 43 | 44 | *s = Style(v) 45 | return nil 46 | } 47 | 48 | func (s *StyleCollection) UnmarshalJSON(data []byte) error { 49 | type styles StyleCollection 50 | var v styles 51 | if err := json.Unmarshal(data, &v); err != nil { 52 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 53 | } 54 | 55 | *s = StyleCollection(v) 56 | return nil 57 | } 58 | 59 | func (s *StyleCollection) ToSlice() *[]interface{} { 60 | ret := make([]interface{}, len(*s)) 61 | for i, v := range *s { 62 | ret[i] = v 63 | } 64 | 65 | return &ret 66 | } 67 | -------------------------------------------------------------------------------- /usersftpclientuse.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | "time" 6 | 7 | lib "github.com/Files-com/files-sdk-go/v3/lib" 8 | ) 9 | 10 | type UserSftpClientUse struct { 11 | Id int64 `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"` 12 | SftpClient string `json:"sftp_client,omitempty" path:"sftp_client,omitempty" url:"sftp_client,omitempty"` 13 | CreatedAt *time.Time `json:"created_at,omitempty" path:"created_at,omitempty" url:"created_at,omitempty"` 14 | UpdatedAt *time.Time `json:"updated_at,omitempty" path:"updated_at,omitempty" url:"updated_at,omitempty"` 15 | UserId int64 `json:"user_id,omitempty" path:"user_id,omitempty" url:"user_id,omitempty"` 16 | } 17 | 18 | func (u UserSftpClientUse) Identifier() interface{} { 19 | return u.Id 20 | } 21 | 22 | type UserSftpClientUseCollection []UserSftpClientUse 23 | 24 | type UserSftpClientUseListParams struct { 25 | UserId int64 `url:"user_id,omitempty" json:"user_id,omitempty" path:"user_id"` 26 | ListParams 27 | } 28 | 29 | func (u *UserSftpClientUse) UnmarshalJSON(data []byte) error { 30 | type userSftpClientUse UserSftpClientUse 31 | var v userSftpClientUse 32 | if err := json.Unmarshal(data, &v); err != nil { 33 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 34 | } 35 | 36 | *u = UserSftpClientUse(v) 37 | return nil 38 | } 39 | 40 | func (u *UserSftpClientUseCollection) UnmarshalJSON(data []byte) error { 41 | type userSftpClientUses UserSftpClientUseCollection 42 | var v userSftpClientUses 43 | if err := json.Unmarshal(data, &v); err != nil { 44 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 45 | } 46 | 47 | *u = UserSftpClientUseCollection(v) 48 | return nil 49 | } 50 | 51 | func (u *UserSftpClientUseCollection) ToSlice() *[]interface{} { 52 | ret := make([]interface{}, len(*u)) 53 | for i, v := range *u { 54 | ret[i] = v 55 | } 56 | 57 | return &ret 58 | } 59 | -------------------------------------------------------------------------------- /fsmount/localfs_linux.go: -------------------------------------------------------------------------------- 1 | //go:build linux 2 | // +build linux 3 | 4 | package fsmount 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | "time" 10 | 11 | "github.com/winfsp/cgofuse/fuse" 12 | ) 13 | 14 | func (fs *LocalFs) Getattr(path string, stat *fuse.Stat_t, fh uint64) (errc int) { 15 | fq := fs.fqPath(path) 16 | stgo := syscall.Stat_t{} 17 | if err := syscall.Lstat(path, &stgo); err != nil { 18 | if !os.IsNotExist(err) { 19 | fs.log.Trace("LocalFs: Getattr: failed to lstat file: path=%v, fh=%v, err=%v", fq, fh, err) 20 | return -fuse.EIO 21 | } 22 | fs.log.Trace("LocalFs: Getattr: file not found: path=%v, fh=%v", fq, fh) 23 | return -fuse.ENOENT 24 | } 25 | stat.Dev = uint64(stgo.Dev) 26 | stat.Ino = uint64(stgo.Ino) 27 | stat.Mode = uint32(stgo.Mode) 28 | stat.Nlink = uint32(stgo.Nlink) 29 | stat.Uid = uint32(stgo.Uid) 30 | stat.Gid = uint32(stgo.Gid) 31 | stat.Rdev = uint64(stgo.Rdev) 32 | stat.Size = int64(stgo.Size) 33 | stat.Atim.Sec, stat.Atim.Nsec = stgo.Atim.Sec, stgo.Atim.Nsec 34 | stat.Mtim.Sec, stat.Mtim.Nsec = stgo.Mtim.Sec, stgo.Mtim.Nsec 35 | stat.Ctim.Sec, stat.Ctim.Nsec = stgo.Ctim.Sec, stgo.Ctim.Nsec 36 | stat.Blksize = int64(stgo.Blksize) 37 | stat.Blocks = int64(stgo.Blocks) 38 | 39 | fs.log.Trace("LocalFs: Getattr: path=%v, stat=%v, fh=%v", fq, stat, fh) 40 | return errc 41 | } 42 | 43 | func (fs *LocalFs) createLocalNode(path string, entry os.DirEntry) (*fsNode, error) { 44 | var nt nodeType 45 | if entry.IsDir() { 46 | nt = nodeTypeDir 47 | } else { 48 | nt = nodeTypeFile 49 | } 50 | info, err := entry.Info() 51 | if err != nil { 52 | return nil, err 53 | } 54 | var creationTime time.Time 55 | // TODO: double check this on linux 56 | // On linux, os.FileInfo does not provide creation time 57 | node := fs.vfs.getOrCreate(path, nt) 58 | node.updateInfo(fsNodeInfo{ 59 | nodeType: nt, 60 | size: info.Size(), 61 | modTime: info.ModTime(), 62 | creationTime: creationTime, 63 | }) 64 | 65 | return node, nil 66 | } 67 | -------------------------------------------------------------------------------- /lib/params_test.go: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | import ( 4 | "io" 5 | "net/url" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | type SubStruct struct { 12 | C string `json:"c" url:"c"` 13 | } 14 | 15 | type ParamsStructExample struct { 16 | A string `json:"a" url:"a" required:"true"` 17 | B string `json:"-" url:"-"` 18 | C []SubStruct `json:"sub" url:"sub"` 19 | D []string `json:"d" url:"d" required:"true"` 20 | E []string `json:"e,omitempty" url:"e,omitempty" required:"false"` 21 | } 22 | 23 | func Test_Params_ToJSON(t *testing.T) { 24 | p := Params{ 25 | Params: ParamsStructExample{ 26 | A: "The a value", 27 | B: "The b value", 28 | C: []SubStruct{{C: "the c value"}}, 29 | D: []string{"hello"}, 30 | }, 31 | } 32 | 33 | reader, err := p.ToJSON() 34 | assert.NoError(t, err) 35 | 36 | b, err := io.ReadAll(reader) 37 | assert.NoError(t, err) 38 | assert.Equal(t, "{\"a\":\"The a value\",\"d\":[\"hello\"],\"sub\":[{\"c\":\"the c value\"}]}", string(b)) 39 | } 40 | 41 | func Test_Params_ToJSON_Missing_Require(t *testing.T) { 42 | p := Params{ 43 | Params: ParamsStructExample{ 44 | A: "The a value", 45 | B: "The b value", 46 | C: []SubStruct{{C: "the c value"}}, 47 | }, 48 | } 49 | 50 | _, err := p.ToJSON() 51 | assert.Error(t, err, "") 52 | 53 | p = Params{ 54 | Params: ParamsStructExample{ 55 | B: "The b value", 56 | C: []SubStruct{{C: "the c value"}}, 57 | D: []string{"hello"}, 58 | }, 59 | } 60 | 61 | _, err = p.ToJSON() 62 | assert.Error(t, err, "") 63 | } 64 | 65 | func Test_Params_ToValues(t *testing.T) { 66 | p := Params{ 67 | Params: ParamsStructExample{ 68 | A: "The a value", 69 | B: "The b value", 70 | C: []SubStruct{{C: "the c value"}}, 71 | D: []string{"hello"}, 72 | }, 73 | } 74 | 75 | values, err := p.ToValues() 76 | assert.NoError(t, err) 77 | unescaped, _ := url.QueryUnescape(values.Encode()) 78 | assert.Equal(t, "a=The a value&d[0]=hello&sub[0][c]=the c value", unescaped) 79 | } 80 | -------------------------------------------------------------------------------- /user/fixtures/TestClient_Create.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 1 3 | interactions: 4 | - request: 5 | body: '{"username":"TestMo"}' 6 | form: {} 7 | headers: 8 | Connection: 9 | - close 10 | User-Agent: 11 | - Files.com Go SDK 2.0.0-beta 12 | url: https://app.files.com/api/rest/v1/users 13 | method: POST 14 | response: 15 | body: '{"id":558974,"username":"TestMo","admin_group_ids":[],"allowed_ips":null,"attachments_permission":false,"api_keys_count":0,"authenticate_until":null,"authentication_method":"password","avatar_url":null,"billing_permission":false,"bypass_site_allowed_ips":false,"bypass_inactive_disable":false,"created_at":"2022-06-29T17:19:58-04:00","dav_permission":true,"disabled":false,"email":null,"ftp_permission":true,"group_ids":"","header_text":null,"language":"","last_login_at":null,"last_protocol_cipher":null,"lockout_expires":null,"name":null,"company":null,"notes":null,"notification_daily_send_time":null,"office_integration_enabled":true,"password_set_at":"2022-06-29T17:19:58-04:00","password_validity_days":0,"public_keys_count":0,"require_2fa":"use_system_setting","active_2fa":false,"require_password_change":false,"password_expired":false,"restapi_permission":true,"self_managed":true,"sftp_permission":true,"site_admin":false,"skip_welcome_screen":false,"ssl_required":"use_system_setting","sso_strategy_id":null,"externally_managed":false,"time_zone":"Eastern 16 | Time (US \u0026 Canada)","type_of_2fa":null,"user_root":""}' 17 | headers: 18 | Cache-Control: 19 | - no-cache, no-store, max-age=0, must-revalidate 20 | Content-Length: 21 | - "1126" 22 | Content-Type: 23 | - application/json 24 | Date: 25 | - Wed, 29 Jun 2022 21:19:58 GMT 26 | Expires: 27 | - Fri, 01 Jan 1990 00:00:00 GMT 28 | Pragma: 29 | - no-cache 30 | Server: 31 | - nginx 32 | X-Request-Id: 33 | - cee862dd-2edb-4645-a58b-ed331694f6f2 34 | status: 201 Created 35 | code: 201 36 | duration: "" 37 | -------------------------------------------------------------------------------- /scimlog/client.go: -------------------------------------------------------------------------------- 1 | package scim_log 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) ScimLog() files_sdk.ScimLog { 23 | return i.Current().(files_sdk.ScimLog) 24 | } 25 | 26 | func (i *Iter) LoadResource(identifier interface{}, opts ...files_sdk.RequestResponseOption) (interface{}, error) { 27 | params := files_sdk.ScimLogFindParams{} 28 | if id, ok := identifier.(int64); ok { 29 | params.Id = id 30 | } 31 | return i.Client.Find(params, opts...) 32 | } 33 | 34 | func (c *Client) List(params files_sdk.ScimLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 35 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 36 | path, err := lib.BuildPath("/scim_logs", params) 37 | if err != nil { 38 | return i, err 39 | } 40 | i.ListParams = ¶ms 41 | list := files_sdk.ScimLogCollection{} 42 | i.Query = listquery.Build(c.Config, path, &list, opts...) 43 | return i, nil 44 | } 45 | 46 | func List(params files_sdk.ScimLogListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 47 | return (&Client{}).List(params, opts...) 48 | } 49 | 50 | func (c *Client) Find(params files_sdk.ScimLogFindParams, opts ...files_sdk.RequestResponseOption) (scimLog files_sdk.ScimLog, err error) { 51 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/scim_logs/{id}", Params: params, Entity: &scimLog}, opts...) 52 | return 53 | } 54 | 55 | func Find(params files_sdk.ScimLogFindParams, opts ...files_sdk.RequestResponseOption) (scimLog files_sdk.ScimLog, err error) { 56 | return (&Client{}).Find(params, opts...) 57 | } 58 | -------------------------------------------------------------------------------- /syncrun/client.go: -------------------------------------------------------------------------------- 1 | package sync_run 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) SyncRun() files_sdk.SyncRun { 23 | return i.Current().(files_sdk.SyncRun) 24 | } 25 | 26 | func (i *Iter) LoadResource(identifier interface{}, opts ...files_sdk.RequestResponseOption) (interface{}, error) { 27 | params := files_sdk.SyncRunFindParams{} 28 | if id, ok := identifier.(int64); ok { 29 | params.Id = id 30 | } 31 | return i.Client.Find(params, opts...) 32 | } 33 | 34 | func (c *Client) List(params files_sdk.SyncRunListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 35 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 36 | path, err := lib.BuildPath("/sync_runs", params) 37 | if err != nil { 38 | return i, err 39 | } 40 | i.ListParams = ¶ms 41 | list := files_sdk.SyncRunCollection{} 42 | i.Query = listquery.Build(c.Config, path, &list, opts...) 43 | return i, nil 44 | } 45 | 46 | func List(params files_sdk.SyncRunListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 47 | return (&Client{}).List(params, opts...) 48 | } 49 | 50 | func (c *Client) Find(params files_sdk.SyncRunFindParams, opts ...files_sdk.RequestResponseOption) (syncRun files_sdk.SyncRun, err error) { 51 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/sync_runs/{id}", Params: params, Entity: &syncRun}, opts...) 52 | return 53 | } 54 | 55 | func Find(params files_sdk.SyncRunFindParams, opts ...files_sdk.RequestResponseOption) (syncRun files_sdk.SyncRun, err error) { 56 | return (&Client{}).Find(params, opts...) 57 | } 58 | -------------------------------------------------------------------------------- /folder/client.go: -------------------------------------------------------------------------------- 1 | package folder 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) File() files_sdk.File { 23 | return i.Current().(files_sdk.File) 24 | } 25 | 26 | func (i *Iter) Iterate(identifier interface{}, opts ...files_sdk.RequestResponseOption) (files_sdk.IterI, error) { 27 | params := files_sdk.FolderListForParams{} 28 | if path, ok := identifier.(string); ok { 29 | params.Path = path 30 | } 31 | return i.Client.ListFor(params, opts...) 32 | } 33 | 34 | func (c *Client) ListFor(params files_sdk.FolderListForParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 35 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 36 | path, err := lib.BuildPath("/folders/{path}", params) 37 | if err != nil { 38 | return i, err 39 | } 40 | i.ListParams = ¶ms 41 | list := files_sdk.FileCollection{} 42 | i.Query = listquery.Build(c.Config, path, &list, opts...) 43 | return i, nil 44 | } 45 | 46 | func ListFor(params files_sdk.FolderListForParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 47 | return (&Client{}).ListFor(params, opts...) 48 | } 49 | 50 | func (c *Client) Create(params files_sdk.FolderCreateParams, opts ...files_sdk.RequestResponseOption) (file files_sdk.File, err error) { 51 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/folders/{path}", Params: params, Entity: &file}, opts...) 52 | return 53 | } 54 | 55 | func Create(params files_sdk.FolderCreateParams, opts ...files_sdk.RequestResponseOption) (file files_sdk.File, err error) { 56 | return (&Client{}).Create(params, opts...) 57 | } 58 | -------------------------------------------------------------------------------- /file/download.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "io" 5 | "io/fs" 6 | "os" 7 | 8 | files_sdk "github.com/Files-com/files-sdk-go/v3" 9 | "github.com/Files-com/files-sdk-go/v3/file/manager" 10 | ) 11 | 12 | func (c *Client) DownloadRetry(job Job, opts ...files_sdk.RequestResponseOption) *Job { 13 | newJob := job.ClearStatuses() 14 | return c.Downloader( 15 | DownloaderParams{ 16 | RemotePath: newJob.RemotePath, 17 | Sync: newJob.Sync, 18 | Manager: newJob.Manager, 19 | LocalPath: newJob.LocalPath, 20 | RetryPolicy: newJob.RetryPolicy.(RetryPolicy), 21 | EventsReporter: newJob.EventsReporter, 22 | }, 23 | opts...) 24 | } 25 | 26 | func (c *Client) DownloadToFile(params files_sdk.FileDownloadParams, filePath string, opts ...files_sdk.RequestResponseOption) (files_sdk.File, error) { 27 | out, err := os.Create(filePath) 28 | if err != nil { 29 | return files_sdk.File{}, err 30 | } 31 | return c.Download(params, append(opts, files_sdk.ResponseBodyOption(func(closer io.ReadCloser) error { 32 | _, err := io.Copy(out, closer) 33 | return err 34 | }))...) 35 | } 36 | 37 | type DownloaderParams struct { 38 | // Ignore gitignore formatted pattern 39 | Ignore []string 40 | // Include gitignore formatted pattern 41 | Include []string 42 | RemotePath string 43 | RemoteFile files_sdk.File 44 | LocalPath string 45 | TempPath string // Folder path where the file(s) will be downloaded to before being moved to LocalPath. If not set, the file(s) will be downloaded directly to LocalPath. 46 | Sync bool 47 | PreserveTimes bool 48 | NoOverwrite bool 49 | RetryPolicy 50 | *manager.Manager 51 | EventsReporter 52 | config files_sdk.Config 53 | DryRun bool 54 | } 55 | 56 | func (c *Client) Downloader(params DownloaderParams, opts ...files_sdk.RequestResponseOption) *Job { 57 | params.config = c.Config 58 | return downloader(files_sdk.ContextOption(opts), (&FS{}).Init(c.Config, true), params) 59 | } 60 | 61 | type Entity struct { 62 | fs.File 63 | fs.FS 64 | error 65 | } 66 | -------------------------------------------------------------------------------- /formfield.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type FormField struct { 10 | Id int64 `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"` 11 | Label string `json:"label,omitempty" path:"label,omitempty" url:"label,omitempty"` 12 | Required *bool `json:"required,omitempty" path:"required,omitempty" url:"required,omitempty"` 13 | HelpText string `json:"help_text,omitempty" path:"help_text,omitempty" url:"help_text,omitempty"` 14 | FieldType string `json:"field_type,omitempty" path:"field_type,omitempty" url:"field_type,omitempty"` 15 | OptionsForSelect []string `json:"options_for_select,omitempty" path:"options_for_select,omitempty" url:"options_for_select,omitempty"` 16 | DefaultOption string `json:"default_option,omitempty" path:"default_option,omitempty" url:"default_option,omitempty"` 17 | FormFieldSetId int64 `json:"form_field_set_id,omitempty" path:"form_field_set_id,omitempty" url:"form_field_set_id,omitempty"` 18 | } 19 | 20 | func (f FormField) Identifier() interface{} { 21 | return f.Id 22 | } 23 | 24 | type FormFieldCollection []FormField 25 | 26 | func (f *FormField) UnmarshalJSON(data []byte) error { 27 | type formField FormField 28 | var v formField 29 | if err := json.Unmarshal(data, &v); err != nil { 30 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 31 | } 32 | 33 | *f = FormField(v) 34 | return nil 35 | } 36 | 37 | func (f *FormFieldCollection) UnmarshalJSON(data []byte) error { 38 | type formFields FormFieldCollection 39 | var v formFields 40 | if err := json.Unmarshal(data, &v); err != nil { 41 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 42 | } 43 | 44 | *f = FormFieldCollection(v) 45 | return nil 46 | } 47 | 48 | func (f *FormFieldCollection) ToSlice() *[]interface{} { 49 | ret := make([]interface{}, len(*f)) 50 | for i, v := range *f { 51 | ret[i] = v 52 | } 53 | 54 | return &ret 55 | } 56 | -------------------------------------------------------------------------------- /invoice/client.go: -------------------------------------------------------------------------------- 1 | package invoice 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) AccountLineItem() files_sdk.AccountLineItem { 23 | return i.Current().(files_sdk.AccountLineItem) 24 | } 25 | 26 | func (i *Iter) LoadResource(identifier interface{}, opts ...files_sdk.RequestResponseOption) (interface{}, error) { 27 | params := files_sdk.InvoiceFindParams{} 28 | if id, ok := identifier.(int64); ok { 29 | params.Id = id 30 | } 31 | return i.Client.Find(params, opts...) 32 | } 33 | 34 | func (c *Client) List(params files_sdk.InvoiceListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 35 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 36 | path, err := lib.BuildPath("/invoices", params) 37 | if err != nil { 38 | return i, err 39 | } 40 | i.ListParams = ¶ms 41 | list := files_sdk.AccountLineItemCollection{} 42 | i.Query = listquery.Build(c.Config, path, &list, opts...) 43 | return i, nil 44 | } 45 | 46 | func List(params files_sdk.InvoiceListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 47 | return (&Client{}).List(params, opts...) 48 | } 49 | 50 | func (c *Client) Find(params files_sdk.InvoiceFindParams, opts ...files_sdk.RequestResponseOption) (accountLineItem files_sdk.AccountLineItem, err error) { 51 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/invoices/{id}", Params: params, Entity: &accountLineItem}, opts...) 52 | return 53 | } 54 | 55 | func Find(params files_sdk.InvoiceFindParams, opts ...files_sdk.RequestResponseOption) (accountLineItem files_sdk.AccountLineItem, err error) { 56 | return (&Client{}).Find(params, opts...) 57 | } 58 | -------------------------------------------------------------------------------- /payment/client.go: -------------------------------------------------------------------------------- 1 | package payment 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) AccountLineItem() files_sdk.AccountLineItem { 23 | return i.Current().(files_sdk.AccountLineItem) 24 | } 25 | 26 | func (i *Iter) LoadResource(identifier interface{}, opts ...files_sdk.RequestResponseOption) (interface{}, error) { 27 | params := files_sdk.PaymentFindParams{} 28 | if id, ok := identifier.(int64); ok { 29 | params.Id = id 30 | } 31 | return i.Client.Find(params, opts...) 32 | } 33 | 34 | func (c *Client) List(params files_sdk.PaymentListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 35 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 36 | path, err := lib.BuildPath("/payments", params) 37 | if err != nil { 38 | return i, err 39 | } 40 | i.ListParams = ¶ms 41 | list := files_sdk.AccountLineItemCollection{} 42 | i.Query = listquery.Build(c.Config, path, &list, opts...) 43 | return i, nil 44 | } 45 | 46 | func List(params files_sdk.PaymentListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 47 | return (&Client{}).List(params, opts...) 48 | } 49 | 50 | func (c *Client) Find(params files_sdk.PaymentFindParams, opts ...files_sdk.RequestResponseOption) (accountLineItem files_sdk.AccountLineItem, err error) { 51 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/payments/{id}", Params: params, Entity: &accountLineItem}, opts...) 52 | return 53 | } 54 | 55 | func Find(params files_sdk.PaymentFindParams, opts ...files_sdk.RequestResponseOption) (accountLineItem files_sdk.AccountLineItem, err error) { 56 | return (&Client{}).Find(params, opts...) 57 | } 58 | -------------------------------------------------------------------------------- /style/client.go: -------------------------------------------------------------------------------- 1 | package style 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | ) 7 | 8 | type Client struct { 9 | files_sdk.Config 10 | } 11 | 12 | func (c *Client) Find(params files_sdk.StyleFindParams, opts ...files_sdk.RequestResponseOption) (style files_sdk.Style, err error) { 13 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/styles/{path}", Params: params, Entity: &style}, opts...) 14 | return 15 | } 16 | 17 | func Find(params files_sdk.StyleFindParams, opts ...files_sdk.RequestResponseOption) (style files_sdk.Style, err error) { 18 | return (&Client{}).Find(params, opts...) 19 | } 20 | 21 | func (c *Client) Update(params files_sdk.StyleUpdateParams, opts ...files_sdk.RequestResponseOption) (style files_sdk.Style, err error) { 22 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "PATCH", Path: "/styles/{path}", Params: params, Entity: &style}, opts...) 23 | return 24 | } 25 | 26 | func Update(params files_sdk.StyleUpdateParams, opts ...files_sdk.RequestResponseOption) (style files_sdk.Style, err error) { 27 | return (&Client{}).Update(params, opts...) 28 | } 29 | 30 | func (c *Client) UpdateWithMap(params map[string]interface{}, opts ...files_sdk.RequestResponseOption) (style files_sdk.Style, err error) { 31 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "PATCH", Path: "/styles/{path}", Params: params, Entity: &style}, opts...) 32 | return 33 | } 34 | 35 | func UpdateWithMap(params map[string]interface{}, opts ...files_sdk.RequestResponseOption) (style files_sdk.Style, err error) { 36 | return (&Client{}).UpdateWithMap(params, opts...) 37 | } 38 | 39 | func (c *Client) Delete(params files_sdk.StyleDeleteParams, opts ...files_sdk.RequestResponseOption) (err error) { 40 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "DELETE", Path: "/styles/{path}", Params: params, Entity: nil}, opts...) 41 | return 42 | } 43 | 44 | func Delete(params files_sdk.StyleDeleteParams, opts ...files_sdk.RequestResponseOption) (err error) { 45 | return (&Client{}).Delete(params, opts...) 46 | } 47 | -------------------------------------------------------------------------------- /automationrun/client.go: -------------------------------------------------------------------------------- 1 | package automation_run 2 | 3 | import ( 4 | files_sdk "github.com/Files-com/files-sdk-go/v3" 5 | lib "github.com/Files-com/files-sdk-go/v3/lib" 6 | listquery "github.com/Files-com/files-sdk-go/v3/listquery" 7 | ) 8 | 9 | type Client struct { 10 | files_sdk.Config 11 | } 12 | 13 | type Iter struct { 14 | *files_sdk.Iter 15 | *Client 16 | } 17 | 18 | func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI { 19 | return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client} 20 | } 21 | 22 | func (i *Iter) AutomationRun() files_sdk.AutomationRun { 23 | return i.Current().(files_sdk.AutomationRun) 24 | } 25 | 26 | func (i *Iter) LoadResource(identifier interface{}, opts ...files_sdk.RequestResponseOption) (interface{}, error) { 27 | params := files_sdk.AutomationRunFindParams{} 28 | if id, ok := identifier.(int64); ok { 29 | params.Id = id 30 | } 31 | return i.Client.Find(params, opts...) 32 | } 33 | 34 | func (c *Client) List(params files_sdk.AutomationRunListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 35 | i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 36 | path, err := lib.BuildPath("/automation_runs", params) 37 | if err != nil { 38 | return i, err 39 | } 40 | i.ListParams = ¶ms 41 | list := files_sdk.AutomationRunCollection{} 42 | i.Query = listquery.Build(c.Config, path, &list, opts...) 43 | return i, nil 44 | } 45 | 46 | func List(params files_sdk.AutomationRunListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 47 | return (&Client{}).List(params, opts...) 48 | } 49 | 50 | func (c *Client) Find(params files_sdk.AutomationRunFindParams, opts ...files_sdk.RequestResponseOption) (automationRun files_sdk.AutomationRun, err error) { 51 | err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/automation_runs/{id}", Params: params, Entity: &automationRun}, opts...) 52 | return 53 | } 54 | 55 | func Find(params files_sdk.AutomationRunFindParams, opts ...files_sdk.RequestResponseOption) (automationRun files_sdk.AutomationRun, err error) { 56 | return (&Client{}).Find(params, opts...) 57 | } 58 | -------------------------------------------------------------------------------- /filecommentreaction.go: -------------------------------------------------------------------------------- 1 | package files_sdk 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | lib "github.com/Files-com/files-sdk-go/v3/lib" 7 | ) 8 | 9 | type FileCommentReaction struct { 10 | Id int64 `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"` 11 | Emoji string `json:"emoji,omitempty" path:"emoji,omitempty" url:"emoji,omitempty"` 12 | UserId int64 `json:"user_id,omitempty" path:"user_id,omitempty" url:"user_id,omitempty"` 13 | FileCommentId int64 `json:"file_comment_id,omitempty" path:"file_comment_id,omitempty" url:"file_comment_id,omitempty"` 14 | } 15 | 16 | func (f FileCommentReaction) Identifier() interface{} { 17 | return f.Id 18 | } 19 | 20 | type FileCommentReactionCollection []FileCommentReaction 21 | 22 | type FileCommentReactionCreateParams struct { 23 | UserId int64 `url:"user_id,omitempty" json:"user_id,omitempty" path:"user_id"` 24 | FileCommentId int64 `url:"file_comment_id" json:"file_comment_id" path:"file_comment_id"` 25 | Emoji string `url:"emoji" json:"emoji" path:"emoji"` 26 | } 27 | 28 | type FileCommentReactionDeleteParams struct { 29 | Id int64 `url:"-,omitempty" json:"-,omitempty" path:"id"` 30 | } 31 | 32 | func (f *FileCommentReaction) UnmarshalJSON(data []byte) error { 33 | type fileCommentReaction FileCommentReaction 34 | var v fileCommentReaction 35 | if err := json.Unmarshal(data, &v); err != nil { 36 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{}) 37 | } 38 | 39 | *f = FileCommentReaction(v) 40 | return nil 41 | } 42 | 43 | func (f *FileCommentReactionCollection) UnmarshalJSON(data []byte) error { 44 | type fileCommentReactions FileCommentReactionCollection 45 | var v fileCommentReactions 46 | if err := json.Unmarshal(data, &v); err != nil { 47 | return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{}) 48 | } 49 | 50 | *f = FileCommentReactionCollection(v) 51 | return nil 52 | } 53 | 54 | func (f *FileCommentReactionCollection) ToSlice() *[]interface{} { 55 | ret := make([]interface{}, len(*f)) 56 | for i, v := range *f { 57 | ret[i] = v 58 | } 59 | 60 | return &ret 61 | } 62 | --------------------------------------------------------------------------------