v1

package
v0.0.0-...-b9d5f24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MPL-2.0 Imports: 7 Imported by: 4

README

github.com/hashicorp/pandora/tools/data-api-sdk/v1

This package contains the SDK for the V1 endpoints within the Data API - intended to be used by the other Pandora tooling.

The majority of the models used in this SDK come from the ./models package - however this package also contains a handful of models for 1:1 compatibility with the API.

Whilst the SDK contains all the supported endpoints, in the majority of cases the LoadAllData method should be sufficient, which can be used like so:

package main

import (
	"context"
	"log"
	
	"github.com/hashicorp/pandora/tools/data-api-sdk/v1"
	"github.com/hashicorp/pandora/tools/data-api-sdk/v1/models"
)

func main() {
	ctx := context.TODO()
	client := v1.NewClient("http://localhost:8888", models.ResourceManagerSourceDataType)
	
	// First check the Data API is available
	resp, err := client.Health(ctx)
	if err != nil {
		log.Fatalf("%+v", err)
	}
	log.Printf("Data API is available: %t", resp.Available)
	
	// Then retrieve all of the Services and all of their associated Data to work against..
	var servicesToLoad []string // this is a list of services to filter to, if empty/nil then every service is loaded
	servicesToLoad = []string{
		"Compute",
    }
	data, err := client.LoadAllData(ctx, servicesToLoad)
	if err != nil {
		log.Fatalf(err.Error())
	}
	log.Printf("retrieved: %+v", data)
}

Finally the ./helpers package contains functions designed to work with each tool within the SDK, including:

  • GolangTypeForSDKObjectDefinition - to obtain the Golang Type Name for an SDK Object Definition.
  • InnerMostSDKObjectDefinition - to obtain the innermost SDK Object Definition.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvailableSourceDataTypes

func AvailableSourceDataTypes() []models.SourceDataType

AvailableSourceDataTypes returns a list of the supported Source Data Types. This can be used to allow tooling to automatically support new Source Data Types as these are defined here, for example by using this information in CLIs.

Types

type APIResourceSummary

type APIResourceSummary struct {
	// OperationsURI specifies the endpoint where information about the Operations for
	// this API Resource can be loaded from.
	OperationsURI string `json:"operationsUri"`

	// SchemaURI specifies the endpoint where information about the Schema for the
	// SDK Constants, Models and Resource IDs for this API Resource can be loaded from.
	SchemaURI string `json:"schemaUri"`
}

type AvailableServiceSummary

