client

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 18 Imported by: 0

README

Go API client for Carbon Aware Sustainability

No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)

Overview

This API client was generated by the swagger-codegen project. By using the swagger-spec from a remote server, you can easily generate an API client.

  • API version: 1.0
  • Package version: 1.0.0
  • Build package: io.swagger.codegen.v3.generators.go.GoClientCodegen

Installation

Put the package under your project folder and add the following in import:

import "github.com/Azure/kubernetes-carbon-intensity-exporter/pkg/sdk/client"

Documentation for API Endpoints

All URIs are relative to https://virtserver.swaggerhub.com/Microsoft-hela/carbonaware/1.0.0

Class Method HTTP request Description
CarbonAwareApi BatchForecastDataAsync Post /emissions/forecasts/batch Given an array of historical forecasts, retrieves the data that contains forecasts metadata, the optimal forecast and a range of forecasts filtered by the attributes [start...end] if provided.
CarbonAwareApi GetAverageCarbonIntensity Get /emissions/average-carbon-intensity Retrieves the measured carbon intensity data between the time boundaries and calculates the average carbon intensity during that period.
CarbonAwareApi GetAverageCarbonIntensityBatch Post /emissions/average-carbon-intensity/batch Given an array of request objects, each with their own location and time boundaries, calculate the average carbon intensity for that location and time period and return an array of carbon intensity objects.
CarbonAwareApi GetBestEmissionsDataForLocationsByTime Get /emissions/bylocations/best Calculate the best emission data by list of locations for a specified time period.
CarbonAwareApi GetCurrentForecastData Get /emissions/forecasts/current Retrieves the most recent forecasted data and calculates the optimal marginal carbon intensity window.
CarbonAwareApi GetEmissionsDataForLocationByTime Get /emissions/bylocation Calculate the best emission data by location for a specified time period.
CarbonAwareApi GetEmissionsDataForLocationsByTime Get /emissions/bylocations Calculate the observed emission data by list of locations for a specified time period.
LocationsApi GetAllLocations Get /locations Get all locations instances

Documentation For Models

Documentation For Authorization

Endpoints do not require authorization.

Author

Documentation

Overview

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

* CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * API version: 1.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

Index

Constants

This section is empty.

Variables

View Source
var (
	// Namespace gets the env variable for the current namespace name.
	Namespace = os.Getenv("NAMESPACE_NAME")

	// PodName gets the env variable for the current pod.
	PodName = os.Getenv("POD_NAME")

	// ContextOAuth2 takes a oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	CarbonAwareApi *CarbonAwareApiService

	LocationsApi *LocationsApiService
	// contains filtered or unexported fields
}

APIClient manages communication with the CarbonAware.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null API v1.0 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

Change base path to allow switching to mocks

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the swagger operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type CarbonAwareApiBatchForecastDataAsyncOpts

type CarbonAwareApiBatchForecastDataAsyncOpts struct {
	Body optional.Interface
}

type CarbonAwareApiGetAverageCarbonIntensityBatchOpts

type CarbonAwareApiGetAverageCarbonIntensityBatchOpts struct {
	Body optional.Interface
}

type CarbonAwareApiGetBestEmissionsDataForLocationsByTimeOpts

type CarbonAwareApiGetBestEmissionsDataForLocationsByTimeOpts struct {
	Time   optional.Time
	ToTime optional.Time
}

type CarbonAwareApiGetCurrentForecastDataOpts

type CarbonAwareApiGetCurrentForecastDataOpts struct {
	DataStartAt optional.Time
	DataEndAt   optional.Time
	WindowSize  optional.Int32
}

type CarbonAwareApiGetEmissionsDataForLocationByTimeOpts

type CarbonAwareApiGetEmissionsDataForLocationByTimeOpts struct {
	StartTime optional.Time
	EndTime   optional.Time
}

type CarbonAwareApiGetEmissionsDataForLocationsByTimeOpts

