Skip to content

Commit

Permalink
Merge pull request #137 from 0chain/update-check
Browse files Browse the repository at this point in the history
update access key for common config
  • Loading branch information
dabasov authored Sep 29, 2024
2 parents 1cbb139 + d091a97 commit a2ef113
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
16 changes: 2 additions & 14 deletions cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var (
chunkNumber int
batchSize int
source string
accessToken string // if source is google drive or dropbox
)

// migrateCmd is the migrateFromS3 sub command to migrate whole objects from some buckets.
Expand All @@ -52,8 +51,8 @@ func init() {
migrateCmd.PersistentFlags().StringVar(&allocationId, "allocation", "", "allocation ID for dStorage")
migrateCmd.Flags().StringVar(&allocationTextPath, "alloc-path", "", "File Path to allocation text")
migrateCmd.Flags().BoolVar(&encrypt, "encrypt", false, "pass this option to encrypt and upload the file")
//flags related to s3
migrateCmd.PersistentFlags().StringVar(&accessKey, "access-key", "", "access-key of aws")
//flags related to cloudstorage
migrateCmd.PersistentFlags().StringVar(&accessKey, "access-key", "", "access-key of CloudStorage [Aws, Drive, Dropbox]")
migrateCmd.PersistentFlags().StringVar(&secretKey, "secret-key", "", "secret-key of aws")
migrateCmd.Flags().StringVar(&awsCredPath, "aws-cred-path", "", "File Path to aws credentials")
migrateCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "Bucket to migrate")
Expand All @@ -74,7 +73,6 @@ func init() {
migrateCmd.Flags().IntVar(&chunkNumber, "chunk-number", 250, "number of chunks to upload")
migrateCmd.Flags().IntVar(&batchSize, "batch-size", 20, "number of files to upload in a batch")
migrateCmd.Flags().StringVar(&source, "source", "s3", "s3 or google_drive or dropbox")
migrateCmd.Flags().StringVar(&accessToken, "access-token", "", "access token for google drive or dropbox")
}

var migrateCmd = &cobra.Command{
Expand Down Expand Up @@ -128,13 +126,6 @@ var migrateCmd = &cobra.Command{
}
}
}

if accessToken == "" && (source=="google_drive" || source =="dropbox") {
if accessToken = util.GetAccessToken(); accessToken == "" {
return errors.New("missing access token")
}
}

if bucket == "" && source == "s3" {
bucket, region, prefix, err = util.GetBucketRegionPrefixFromFile(awsCredPath)
if err != nil {
Expand Down Expand Up @@ -210,7 +201,6 @@ var migrateCmd = &cobra.Command{
startAfter = strings.ReplaceAll(strings.ReplaceAll(startAfter, " ", ""), "\n", "")
}
}

if err := util.SetAwsEnvCredentials(accessKey, secretKey); err != nil {
return err
}
Expand Down Expand Up @@ -245,9 +235,7 @@ var migrateCmd = &cobra.Command{
ChunkSize: chunkSize,
ChunkNumber: chunkNumber,
BatchSize: batchSize,

Source: source,
AccessToken: accessToken,
}

if err := migration.InitMigration(&mConfig); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ func InitMigration(mConfig *MigrationConfig) error {
)
} else if mConfig.Source == "dropbox" {
dataSourceStore, err = dropbox.GetDropboxClient(
mConfig.AccessToken,
util.GetAccessKeyFromEnv(),
mConfig.WorkDir,
)
} else if mConfig.Source == "google_drive" {
dataSourceStore, err = gdrive.NewGoogleDriveClient(
mConfig.AccessToken,
util.GetAccessKeyFromEnv(),
mConfig.WorkDir,
)
} else {
Expand Down
5 changes: 3 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ func GetAllocationIDFromEnv() string {
func GetAwsCredentialsFromEnv() (string, string) {
return os.Getenv("AWS_ACCESS_KEY"), os.Getenv("AWS_SECRET_KEY")
}
func GetAccessToken() string {
return os.Getenv("AccessToken")

func GetAccessKeyFromEnv() (string) {
return os.Getenv("AWS_ACCESS_KEY_ID")
}

func ConvertGoSDKTimeToTime(in string) time.Time {
Expand Down

0 comments on commit a2ef113

Please sign in to comment.