stashed changes

This commit is contained in:
Abhishek Pandey 2023-09-12 22:22:58 +05:30
parent 62b466ca39
commit c2e09688db
5 changed files with 45 additions and 12 deletions

View File

@ -291,6 +291,8 @@ func getStorageAndAccountWithViper(
err error err error
) )
//overrides := repo.S3Overrides(pfs)
overrides := make(map[string]string)
readConfigFromViper := readFromFile readConfigFromViper := readFromFile
// possibly read the prior config from a .corso file // possibly read the prior config from a .corso file

View File

@ -52,7 +52,7 @@ func s3Overrides(in map[string]string) map[string]string {
} }
} }
// Make it local // Moved from repo/s3.go pkg
func S3Overrides(pfs *pflag.FlagSet) map[string]string { func S3Overrides(pfs *pflag.FlagSet) map[string]string {
fs := flags.GetPopulatedFlags(pfs) fs := flags.GetPopulatedFlags(pfs)
return PopulateS3Flags(fs) return PopulateS3Flags(fs)
@ -76,23 +76,23 @@ func PopulateS3Flags(flagset flags.PopulatedFlags) map[string]string {
} }
if _, ok := flagset[flags.BucketFN]; ok { if _, ok := flagset[flags.BucketFN]; ok {
s3Overrides[storage.Bucket] = flags.BucketFV s3Overrides[storage.Bucket] = bucket
} }
if _, ok := flagset[flags.PrefixFN]; ok { if _, ok := flagset[prefixFN]; ok {
s3Overrides[storage.Prefix] = flags.PrefixFV s3Overrides[storage.Prefix] = prefix
} }
if _, ok := flagset[flags.DoNotUseTLSFN]; ok { if _, ok := flagset[doNotUseTLSFN]; ok {
s3Overrides[storage.DoNotUseTLS] = strconv.FormatBool(flags.DoNotUseTLSFV) s3Overrides[storage.DoNotUseTLS] = strconv.FormatBool(doNotUseTLS)
} }
if _, ok := flagset[flags.DoNotVerifyTLSFN]; ok { if _, ok := flagset[doNotVerifyTLSFN]; ok {
s3Overrides[storage.DoNotVerifyTLS] = strconv.FormatBool(flags.DoNotVerifyTLSFV) s3Overrides[storage.DoNotVerifyTLS] = strconv.FormatBool(doNotVerifyTLS)
} }
if _, ok := flagset[flags.EndpointFN]; ok { if _, ok := flagset[endpointFN]; ok {
s3Overrides[storage.Endpoint] = flags.EndpointFV s3Overrides[storage.Endpoint] = endpoint
} }
return s3Overrides return s3Overrides

View File

@ -24,7 +24,7 @@ func (fs PopulatedFlags) populate(pf *pflag.Flag) {
func GetPopulatedFlags(pfs *pflag.FlagSet) PopulatedFlags { func GetPopulatedFlags(pfs *pflag.FlagSet) PopulatedFlags {
pop := PopulatedFlags{} pop := PopulatedFlags{}
// fs := cmd.Flags() //fs := cmd.Flags()
if pfs == nil { if pfs == nil {
return pop return pop
} }

View File

@ -14,6 +14,15 @@ const (
CorsoPassphraseFN = "passphrase" CorsoPassphraseFN = "passphrase"
) )
// s3 bucket flags
const (
BucketFN = "bucket"
EndpointFN = "endpoint"
PrefixFN = "prefix"
DoNotUseTLSFN = "disable-tls"
DoNotVerifyTLSFN = "disable-tls-verification"
)
var ( var (
BackupIDFV string BackupIDFV string
AWSAccessKeyFV string AWSAccessKeyFV string

View File

@ -15,6 +15,16 @@ import (
"github.com/alcionai/corso/src/pkg/repository" "github.com/alcionai/corso/src/pkg/repository"
) )
// s3 bucket info from flags
var (
succeedIfExists bool
bucket string
endpoint string
prefix string
doNotUseTLS bool
doNotVerifyTLS bool
)
// called by repo.go to map subcommands to provider-specific handling. // called by repo.go to map subcommands to provider-specific handling.
func addS3Commands(cmd *cobra.Command) *cobra.Command { func addS3Commands(cmd *cobra.Command) *cobra.Command {
var c *cobra.Command var c *cobra.Command
@ -35,7 +45,19 @@ func addS3Commands(cmd *cobra.Command) *cobra.Command {
flags.AddAWSCredsFlags(c) flags.AddAWSCredsFlags(c)
flags.AddAzureCredsFlags(c) flags.AddAzureCredsFlags(c)
flags.AddCorsoPassphaseFlags(c) flags.AddCorsoPassphaseFlags(c)
flags.AddS3BucketFlags(c)
// Flags addition ordering should follow the order we want them to appear in help and docs:
// More generic and more frequently used flags take precedence.
fs.StringVar(&bucket, flags.BucketFN, "", "Name of S3 bucket for repo. (required)")
fs.StringVar(&prefix, flags.PrefixFN, "", "Repo prefix within bucket.")
fs.StringVar(&endpoint, flags.EndpointFN, "", "S3 service endpoint.")
fs.BoolVar(&doNotUseTLS, flags.DoNotUseTLSFN, false, "Disable TLS (HTTPS)")
fs.BoolVar(&doNotVerifyTLS, flags.DoNotVerifyTLSFN, false, "Disable TLS (HTTPS) certificate verification.")
// In general, we don't want to expose this flag to users and have them mistake it
// for a broad-scale idempotency solution. We can un-hide it later the need arises.
fs.BoolVar(&succeedIfExists, "succeed-if-exists", false, "Exit with success if the repo has already been initialized.")
cobra.CheckErr(fs.MarkHidden("succeed-if-exists"))
return c return c
} }