github.com/opentofu/opentofu@v1.7.1/internal/encryption/keyprovider/aws_kms/config_endpoints.go (about) 1 package aws_kms 2 3 import ( 4 "fmt" 5 "log" 6 "regexp" 7 ) 8 9 type ConfigEndpoints struct { 10 IAM string `hcl:"iam,optional"` 11 STS string `hcl:"sts,optional"` 12 } 13 14 // Mirrored from s3 backend config 15 func includeProtoIfNessesary(endpoint string) string { 16 if matched, _ := regexp.MatchString("[a-z]*://.*", endpoint); !matched { 17 log.Printf("[DEBUG] Adding https:// prefix to endpoint '%s'", endpoint) 18 endpoint = fmt.Sprintf("https://%s", endpoint) 19 } 20 return endpoint 21 } 22 23 func (c Config) getEndpoints() (ConfigEndpoints, error) { 24 endpoints := ConfigEndpoints{} 25 26 // Make sure we have 0 or 1 endpoint blocks 27 if len(c.Endpoints) == 1 { 28 endpoints = c.Endpoints[0] 29 } 30 if len(c.Endpoints) > 1 { 31 return endpoints, fmt.Errorf("expected single aws_kms endpoints block, multiple provided") 32 } 33 34 // Endpoint formatting 35 if len(endpoints.IAM) != 0 { 36 endpoints.IAM = includeProtoIfNessesary(endpoints.IAM) 37 } 38 if len(endpoints.STS) != 0 { 39 endpoints.STS = includeProtoIfNessesary(endpoints.STS) 40 } 41 return endpoints, nil 42 }