diff --git a/ds3/buildclient/buildClient.go b/ds3/buildclient/buildClient.go index c4dc5c0..5297252 100644 --- a/ds3/buildclient/buildClient.go +++ b/ds3/buildclient/buildClient.go @@ -7,6 +7,7 @@ import ( "errors" "github.com/SpectraLogic/ds3_go_sdk/ds3/networking" "os" + "strings" ) const EndpointEnv = "DS3_ENDPOINT" @@ -16,7 +17,7 @@ const ProxyEnv = "DS3_PROXY" // Creates a client from cli arguments func FromArgs(args *commands.Arguments) (*ds3.Client, error) { - return createClient(args.Endpoint, args.AccessKey, args.SecretKey, args.Proxy) + return createClient(args) } // Creates a client from environment variables @@ -32,13 +33,27 @@ func FromEnv() (*ds3.Client, error) { case endpoint == "": return nil, errors.New("Must specify an endpoint.") case accessKey == "": return nil, errors.New("Must specify an access key.") case secretKey == "": return nil, errors.New("Must specify an secret key.") - default: return createClient(endpoint, accessKey, secretKey, proxy) } + + args := commands.Arguments{ + Endpoint: endpoint, + AccessKey: accessKey, + SecretKey: secretKey, + Proxy: proxy, + } + + return createClient(&args) } // Creates a client -func createClient(endpoint, accessKey, secretKey, proxy string) (*ds3.Client, error) { +func createClient(args *commands.Arguments) (*ds3.Client, error) { + // Parse endpoint. + endpoint := args.Endpoint + if !strings.HasPrefix(endpoint, "http://") || !strings.HasPrefix(endpoint, "https://") { + endpoint = "https://" + endpoint + } + endpointUrl, endpointErr := url.Parse(endpoint) if endpointErr != nil { return nil, errors.New("The endpoint format was invalid.") @@ -46,9 +61,9 @@ func createClient(endpoint, accessKey, secretKey, proxy string) (*ds3.Client, er // Parse proxy. var proxyUrlPtr *url.URL - if len(proxy) != 0 { + if len(args.Proxy) != 0 { var proxyErr error - proxyUrlPtr, proxyErr = url.Parse(proxy) + proxyUrlPtr, proxyErr = url.Parse(args.Proxy) if proxyErr != nil { return nil, errors.New("The proxy format was invalid.") } @@ -56,7 +71,8 @@ func createClient(endpoint, accessKey, secretKey, proxy string) (*ds3.Client, er // Create the client. client := ds3. - NewClientBuilder(endpointUrl, &networking.Credentials{AccessId: accessKey, Key: secretKey}). + NewClientBuilder(endpointUrl, &networking.Credentials{AccessId: args.AccessKey, Key: args.SecretKey}). + WithIgnoreServerCertificate(args.IgnoreServerCertificate). WithProxy(proxyUrlPtr). BuildClient() return client, nil diff --git a/ds3_cli/commands/args.go b/ds3_cli/commands/args.go index e39b4e9..ddae425 100644 --- a/ds3_cli/commands/args.go +++ b/ds3_cli/commands/args.go @@ -10,6 +10,7 @@ import ( type Arguments struct { Endpoint, Proxy string AccessKey, SecretKey string + IgnoreServerCertificate bool Command string Bucket string Key string @@ -21,6 +22,7 @@ type Arguments struct { func ParseArgs() (*Arguments, error) { // Parse command line arguments. endpointParam := flag.String("endpoint", "", "Specifies the url to the DS3 server.") + ignoreServerCertParam := flag.Bool("ignore_server_cert", false, "Specifies whether to ignore the server's certificate.") accessKeyParam := flag.String("access_key", "", "Specifies the access_key for the DS3 user.") secretKeyParam := flag.String("secret_key", "", "Specifies the secret_key for the DS3 user.") proxyParam := flag.String("proxy", "", "Specifies the HTTP proxy to route through.") @@ -36,6 +38,7 @@ func ParseArgs() (*Arguments, error) { // Build the arguments object. args := Arguments{ Endpoint: paramOrEnv(*endpointParam, "DS3_ENDPOINT"), + IgnoreServerCertificate: *ignoreServerCertParam, AccessKey: paramOrEnv(*accessKeyParam, "DS3_ACCESS_KEY"), SecretKey: paramOrEnv(*secretKeyParam, "DS3_SECRET_KEY"), Proxy: paramOrEnv(*proxyParam, "DS3_PROXY"),