type AvailableServiceSummary struct {
	// Generate specifies whether this API should be generated or not
	Generate bool `json:"generate"`

	// Uri is the Uri used to access more information about this Service
	Uri string `json:"uri"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(endpoint string, sourceDataType models.SourceDataType) *Client

NewClient returns an instance of Client configured for the current endpoint and sourceDataType combination - used to retrieve information from the Data API.

func (*Client) DetailsForAPIVersion

func (c *Client) DetailsForAPIVersion(ctx context.Context, apiVersion ServiceAPIVersionSummary) (*DetailsForAPIVersionResponse, error)

DetailsForAPIVersion retrieves information about the specified API Version, including the list of API Resources available within it.

func (*Client) GetAvailableServices

func (c *Client) GetAvailableServices(ctx context.Context) (*GetAvailableServicesResponse, error)

GetAvailableServices returns the list of available Services within this Source Data Type.

func (*Client) GetCommonTypes

func (c *Client) GetCommonTypes(ctx context.Context) (*GetCommonTypesResponse, error)

GetCommonTypes returns the Common SDK Types for this Source Data Type.

func (*Client) GetDetailsForServiceResponse

func (c *Client) GetDetailsForServiceResponse(ctx context.Context, service AvailableServiceSummary) (*GetDetailsForServiceResponse, error)

GetDetailsForServiceResponse returns information about the specified Service, including the list of available API Versions.

func (*Client) GetSDKOperationsForAPIResource

func (c *Client) GetSDKOperationsForAPIResource(ctx context.Context, apiResource APIResourceSummary) (*GetSDKOperationsForAPIResourceResponse, error)

GetSDKOperationsForAPIResource returns the SDK Operations for the specified API Resource (within a given API Version/Service).

func (*Client) GetSDKSchemaForAPIResource

func (c *Client) GetSDKSchemaForAPIResource(ctx context.Context, apiResource APIResourceSummary) (*GetSDKSchemaForAPIResourceResponse, error)

GetSDKSchemaForAPIResource returns the SDK Schema for the specified API Resource (within a given API Version/Service).

func (*Client) GetTerraformDetailsForService

func (c *Client) GetTerraformDetailsForService(ctx context.Context, service ServiceDetailsResponse) (*GetTerraformDetailsForServiceResponse, error)

GetTerraformDetailsForService retrieves the Terraform Details for the specified Service.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (*HealthResponse, error)

Health checks the current status of the Data API, returning whether it's ready to accept requests or not.

func (*Client) LoadAllData

func (c *Client) LoadAllData(ctx context.Context, serviceNamesToLimitTo []string) (*LoadAllDataResult, error)

LoadAllData is a helper function which returns all information for a given SourceDataType from the Data API. This allows implementations to rely on the entire set of source data being available, and means they don't need to reimplement this logic. This function assumes that the Data API is online and available, which can be checked via the Health function.

serviceNamesToLimitTo is an optional value allowing limiting the returned result to a subset of the available services, primarily intended for debugging purposes.

func (*Client) SetLogger

func (c *Client) SetLogger(logger hclog.Logger)

SetLogger enables configuring a logger for debug purposes

type DetailsForAPIVersionResponse

type DetailsForAPIVersionResponse struct {
	// HttpResponse is the raw HTTP Response.
	HttpResponse *http.Response

	// Model describes details about the specified API Version, including the API Resources available within it.
	Model *DetailsForAPIVersionSummary
}

type DetailsForAPIVersionSummary

type DetailsForAPIVersionSummary struct {
	// Resources is a map of API Resource names (key) to APIResourceSummary (value).
	// This can be used to retrieve information about the API Resource in question.
	Resources map[string]APIResourceSummary `json:"resources"`

	// Source specifies the origin of the Source Data for this API version.
	Source models.SourceDataOrigin `json:"source"`
}

type GetAvailableServices

type GetAvailableServices struct {
	// Services is a map of Service Name to AvailableServiceSummary, which can be used to determine
	// the API Versions available for this Service.
	Services map[string]AvailableServiceSummary `json:"services"`
}

type GetAvailableServicesResponse

type GetAvailableServicesResponse struct {
	// HttpResponse is the raw HTTP Response
	HttpResponse *http.Response

	// Model contains a list of the Available Services within this Source Data Type.
	Model *GetAvailableServices
}

type GetCommonTypesResponse

type GetCommonTypesResponse struct {
	// HttpResponse is the raw HTTP Response.
	HttpResponse *http.Response

	// Model is the Common SDK Types for this Source Data Type.
	Model *models.CommonTypes
}

type GetDetailsForServiceResponse

type GetDetailsForServiceResponse struct {
	// HttpResponse is the raw HTTP Response.
	HttpResponse *http.Response

	// Model describes details about the specified Service, including the API Versions that are available.
	Model *ServiceDetailsResponse
}

type GetSDKOperationsForAPIResource

type GetSDKOperationsForAPIResource struct {
	// Operations describes a map of key (Operation Name) to value (SDKOperation) of the
	// SDK Operations available within this API Resource.
	Operations map[string]models.SDKOperation `json:"operations"`
}

type GetSDKOperationsForAPIResourceResponse

type GetSDKOperationsForAPIResourceResponse struct {
	// HttpResponse is the raw HTTP Response.
	HttpResponse *http.Response

	// Model contains the SDKOperations for this APIResource.
	Model *GetSDKOperationsForAPIResource
}

type GetSDKSchemaForAPIResource

type GetSDKSchemaForAPIResource struct {
	// Constants describes a map of Constant Name (key) to SDKConstant (value) used within this APIResource.
	// The Constant Name is a valid Identifier.
	Constants map[string]models.SDKConstant `json:"constants"`

	// Models describes a map of Model Name (key) to SDKModel (value) used within this APIResource.
	// The Model Name is a valid Identifier.
	Models map[string]models.SDKModel `json:"models"`

	// ResourceIDs describes a map of Resource ID Name (key) to ResourceID (value) used within this APIResource.
	// The Resource ID Name is a valid Identifier.
	ResourceIDs map[string]models.ResourceID `json:"resourceIds"`
}

type GetSDKSchemaForAPIResourceResponse

type GetSDKSchemaForAPIResourceResponse struct {
	// HttpResponse is the raw HTTP Response.
	HttpResponse *http.Response

	// Model contains the SDKConstants, SDKModels and ResourceIDs for this APIResource.
	Model *GetSDKSchemaForAPIResource
}

type GetTerraformDetailsForServiceResponse

type GetTerraformDetailsForServiceResponse struct {
	// HttpResponse is the raw HTTP Response.
	HttpResponse *http.Response

	// Model returns the Terraform Definition for this Service.
	Model *models.TerraformDefinition
}

type HealthResponse

type HealthResponse struct {
	// Available specifies whether the Data API is available or not.
	Available bool

	// HttpResponse is the raw HTTP Response
	HttpResponse *http.Response
}

type LoadAllDataResult

type LoadAllDataResult struct {
	// CommonTypes specifies the Common Types which exist across the entire API, rather than being scoped to an
	// APIResource (within an APIVersion within a Service).
	// This allows for Common Types which are defined in _every_ package to be sourced from a single location,
	// reducing the size of each APIResource - particularly where circular references exist in the Types.
	CommonTypes models.CommonTypes

	// Services specifies a map of Service Name (key) to Service (value) representing the available Services for
	// this SourceDataType.
	// The Service Name is a valid Identifier.
	Services map[string]models.Service
}

type ServiceAPIVersionSummary

type ServiceAPIVersionSummary struct {
	// Generate specifies whether this API Version should be generated or not.
	Generate bool `json:"generate"`

	// Preview specifies whether this API Version is a Preview rather than a Stable version.
	Preview bool `json:"preview"`

	// URI specifies the URI where additional information about this API version can be loaded from.
	URI string `json:"uri"`
}

type ServiceDetailsResponse

type ServiceDetailsResponse struct {
	// ResourceProvider specifies the Azure Resource Provider associated with this Service. This is
	// only relevant for Source Data from Resource Manager. For other Source Data Types this is null.
	ResourceProvider *string `json:"resourceProvider,omitempty"`

	// TerraformPackageName specifies the name of the Service Package associated with this Service used
	// in the associated Terraform Provider.
	TerraformPackageName *string `json:"terraformPackageName,omitempty"`

	// TerraformURI specifies the URI where the Terraform-specific information can be loaded from.
	TerraformURI string `json:"terraformUri"`

	// Versions specifies a map of ApiVersion (key) to ServiceAPIVersionSummary, containing
	Versions map[string]ServiceAPIVersionSummary `json:"versions"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL