Documentation ¶
Index ¶
- Constants
- func ProviderOpenAPI(providerName string) (*schema.Provider, error)
- type ClientOpenAPI
- type PluginConfigSchema
- type PluginConfigSchemaV1
- func (p *PluginConfigSchemaV1) GetAllServiceConfigurations() (ServiceConfigurations, error)
- func (p *PluginConfigSchemaV1) GetServiceConfig(providerName string) (ServiceConfiguration, error)
- func (p *PluginConfigSchemaV1) GetVersion() (string, error)
- func (p *PluginConfigSchemaV1) Marshal() ([]byte, error)
- func (p *PluginConfigSchemaV1) Validate() error
- type PluginConfiguration
- type ProviderClient
- func (o *ProviderClient) Delete(resource SpecResource, id string) (*http.Response, error)
- func (o *ProviderClient) Get(resource SpecResource, id string, responsePayload interface{}) (*http.Response, error)
- func (o *ProviderClient) Post(resource SpecResource, requestPayload interface{}, responsePayload interface{}) (*http.Response, error)
- func (o *ProviderClient) Put(resource SpecResource, id string, requestPayload interface{}, ...) (*http.Response, error)
- type ServiceConfigV1
- type ServiceConfiguration
- type ServiceConfigurations
- type SpecAnalyser
- type SpecAnalyserVersion
- type SpecBackendConfiguration
- type SpecHeaderParam
- type SpecHeaderParameters
- type SpecResource
- type SpecSecurity
- type SpecSecurityDefinition
- type SpecSecurityDefinitions
- type SpecSecurityScheme
- type SpecSecuritySchemes
- type SpecV2Resource
Constants ¶
const OpenAPIPluginConfigurationFileName = "terraform-provider-openapi.yaml"
OpenAPIPluginConfigurationFileName defines the file name used for the OpenAPI plugin configuration
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClientOpenAPI ¶ added in v0.4.0
type ClientOpenAPI interface { Post(resource SpecResource, requestPayload interface{}, responsePayload interface{}) (*http.Response, error) Put(resource SpecResource, id string, requestPayload interface{}, responsePayload interface{}) (*http.Response, error) Get(resource SpecResource, id string, responsePayload interface{}) (*http.Response, error) Delete(resource SpecResource, id string) (*http.Response, error) }
ClientOpenAPI defines the behaviour expected to be implemented for the OpenAPI Client used in the Terraform OpenAPI Provider
type PluginConfigSchema ¶ added in v0.1.1
type PluginConfigSchema interface { // Validate performs a check to confirm that the schema content is correct Validate() error // GetServiceConfig returns the service configuration for a given provider name GetServiceConfig(providerName string) (ServiceConfiguration, error) // GetAllServiceConfigurations returns all the service configuration GetAllServiceConfigurations() (ServiceConfigurations, error) // GetVersion returns the plugin configuration version GetVersion() (string, error) // Marshal serializes the value provided into a YAML document Marshal() ([]byte, error) }
PluginConfigSchema defines the interface/expected behaviour for PluginConfigSchema implementations.
type PluginConfigSchemaV1 ¶ added in v0.1.1
type PluginConfigSchemaV1 struct { Version string `yaml:"version"` Services map[string]*ServiceConfigV1 `yaml:"services"` }
PluginConfigSchemaV1 defines PluginConfigSchema version 1 Configuration example: version: '1' services:
monitor: swagger-url: http://monitor-api.com/swagger.json insecure_skip_verify: true cdn: swagger-url: https://cdn-api.com/swagger.json vm: swagger-url: http://vm-api.com/swagger.json
func NewPluginConfigSchemaV1 ¶ added in v0.1.1
func NewPluginConfigSchemaV1(services map[string]*ServiceConfigV1) *PluginConfigSchemaV1
NewPluginConfigSchemaV1 creates a new PluginConfigSchemaV1 that implements PluginConfigSchema interface
func (*PluginConfigSchemaV1) GetAllServiceConfigurations ¶ added in v0.1.2
func (p *PluginConfigSchemaV1) GetAllServiceConfigurations() (ServiceConfigurations, error)
GetAllServiceConfigurations returns all the service configuration
func (*PluginConfigSchemaV1) GetServiceConfig ¶ added in v0.1.1
func (p *PluginConfigSchemaV1) GetServiceConfig(providerName string) (ServiceConfiguration, error)
GetServiceConfig returns the configuration for the given provider name
func (*PluginConfigSchemaV1) GetVersion ¶ added in v0.1.2
func (p *PluginConfigSchemaV1) GetVersion() (string, error)
GetVersion returns the plugin configuration version
func (*PluginConfigSchemaV1) Marshal ¶ added in v0.1.2
func (p *PluginConfigSchemaV1) Marshal() ([]byte, error)
Marshal serializes the value provided into a YAML document
func (*PluginConfigSchemaV1) Validate ¶ added in v0.1.1
func (p *PluginConfigSchemaV1) Validate() error
Validate makes sure that schema data is correct
type PluginConfiguration ¶ added in v0.1.1
type PluginConfiguration struct { // ProviderName defines the <provider_name> (should match the provider name of the terraform provider binary; terraform-provider-<provider_name>) ProviderName string // Configuration defines the reader that contains the plugin's external configuration (located at ~/.terraform.d/plugins) // If the plugin configuration file is not present the OTF_VAR_<provider_name>_SWAGGER_URL environment variable will // be required when invoking the openapi provider. // If at runtime both the OTF_VAR_<provider_name>_SWAGGER_URL as well as the plugin configuration file are present // the former takes preference. This allows the user to override the url specified in the configuration file with // the value provided in the OTF_VAR_<provider_name>_SWAGGER_URL Configuration io.Reader }
PluginConfiguration defines the OpenAPI plugin's configuration
func NewPluginConfiguration ¶ added in v0.1.1
func NewPluginConfiguration(providerName string) (*PluginConfiguration, error)
NewPluginConfiguration creates a new PluginConfiguration
type ProviderClient ¶ added in v0.4.0
type ProviderClient struct {
// contains filtered or unexported fields
}
ProviderClient defines a client that is configured based on the OpenAPI server side documentation The CRUD operations accept an OpenAPI operation which defines among other things the security scheme applicable to the API when making the HTTP request
func (*ProviderClient) Delete ¶ added in v0.4.0
func (o *ProviderClient) Delete(resource SpecResource, id string) (*http.Response, error)
Delete performs a DELETE request to the server API based on the resource configuration and the resource instance id passed in
func (*ProviderClient) Get ¶ added in v0.4.0
func (o *ProviderClient) Get(resource SpecResource, id string, responsePayload interface{}) (*http.Response, error)
Get performs a GET request to the server API based on the resource configuration and the resource instance id passed in
func (*ProviderClient) Post ¶ added in v0.4.0
func (o *ProviderClient) Post(resource SpecResource, requestPayload interface{}, responsePayload interface{}) (*http.Response, error)
Post performs a POST request to the server API based on the resource configuration and the payload passed in
func (*ProviderClient) Put ¶ added in v0.4.0
func (o *ProviderClient) Put(resource SpecResource, id string, requestPayload interface{}, responsePayload interface{}) (*http.Response, error)
Put performs a PUT request to the server API based on the resource configuration and the payload passed in
type ServiceConfigV1 ¶ added in v0.1.1
type ServiceConfigV1 struct { // SwaggerURL defines where the swagger is located SwaggerURL string `yaml:"swagger-url"` // InsecureSkipVerify defines whether the internal http client used to fetch the swagger file should verify the server cert // or not. This should only be used purposefully if the server is using a self-signed cert and only if the server is trusted InsecureSkipVerify bool `yaml:"insecure_skip_verify"` }
ServiceConfigV1 defines configuration for the service provider
func NewServiceConfigV1 ¶ added in v0.1.2
func NewServiceConfigV1(swaggerURL string, insecureSkipVerifyEnabled bool) *ServiceConfigV1
NewServiceConfigV1 creates a new instance of NewServiceConfigV1 struct with the values provided
func NewServiceConfigV1WithDefaults ¶ added in v0.1.2
func NewServiceConfigV1WithDefaults(swaggerURL string) *ServiceConfigV1
NewServiceConfigV1WithDefaults creates a new ServiceConfigV1 with the swaggerURL passed in and default configuration for the rest of the struct fields
func (*ServiceConfigV1) GetSwaggerURL ¶ added in v0.1.1
func (s *ServiceConfigV1) GetSwaggerURL() string
GetSwaggerURL returns the URL where the service swagger doc is exposed
func (*ServiceConfigV1) IsInsecureSkipVerifyEnabled ¶ added in v0.1.1
func (s *ServiceConfigV1) IsInsecureSkipVerifyEnabled() bool
IsInsecureSkipVerifyEnabled returns true if the given provider's service configuration has InsecureSkipVerify enabled; false otherwise
type ServiceConfiguration ¶ added in v0.1.1
type ServiceConfiguration interface { // GetSwaggerURL returns the URL where the service swagger doc is exposed GetSwaggerURL() string // IsInsecureSkipVerifyEnabled returns true if the given provider's service configuration has InsecureSkipVerify enabled; false // otherwise IsInsecureSkipVerifyEnabled() bool }
ServiceConfiguration defines the interface/expected behaviour for ServiceConfiguration implementations.
type ServiceConfigurations ¶ added in v0.1.2
type ServiceConfigurations map[string]ServiceConfiguration
ServiceConfigurations contains the map with all service configurations
type SpecAnalyser ¶ added in v0.4.0
type SpecAnalyser interface { // GetTerraformCompliantResources defines the method that is meant to discover the paths from the OpenAPI document // that are considered Terraform compliant, returning a list of SpecResource or an error otherwise. GetTerraformCompliantResources() ([]SpecResource, error) // GetSecurity returns a SpecSecurity based on the security defined in the OpenAPI document GetSecurity() SpecSecurity // GetAllHeaderParameters returns SpecHeaderParameters containing all the headers defined in the OpenAPI document. This // enabled the OpenAPI provider to expose the headers as configurable properties available in the OpenAPI Terraform // provider; so users can provide values for the headers that are meant to be sent along with the operations the headers // are defined in. GetAllHeaderParameters() (SpecHeaderParameters, error) // GetAPIBackendConfiguration encapsulates all the information related to the backend in the OpenAPI doc // (e,g: host, protocols, etc) which is then used in the ProviderClient to communicate with the API as specified in // the configuration. GetAPIBackendConfiguration() (SpecBackendConfiguration, error) }
SpecAnalyser analyses the swagger doc and provides helper methods to retrieve all the end points that can be used as terraform resources. These endpoints have to meet certain criteria to be considered eligible resources as explained below: A resource is considered any end point that meets the following:
- POST operation on the root path (e,g: api/users)
- GET operation on the instance path (e,g: api/users/{id}). Other operations like DELETE, PUT are optional
In the example above, the resource name would be 'users'. Versioning is also supported, thus if the endpoint above had been api/v1/users the corresponding resouce name would have been 'users_v1'
func CreateSpecAnalyser ¶ added in v0.4.0
func CreateSpecAnalyser(specAnalyserVersion SpecAnalyserVersion, openAPIDocumentURL string) (SpecAnalyser, error)
CreateSpecAnalyser is a factory method that returns the appropriate implementation of SpecAnalyser depending upon the openApiSpecAnalyserVersion passed in. Currently only OpenAPI v2 version is supported but this constructor is ready to handle new implementations such as v3 when the time comes
type SpecAnalyserVersion ¶ added in v0.4.0
type SpecAnalyserVersion string
SpecAnalyserVersion defines the type for versions supported in the SpecAnalyser
type SpecBackendConfiguration ¶ added in v0.4.0
type SpecBackendConfiguration interface {
// contains filtered or unexported methods
}
SpecBackendConfiguration defines the behaviour related to the OpenAPI doc backend configuration
type SpecHeaderParam ¶ added in v0.4.0
SpecHeaderParam defines the properties for a Header Parameter
func (SpecHeaderParam) GetHeaderTerraformConfigurationName ¶ added in v0.4.0
func (h SpecHeaderParam) GetHeaderTerraformConfigurationName() string
GetHeaderTerraformConfigurationName returns the terraform compliant name of the header. If the header TerraformName field is populated it takes preference over the Name field.
type SpecHeaderParameters ¶ added in v0.4.0
type SpecHeaderParameters []SpecHeaderParam
SpecHeaderParameters groups a list of SpecHeaderParam
type SpecResource ¶ added in v0.4.0
type SpecResource interface {
// contains filtered or unexported methods
}
SpecResource defines the behaviour related to terraform compliant OpenAPI Resources.
type SpecSecurity ¶ added in v0.4.0
type SpecSecurity interface { // GetAPIKeySecurityDefinitions returns all the OpenAPI security definitions from the OpenAPI document and translates those // into SpecSecurityDefinitions GetAPIKeySecurityDefinitions() (*SpecSecurityDefinitions, error) // GetGlobalSecuritySchemes returns all the global security schemes from the OpenAPI document and translates those // into SpecSecuritySchemes GetGlobalSecuritySchemes() (SpecSecuritySchemes, error) }
SpecSecurity defines the behaviour related to OpenAPI security. This interface serves as a translation between the OpenAPI document and the security spec that will be used by the OpenAPI Terraform provider
type SpecSecurityDefinition ¶ added in v0.4.0
type SpecSecurityDefinition struct { Name string Type string // apiKey // contains filtered or unexported fields }
SpecSecurityDefinition defines a security definition. This struct serves as a translation between the OpenAPI document and the scheme that will be used by the OpenAPI Terraform provider when making API calls to the backend
type SpecSecurityDefinitions ¶ added in v0.4.0
type SpecSecurityDefinitions []SpecSecurityDefinition
SpecSecurityDefinitions groups a list of SpecSecurityDefinition
type SpecSecurityScheme ¶ added in v0.4.0
type SpecSecurityScheme struct {
Name string
}
SpecSecurityScheme defines a security scheme. This struct serves as a translation between the OpenAPI document and the scheme that will be used by the OpenAPI Terraform provider when making API calls to the backend
type SpecSecuritySchemes ¶ added in v0.4.0
type SpecSecuritySchemes []SpecSecurityScheme
SpecSecuritySchemes groups a list of SpecSecurityScheme
type SpecV2Resource ¶ added in v0.4.0
type SpecV2Resource struct { Name string Region string // Path contains the full relative path to the resource e,g: /v1/resource Path string // SpecSchemaDefinition definition represents the representational state (aka model) of the resource SchemaDefinition spec.Schema // RootPathItem contains info about the resource root path e,g: /resource, including the POST operation used to create instances of this resource RootPathItem spec.PathItem // InstancePathItem contains info about the resource's instance /resource/{id}, including GET, PUT and REMOVE operations if applicable InstancePathItem spec.PathItem // SchemaDefinitions contains all the definitions which might be needed in case the resource schema contains properties // of type object which in turn refer to other definitions SchemaDefinitions map[string]spec.Schema }
SpecV2Resource defines a struct that implements the SpecResource interface and it's based on OpenAPI v2 specification
Source Files ¶
- openapi_client.go
- openapi_client_stub.go
- openapi_spec_analyser.go
- openapi_spec_analyser_stub.go
- openapi_spec_authenticator.go
- openapi_spec_authenticator_api.go
- openapi_spec_authenticator_apikey.go
- openapi_spec_authenticator_apikey_header.go
- openapi_spec_authenticator_apikey_query.go
- openapi_spec_backend_configuration.go
- openapi_spec_header.go
- openapi_spec_resource.go
- openapi_spec_resource_operations.go
- openapi_spec_resource_responses.go
- openapi_spec_resource_schema_definition.go
- openapi_spec_resource_schema_definition_property.go
- openapi_spec_security.go
- openapi_spec_security_definition_apikey.go
- openapi_spec_security_definitions.go
- openapi_spec_security_schemes.go
- openapi_spec_security_stub.go
- openapi_stub_authenticator.go
- openapi_stub_backend_configuration.go
- openapi_stub_resource.go
- openapi_v2_backend_configuration.go
- openapi_v2_headers.go
- openapi_v2_resource.go
- openapi_v2_security.go
- openapi_v2_spec_analyser.go
- plugin_config.go
- plugin_config_schema.go
- plugin_config_services_schema.go
- provider.go
- provider_configuration.go
- provider_factory.go
- resource_factory.go
- test_utils.go
- utils.go