Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,69 @@ go_repository(
version = "v1.1.0",
)

go_repository(
name = "com_github_azure_azure_sdk_for_go",
importpath = "github.com/Azure/azure-sdk-for-go",
sum = "h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU=",
version = "v68.0.0+incompatible",
)

go_repository(
name = "com_github_azure_azure_sdk_for_go_sdk_storage_azblob",
importpath = "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob",
sum = "h1:u/LLAOFgsMv7HmNL4Qufg58y+qElGOt5qv0z1mURkRY=",
version = "v1.0.0",
)

go_repository(
name = "com_github_azure_azure_sdk_for_go_sdk_azidentity",
importpath = "github.com/Azure/azure-sdk-for-go/sdk/azidentity",
sum = "h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=",
version = "v1.3.0",
)

go_repository(
name = "com_github_azure_azure_sdk_for_go_sdk_azcore",
importpath = "github.com/Azure/azure-sdk-for-go/sdk/azcore",
sum = "h1:8kDqDngH+DmVBiCtIjCFTGa7MBnsIOkF9IccInFEbjk=",
version = "v1.6.0",
)

go_repository(
name = "com_github_azuread_microsoft_authentication_library_for_go",
importpath = "github.com/AzureAD/microsoft-authentication-library-for-go",
sum = "h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY=",
version = "v1.0.0",
)

go_repository(
name = "com_github_azure_azure_sdk_for_go_sdk_internal",
importpath = "github.com/Azure/azure-sdk-for-go/sdk/internal",
sum = "h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=",
version = "v1.3.0",
)

go_repository(
name = "com_github_kylelemons_godebug",
importpath = "github.com/kylelemons/godebug",
sum = "h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=",
version = "v1.1.0",
)

go_repository(
name = "com_github_pkg_browser",
importpath = "github.com/pkg/browser",
sum = "h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=",
version = "v0.0.0-20210911075715-681adbf594b8",
)

go_repository(
name = "com_github_golang_jwt_jwt_v4",
importpath = "github.com/golang-jwt/jwt/v4",
sum = "h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=",
version = "v4.5.0",
)

bazel_skylib_workspace()

