github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/config/clouds/options.go (about)

     1  package clouds
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/vnpaycloud-console/gophercloud/v2"
     7  )
     8  
     9  type cloudOpts struct {
    10  	cloudName        string
    11  	locations        []string
    12  	cloudsyamlReader io.Reader
    13  	secureyamlReader io.Reader
    14  
    15  	applicationCredentialID     string
    16  	applicationCredentialName   string
    17  	applicationCredentialSecret string
    18  	authURL                     string
    19  	domainID                    string
    20  	domainName                  string
    21  	endpointType                string
    22  	password                    string
    23  	projectID                   string
    24  	projectName                 string
    25  	region                      string
    26  	scope                       *gophercloud.AuthScope
    27  	token                       string
    28  	userID                      string
    29  	username                    string
    30  
    31  	caCertPath     string
    32  	clientCertPath string
    33  	clientKeyPath  string
    34  	insecure       *bool
    35  }
    36  
    37  // ParseOption one of parse configuration returned by With* modifier
    38  type ParseOption = func(*cloudOpts)
    39  
    40  // WithCloudName allows to override the environment variable `OS_CLOUD`.
    41  func WithCloudName(osCloud string) ParseOption {
    42  	return func(co *cloudOpts) {
    43  		co.cloudName = osCloud
    44  	}
    45  }
    46  
    47  // WithLocations is a functional option that sets the search locations for the
    48  // clouds.yaml file (and its optional companion secure.yaml). Each location is
    49  // a file path pointing to a possible `clouds.yaml`.
    50  func WithLocations(locations ...string) ParseOption {
    51  	return func(co *cloudOpts) {
    52  		co.locations = locations
    53  	}
    54  }
    55  
    56  // WithCloudsYAML is a functional option that lets you pass a clouds.yaml file
    57  // as an io.Reader interface. When this option is passed, FromCloudsYaml will
    58  // not attempt to fetch any file from the file system. To add a secure.yaml,
    59  // use in conjunction with WithSecureYAML.
    60  func WithCloudsYAML(clouds io.Reader) ParseOption {
    61  	return func(co *cloudOpts) {
    62  		co.cloudsyamlReader = clouds
    63  	}
    64  }
    65  
    66  // WithSecureYAML is a functional option that lets you pass a secure.yaml file
    67  // as an io.Reader interface, to complement the clouds.yaml that is either
    68  // fetched from the filesystem, or passed with WithCloudsYAML.
    69  func WithSecureYAML(secure io.Reader) ParseOption {
    70  	return func(co *cloudOpts) {
    71  		co.secureyamlReader = secure
    72  	}
    73  }
    74  
    75  func WithApplicationCredentialID(applicationCredentialID string) ParseOption {
    76  	return func(co *cloudOpts) {
    77  		co.applicationCredentialID = applicationCredentialID
    78  	}
    79  }
    80  
    81  func WithApplicationCredentialName(applicationCredentialName string) ParseOption {
    82  	return func(co *cloudOpts) {
    83  		co.applicationCredentialName = applicationCredentialName
    84  	}
    85  }
    86  
    87  func WithApplicationCredentialSecret(applicationCredentialSecret string) ParseOption {
    88  	return func(co *cloudOpts) {
    89  		co.applicationCredentialSecret = applicationCredentialSecret
    90  	}
    91  }
    92  
    93  func WithIdentityEndpoint(authURL string) ParseOption {
    94  	return func(co *cloudOpts) {
    95  		co.authURL = authURL
    96  	}
    97  }
    98  
    99  func WithDomainID(domainID string) ParseOption {
   100  	return func(co *cloudOpts) {
   101  		co.domainID = domainID
   102  	}
   103  }
   104  
   105  func WithDomainName(domainName string) ParseOption {
   106  	return func(co *cloudOpts) {
   107  		co.domainName = domainName
   108  	}
   109  }
   110  
   111  // WithRegion allows to override the endpoint type set in clouds.yaml or in the
   112  // environment variable `OS_INTERFACE`.
   113  func WithEndpointType(endpointType string) ParseOption {
   114  	return func(co *cloudOpts) {
   115  		co.endpointType = endpointType
   116  	}
   117  }
   118  
   119  func WithPassword(password string) ParseOption {
   120  	return func(co *cloudOpts) {
   121  		co.password = password
   122  	}
   123  }
   124  
   125  func WithProjectID(projectID string) ParseOption {
   126  	return func(co *cloudOpts) {
   127  		co.projectID = projectID
   128  	}
   129  }
   130  
   131  func WithProjectName(projectName string) ParseOption {
   132  	return func(co *cloudOpts) {
   133  		co.projectName = projectName
   134  	}
   135  }
   136  
   137  // WithRegion allows to override the region set in clouds.yaml or in the
   138  // environment variable `OS_REGION_NAME`
   139  func WithRegion(region string) ParseOption {
   140  	return func(co *cloudOpts) {
   141  		co.region = region
   142  	}
   143  }
   144  
   145  func WithScope(scope *gophercloud.AuthScope) ParseOption {
   146  	return func(co *cloudOpts) {
   147  		co.scope = scope
   148  	}
   149  }
   150  
   151  func WithToken(token string) ParseOption {
   152  	return func(co *cloudOpts) {
   153  		co.token = token
   154  	}
   155  }
   156  
   157  func WithUserID(userID string) ParseOption {
   158  	return func(co *cloudOpts) {
   159  		co.userID = userID
   160  	}
   161  }
   162  
   163  func WithUsername(username string) ParseOption {
   164  	return func(co *cloudOpts) {
   165  		co.username = username
   166  	}
   167  }
   168  
   169  func WithCACertPath(caCertPath string) ParseOption {
   170  	return func(co *cloudOpts) {
   171  		co.caCertPath = caCertPath
   172  	}
   173  }
   174  
   175  func WithClientCertPath(clientCertPath string) ParseOption {
   176  	return func(co *cloudOpts) {
   177  		co.clientCertPath = clientCertPath
   178  	}
   179  }
   180  
   181  func WithClientKeyPath(clientKeyPath string) ParseOption {
   182  	return func(co *cloudOpts) {
   183  		co.clientKeyPath = clientKeyPath
   184  	}
   185  }
   186  
   187  func WithInsecure(insecure bool) ParseOption {
   188  	return func(co *cloudOpts) {
   189  		co.insecure = &insecure
   190  	}
   191  }