func NewCredentialService()

in local-container-endpoints/handlers/credentials_handler.go [55:96]


func NewCredentialService() (*CredentialService, error) {
	iamCustomEndpoint := utils.GetValue("", config.IAMCustomEndpointVar)
	if iamCustomEndpoint != "" {
		logrus.Infof("Using custom IAM endpoint %s", iamCustomEndpoint)
	}

	stsCustomEndpoint := utils.GetValue("", config.STSCustomEndpointVar)
	if stsCustomEndpoint != "" {
		logrus.Infof("Using custom STS endpoint %s", stsCustomEndpoint)
	}

	defaultResolver := endpoints.DefaultResolver()
	customResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
		if service == endpoints.IamServiceID && iamCustomEndpoint != "" {
			return endpoints.ResolvedEndpoint{
				URL: iamCustomEndpoint,
			}, nil
		} else if service == endpoints.StsServiceID && stsCustomEndpoint != "" {
			return endpoints.ResolvedEndpoint{
				URL: stsCustomEndpoint,
			}, nil
		}
		return defaultResolver.EndpointFor(service, region, optFns...)
	}

	sess, err := session.NewSessionWithOptions(session.Options{
		Config: aws.Config{
			EndpointResolver:              endpoints.ResolverFunc(customResolverFn),
			CredentialsChainVerboseErrors: aws.Bool(true),
		},
		SharedConfigState: session.SharedConfigEnable,
	})
	if err != nil {
		return nil, err
	}

	iamClient := iam.New(sess)
	iamClient.Handlers.Build.PushBackNamed(useragent.CustomUserAgentHandler())
	stsClient := sts.New(sess)
	stsClient.Handlers.Build.PushBackNamed(useragent.CustomUserAgentHandler())
	return NewCredentialServiceWithClients(iamClient, stsClient, sess), nil
}