github.phpd.cn/hashicorp/packer@v1.3.2/builder/oracle/oci/config_provider.go (about) 1 package oci 2 3 import ( 4 "crypto/rsa" 5 "errors" 6 "fmt" 7 8 "github.com/oracle/oci-go-sdk/common" 9 ) 10 11 // rawConfigurationProvider allows a user to simply construct a configuration 12 // provider from raw values. It errors on access when those values are empty. 13 type rawConfigurationProvider struct { 14 tenancy string 15 user string 16 region string 17 fingerprint string 18 privateKey string 19 privateKeyPassphrase *string 20 } 21 22 // NewRawConfigurationProvider will create a rawConfigurationProvider. 23 func NewRawConfigurationProvider(tenancy, user, region, fingerprint, privateKey string, privateKeyPassphrase *string) common.ConfigurationProvider { 24 return rawConfigurationProvider{tenancy, user, region, fingerprint, privateKey, privateKeyPassphrase} 25 } 26 27 func (p rawConfigurationProvider) PrivateRSAKey() (key *rsa.PrivateKey, err error) { 28 return common.PrivateKeyFromBytes([]byte(p.privateKey), p.privateKeyPassphrase) 29 } 30 31 func (p rawConfigurationProvider) KeyID() (keyID string, err error) { 32 tenancy, err := p.TenancyOCID() 33 if err != nil { 34 return 35 } 36 37 user, err := p.UserOCID() 38 if err != nil { 39 return 40 } 41 42 fingerprint, err := p.KeyFingerprint() 43 if err != nil { 44 return 45 } 46 47 return fmt.Sprintf("%s/%s/%s", tenancy, user, fingerprint), nil 48 } 49 50 func (p rawConfigurationProvider) TenancyOCID() (string, error) { 51 if p.tenancy == "" { 52 return "", errors.New("no tenancy provided") 53 } 54 return p.tenancy, nil 55 } 56 57 func (p rawConfigurationProvider) UserOCID() (string, error) { 58 if p.user == "" { 59 return "", errors.New("no user provided") 60 } 61 return p.user, nil 62 } 63 64 func (p rawConfigurationProvider) KeyFingerprint() (string, error) { 65 if p.fingerprint == "" { 66 return "", errors.New("no fingerprint provided") 67 } 68 return p.fingerprint, nil 69 } 70 71 func (p rawConfigurationProvider) Region() (string, error) { 72 if p.region == "" { 73 return "", errors.New("no region provided") 74 } 75 return p.region, nil 76 }