type CarbonAwareApiGetEmissionsDataForLocationsByTimeOpts struct {
	Time   optional.Time
	ToTime optional.Time
}

type CarbonAwareApiService

type CarbonAwareApiService service

func (*CarbonAwareApiService) BatchForecastDataAsync

func (*CarbonAwareApiService) GetAverageCarbonIntensity

func (a *CarbonAwareApiService) GetAverageCarbonIntensity(ctx context.Context, location string, startTime time.Time, endTime time.Time) (CarbonIntensityDto, *http.Response, error)

CarbonAwareApiService Retrieves the measured carbon intensity data between the time boundaries and calculates the average carbon intensity during that period. This endpoint is useful for reporting the measured carbon intensity for a specific time period in a specific location.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param location The location name where workflow is run
  • @param startTime The time at which the workflow we are measuring carbon intensity for started
  • @param endTime The time at which the workflow we are measuring carbon intensity for ended

@return CarbonIntensityDto

func (*CarbonAwareApiService) GetAverageCarbonIntensityBatch

func (a *CarbonAwareApiService) GetAverageCarbonIntensityBatch(ctx context.Context, localVarOptionals *CarbonAwareApiGetAverageCarbonIntensityBatchOpts) ([]CarbonIntensityDto, *http.Response, error)

func (*CarbonAwareApiService) GetBestEmissionsDataForLocationsByTime

func (a *CarbonAwareApiService) GetBestEmissionsDataForLocationsByTime(ctx context.Context, location []string, localVarOptionals *CarbonAwareApiGetBestEmissionsDataForLocationsByTimeOpts) ([]EmissionsData, *http.Response, error)

func (*CarbonAwareApiService) GetCurrentForecastData

func (a *CarbonAwareApiService) GetCurrentForecastData(ctx context.Context, location []string, localVarOptionals *CarbonAwareApiGetCurrentForecastDataOpts) ([]EmissionsForecastDto, *http.Response, error)

func (*CarbonAwareApiService) GetEmissionsDataForLocationByTime

func (a *CarbonAwareApiService) GetEmissionsDataForLocationByTime(ctx context.Context, location string, localVarOptionals *CarbonAwareApiGetEmissionsDataForLocationByTimeOpts) ([]EmissionsData, *http.Response, error)

func (*CarbonAwareApiService) GetEmissionsDataForLocationsByTime

func (a *CarbonAwareApiService) GetEmissionsDataForLocationsByTime(ctx context.Context, location []string, localVarOptionals *CarbonAwareApiGetEmissionsDataForLocationsByTimeOpts) ([]EmissionsData, *http.Response, error)

type CarbonIntensityBatchParametersDto

type CarbonIntensityBatchParametersDto struct {
	// The location name where workflow is run
	Location string `json:"location,omitempty"`
	// The time at which the workflow we are measuring carbon intensity for started
	StartTime time.Time `json:"startTime,omitempty"`
	// The time at which the workflow we are measuring carbon intensity for ended
	EndTime time.Time `json:"endTime,omitempty"`
}

type CarbonIntensityDto

type CarbonIntensityDto struct {
	// the location name where workflow is run
	Location string `json:"location,omitempty"`
	// the time at which the workflow we are measuring carbon intensity for started
	StartTime time.Time `json:"startTime,omitempty"`
	// the time at which the workflow we are measuring carbon intensity for ended
	EndTime time.Time `json:"endTime,omitempty"`
	// Value of the marginal carbon intensity in grams per kilowatt-hour.
	CarbonIntensity float64 `json:"carbonIntensity,omitempty"`
}

type Configuration

type Configuration struct {
	BasePath      string            `json:"basePath,omitempty"`
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	UserAgent     string            `json:"userAgent,omitempty"`
	HTTPClient    *http.Client
}

func NewConfiguration

func NewConfiguration() *Configuration

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

type EmissionsData

