func()

in internal/plugin/plugin.go [93:140]


func (c *OperationConfig) newAWSSession() (*session.Session, error) {
	o := session.Options{
		SharedConfigState: session.SharedConfigEnable,
	}

	o.Handlers = defaults.Handlers()
	o.Handlers.Build.PushBackNamed(request.NamedHandler{
		Name: "lightsailctl.UserAgentHandler",
		Fn: request.MakeAddToUserAgentHandler(
			"lightsailctl", internal.Version.String(),
			// extra runtime info:
			runtime.Version(), runtime.GOOS, runtime.GOARCH),
	})

	if c.Region != "" {
		o.Config.WithRegion(c.Region)
	}

	if ep := strings.TrimRight(c.Endpoint, "/"); ep != "" {
		o.Config.WithEndpoint(ep)
	}

	if c.Profile != "" {
		o.Profile = c.Profile
	}

	if c.Debug {
		o.Config.WithLogLevel(aws.LogDebugWithSigning | aws.LogDebugWithHTTPBody)
	}

	if c.DoNotVerifySSL {
		o.Config.WithHTTPClient(&http.Client{
			Transport: &http.Transport{
				TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
			},
		})
	}

	if c.CABundle != "" {
		b, err := ioutil.ReadFile(c.CABundle)
		if err != nil {
			return nil, fmt.Errorf("read CA bundle file: %v", err)
		}
		o.CustomCABundle = bytes.NewReader(b)
	}

	return session.NewSessionWithOptions(o)
}