Skip to content

Commit 3de7303

Browse files
committed
refactor service account / banned remotes logic into rclone package
1 parent 9314e1f commit 3de7303

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

cmd/upload.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"github.com/dustin/go-humanize"
55
"github.com/l3uddz/crop/config"
6+
"github.com/l3uddz/crop/rclone"
67
"github.com/l3uddz/crop/uploader"
78
"github.com/pkg/errors"
89
"github.com/sirupsen/logrus"
@@ -48,7 +49,7 @@ var uploadCmd = &cobra.Command{
4849
} else {
4950
// no service accounts were loaded
5051
// check to see if any of the copy or move remote(s) are banned
51-
banned, expiry := upload.RemotesBanned(upload.Config.Remotes.Copy)
52+
banned, expiry := rclone.AnyRemotesBanned(upload.Config.Remotes.Copy)
5253
if banned && !expiry.IsZero() {
5354
// one of the copy remotes is banned, abort
5455
upload.Log.WithFields(logrus.Fields{
@@ -58,7 +59,7 @@ var uploadCmd = &cobra.Command{
5859
continue
5960
}
6061

61-
banned, expiry = upload.RemotesBanned([]string{upload.Config.Remotes.Move})
62+
banned, expiry = rclone.AnyRemotesBanned([]string{upload.Config.Remotes.Move})
6263
if banned && !expiry.IsZero() {
6364
// the move remote is banned, abort
6465
upload.Log.WithFields(logrus.Fields{

uploader/cache.go renamed to rclone/sa.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package uploader
1+
package rclone
22

33
import (
44
"github.com/l3uddz/crop/cache"
@@ -9,11 +9,11 @@ import (
99
)
1010

1111
/* Private */
12-
func (u *Uploader) getAvailableServiceAccount() (*pathutils.Path, error) {
12+
func GetAvailableServiceAccount(serviceAccountFiles []pathutils.Path) (*pathutils.Path, error) {
1313
var serviceAccountFile *pathutils.Path = nil
1414

1515
// find an unbanned service account
16-
for _, sa := range u.ServiceAccountFiles {
16+
for _, sa := range serviceAccountFiles {
1717
// does the cache already contain this service account?
1818
if exists, _ := cache.Get(sa.RealPath); exists {
1919
// service account is currently banned
@@ -34,7 +34,7 @@ func (u *Uploader) getAvailableServiceAccount() (*pathutils.Path, error) {
3434
}
3535

3636
/* Public */
37-
func (u *Uploader) RemotesBanned(remotes []string) (bool, time.Time) {
37+
func AnyRemotesBanned(remotes []string) (bool, time.Time) {
3838
var banned bool
3939
var expires time.Time
4040

uploader/copy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (u *Uploader) Copy(additionalRcloneParams []string) error {
2929
var err error
3030

3131
if u.ServiceAccountCount > 0 {
32-
serviceAccount, err = u.getAvailableServiceAccount()
32+
serviceAccount, err = rclone.GetAvailableServiceAccount(u.ServiceAccountFiles)
3333
if err != nil {
3434
return errors.WithMessagef(err,
3535
"aborting further copy attempts of %q due to serviceAccount exhaustion",

uploader/move.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (u *Uploader) Move(serverSide bool, additionalRcloneParams []string) error
5757

5858
if u.ServiceAccountCount > 0 && !serverSide {
5959
// server side moves not supported with service account files
60-
serviceAccount, err = u.getAvailableServiceAccount()
60+
serviceAccount, err = rclone.GetAvailableServiceAccount(u.ServiceAccountFiles)
6161
if err != nil {
6262
return errors.WithMessagef(err,
6363
"aborting further move attempts of %q due to serviceAccount exhaustion",

0 commit comments

Comments
 (0)