type EmissionsData struct {
	Location string    `json:"location,omitempty"`
	Time     time.Time `json:"time,omitempty"`
	Rating   float64   `json:"rating,omitempty"`
	Duration string    `json:"duration,omitempty"`
}

type EmissionsDataDto

type EmissionsDataDto struct {
	Location  string    `json:"location,omitempty"`
	Timestamp time.Time `json:"timestamp,omitempty"`
	Duration  int32     `json:"duration,omitempty"`
	Value     float64   `json:"value,omitempty"`
}

type EmissionsForecastBatchParametersDto

type EmissionsForecastBatchParametersDto struct {
	// For historical forecast requests, this value is the timestamp used to access the most  recently generated forecast as of that time.
	RequestedAt time.Time `json:"requestedAt,omitempty"`
	// The location of the forecast
	Location string `json:"location,omitempty"`
	// Start time boundary of forecasted data points.Ignores current forecast data points before this time.  Defaults to the earliest time in the forecast data.
	DataStartAt time.Time `json:"dataStartAt,omitempty"`
	// End time boundary of forecasted data points. Ignores current forecast data points after this time.  Defaults to the latest time in the forecast data.
	DataEndAt time.Time `json:"dataEndAt,omitempty"`
	// The estimated duration (in minutes) of the workload.  Defaults to the duration of a single forecast data point.
	WindowSize int32 `json:"windowSize,omitempty"`
}

type EmissionsForecastDto

type EmissionsForecastDto struct {
	// Timestamp when the forecast was generated.
	GeneratedAt time.Time `json:"generatedAt,omitempty"`
	// For current requests, this value is the timestamp the request for forecast data was made.  For historical forecast requests, this value is the timestamp used to access the most   recently generated forecast as of that time.
	RequestedAt time.Time `json:"requestedAt,omitempty"`
	// The location of the forecast
	Location string `json:"location,omitempty"`
	// Start time boundary of forecasted data points. Ignores forecast data points before this time.  Defaults to the earliest time in the forecast data.
	DataStartAt time.Time `json:"dataStartAt,omitempty"`
	// End time boundary of forecasted data points. Ignores forecast data points after this time.  Defaults to the latest time in the forecast data.
	DataEndAt time.Time `json:"dataEndAt,omitempty"`
	// The estimated duration (in minutes) of the workload.  Defaults to the duration of a single forecast data point.
	WindowSize int32 `json:"windowSize,omitempty"`
	// The optimal forecasted data point within the 'forecastData' array.  Null if 'forecastData' array is empty.
	OptimalDataPoints []EmissionsDataDto `json:"optimalDataPoints,omitempty"`
	// The forecasted data points transformed and filtered to reflect the specified time and window parameters.  Points are ordered chronologically; Empty array if all data points were filtered out.  E.G. dataStartAt and dataEndAt times outside the forecast period; windowSize greater than total duration of forecast data;
	ForecastData []EmissionsDataDto `json:"forecastData,omitempty"`
}

type GenericSwaggerError

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

GenericSwaggerError Provides access to the body, error and model on returned errors.

func (GenericSwaggerError) Body

func (e GenericSwaggerError) Body() []byte

Body returns the raw bytes of the response

func (GenericSwaggerError) Error

func (e GenericSwaggerError) Error() string

Error returns non-empty string if there was an error.

func (GenericSwaggerError) Model

func (e GenericSwaggerError) Model() interface{}

Model returns the unpacked model of the error

type Location

type Location struct {
	Latitude  float64 `json:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty"`
	Name      string  `json:"name,omitempty"`
}

type LocationsApiService

type LocationsApiService service

func (*LocationsApiService) GetAllLocations

func (a *LocationsApiService) GetAllLocations(ctx context.Context) (map[string]Location, *http.Response, error)

LocationsApiService Get all locations instances

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().

@return map[string]Location

Jump to

Keyboard shortcuts

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