load("//:repositories.bzl", "go_repositories")
Expand Down
1 change: 1 addition & 0 deletions add-bazel-dep.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
go get $1
bazel run //:gazelle -- update-repos $1
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.0.1 // indirect
cloud.google.com/go/pubsub v1.30.1 // indirect
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.44.256 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.8 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.21 // indirect
Expand All @@ -44,6 +50,7 @@ require (
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsouza/fake-gcs-server v1.45.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand All @@ -60,9 +67,11 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/johannesboyne/gofakes3 v0.0.0-20230506070712-04da935ef877 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/xattr v0.4.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
Expand Down
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi
cloud.google.com/go/storage v1.30.1 h1:uOdMxAs8HExqBlnLtnQyP0YkvbiDpdGShGKtx6U/oNM=
cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7BiccwkR7+P7gN8E=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU=
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 h1:8kDqDngH+DmVBiCtIjCFTGa7MBnsIOkF9IccInFEbjk=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0 h1:u/LLAOFgsMv7HmNL4Qufg58y+qElGOt5qv0z1mURkRY=
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0/go.mod h1:2e8rMJtl2+2j+HXbTBwnyGpm5Nou7KhvSfxOq8JpTag=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down Expand Up @@ -137,6 +149,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -257,6 +271,8 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
Expand All @@ -265,6 +281,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE=
Expand Down Expand Up @@ -478,6 +496,7 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
1 change: 1 addition & 0 deletions internal/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//internal/metadata",
"//internal/program",
"//internal/stores",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//:azblob",
"@com_github_google_logger//:logger",
"@com_github_spf13_afero//:afero",
"@com_github_spf13_cobra//:cobra",
Expand Down
12 changes: 12 additions & 0 deletions internal/cli/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/discentem/cavorite/internal/config"
"github.com/discentem/cavorite/internal/stores"
"github.com/google/logger"
Expand Down Expand Up @@ -54,6 +55,17 @@ func initStoreFromConfig(ctx context.Context, cfg config.Config, fsys afero.Fs,
return nil, fmt.Errorf("improper stores.GCSClient init: %v", err)
}
s = stores.Store(gcs)
case stores.StoreTypeAzureBlob:
az, err := stores.NewAzureBlobStore(
ctx,
fsys,
opts,
azblob.ClientOptions{},
)
if err != nil {
return nil, fmt.Errorf("improper stores.AzureBlobStore init: %v", err)
}
s = stores.Store(az)
default:
return nil, fmt.Errorf("type %s is not supported", cfg.StoreType)
}
Expand Down
23 changes: 19 additions & 4 deletions internal/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ import (

func initCmd() *cobra.Command {
initCmd := &cobra.Command{
Use: "init",
Short: fmt.Sprintf("Initialize a new %s repo", program.Name),
Long: fmt.Sprintf("Initialize a new %s repo", program.Name),
Args: cobra.ExactArgs(1),
Use: "init",
Short: fmt.Sprintf("Initialize a new %s repo", program.Name),
Long: fmt.Sprintf("Initialize a new %s repo", program.Name),
Args: func(cmd *cobra.Command, args []string) error {
fn := cobra.ExactArgs(1)
err := fn(cmd, args)
if err != nil {
return fmt.Errorf("you must specify a path to a repo you want %s to track", program.Name)
}
return nil
},
PreRunE: initPreExecFn,
RunE: initFn,
}
Expand Down Expand Up @@ -99,6 +106,14 @@ func initFn(cmd *cobra.Command, args []string) error {
backendAddress,
opts,
)
case stores.StoreTypeAzureBlob:
cfg = config.InitializeStoreTypeAzureBlob(
cmd.Context(),
fsys,
repoToInit,
backendAddress,
opts,
)
default:
return config.ErrUnsupportedStore
}
Expand Down
5 changes: 5 additions & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/discentem/cavorite/internal/metadata"
"github.com/discentem/cavorite/internal/program"
"github.com/discentem/cavorite/internal/stores"
"github.com/google/logger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -74,6 +75,10 @@ func rootCmd() *cobra.Command {
viper.SetDefault("store_type", stores.StoreTypeUndefined)
viper.SetDefault("metadata_file_extension", metadata.MetadataFileExtension)

if vv {
logger.SetLevel(2)
}

// Import subCmds into the rootCmd
rootCmd.AddCommand(
initCmd(),
Expand Down
15 changes: 15 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ func InitializeStoreTypeGCS(
}
}

func InitializeStoreTypeAzureBlob(
ctx context.Context,
fsys afero.Fs,
sourceRepo, backendAddress string,
opts stores.Options,
) Config {
return Config{
StoreType: stores.StoreTypeAzureBlob,
Options: opts,
Validate: func() error {
return nil
},
}
}

func (c *Config) Write(fsys afero.Fs, sourceRepo string) error {
if c.Validate == nil {
return ErrValidateNil
Expand Down
9 changes: 9 additions & 0 deletions internal/fileutils/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "fileutils",
srcs = ["fileutils.go"],
importpath = "github.com/discentem/cavorite/internal/fileutils",
visibility = ["//:__subpackages__"],
deps = ["@com_github_spf13_afero//:afero"],
)
25 changes: 25 additions & 0 deletions internal/fileutils/fileutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fileutils

import (
"fmt"
"io"

"github.com/spf13/afero"
)

func BytesFromAferoFile(f afero.File) ([]byte, error) {
_, err := f.Seek(0, io.SeekStart)
if err != nil {
return nil, err
}
objInfo, err := f.Stat()
if err != nil {
return nil, err
}
b := make([]byte, objInfo.Size())
_, err = f.Read(b)
if err != nil {
return nil, fmt.Errorf("failed to read bytes from objectHandle: %w", err)
}
return b, nil
}
9 changes: 9 additions & 0 deletions internal/stores/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "stores",
srcs = [
"azure.go",
"gcs.go",
"options.go",
"s3.go",
Expand All @@ -16,6 +17,10 @@ go_library(
"@com_github_aws_aws_sdk_go_v2_config//:config",
"@com_github_aws_aws_sdk_go_v2_feature_s3_manager//:manager",
"@com_github_aws_aws_sdk_go_v2_service_s3//:s3",
"@com_github_azure_azure_sdk_for_go_sdk_azidentity//:azidentity",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//:azblob",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//blob",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//blockblob",
"@com_github_google_logger//:logger",
"@com_github_hashicorp_go_multierror//:go-multierror",
"@com_github_spf13_afero//:afero",
Expand All @@ -27,6 +32,7 @@ go_library(
go_test(
name = "stores_test",
srcs = [
"azure_test.go",
"gcs_test.go",
"s3_test.go",
"stores_test.go",
Expand All @@ -36,9 +42,12 @@ go_test(
"//internal/testutils",
"@com_github_aws_aws_sdk_go_v2_feature_s3_manager//:manager",
"@com_github_aws_aws_sdk_go_v2_service_s3//:s3",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//:azblob",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//blob",
"@com_github_fsouza_fake_gcs_server//fakestorage",
"@com_github_spf13_afero//:afero",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@com_google_cloud_go_storage//:storage",
"@org_golang_google_api//option",
],
Expand Down
Loading