handle endpoint flag to check http:// or https:// (#2874)

<!-- Insert PR description-->

add CLI check to handle http or https protocol.  

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🐛 Bugfix

#### Issue(s)

* https://github.com/alcionai/corso/issues/2330

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
This commit is contained in:
neha_gupta 2023-03-21 13:05:05 +05:30 committed by GitHub
parent bdc854c1da
commit 5951cbc289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package repo
import (
"strconv"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -73,7 +74,7 @@ corso repo init s3 --bucket my-bucket
corso repo init s3 --bucket my-bucket --prefix my-prefix
# Create a new Corso repo in an S3 compliant storage provider
corso repo init s3 --bucket my-bucket --endpoint https://my-s3-server-endpoint`
corso repo init s3 --bucket my-bucket --endpoint my-s3-server-endpoint`
s3ProviderCommandConnectExamples = `# Connect to a Corso repo in AWS S3 bucket named "my-bucket"
corso repo connect s3 --bucket my-bucket
@ -82,7 +83,7 @@ corso repo connect s3 --bucket my-bucket
corso repo connect s3 --bucket my-bucket --prefix my-prefix
# Connect to a Corso repo in an S3 compliant storage provider
corso repo connect s3 --bucket my-bucket --endpoint https://my-s3-server-endpoint`
corso repo connect s3 --bucket my-bucket --endpoint my-s3-server-endpoint`
)
// ---------------------------------------------------------------------------------------------------------
@ -128,6 +129,13 @@ func initS3Cmd(cmd *cobra.Command, args []string) error {
return Only(ctx, errors.Wrap(err, "Retrieving s3 configuration"))
}
if strings.HasPrefix(s3Cfg.Endpoint, "http://") || strings.HasPrefix(s3Cfg.Endpoint, "https://") {
invalidEndpointErr := "endpoint doesn't support specifying protocol. " +
"pass --disable-tls flag to use http:// instead of default https://"
return Only(ctx, errors.New(invalidEndpointErr))
}
m365, err := cfg.Account.M365Config()
if err != nil {
return Only(ctx, errors.Wrap(err, "Failed to parse m365 account config"))
@ -192,6 +200,13 @@ func connectS3Cmd(cmd *cobra.Command, args []string) error {
return Only(ctx, errors.Wrap(err, "Failed to parse m365 account config"))
}
if strings.HasPrefix(s3Cfg.Endpoint, "http://") || strings.HasPrefix(s3Cfg.Endpoint, "https://") {
invalidEndpointErr := "endpoint doesn't support specifying protocol. " +
"pass --disable-tls flag to use http:// instead of default https://"
return Only(ctx, errors.New(invalidEndpointErr))
}
r, err := repository.ConnectAndSendConnectEvent(ctx, cfg.Account, cfg.Storage, options.Control())
if err != nil {
return Only(ctx, errors.Wrap(err, "Failed to connect to the S3 repository"))