transformer

package
v0.0.0-...-a4b769c Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUniqueIDForAPI

func GetUniqueIDForAPI(name, version, organization string) string

GetUniqueIDForAPI will generate a unique ID for newly created APIs

func ReadContent

func ReadContent(file *zip.File) ([]byte, error)

ReadContent read the content of file

func StringExists

func StringExists(target string, slice []string) bool

StringExists checks for the existance of a particular string a string slice

func UpdateCRS

func UpdateCRS(k8sArtifact *K8sArtifacts, environments *[]Environment, organizationID string, apiUUID string, revisionID string, namespace string, configuredRateLimitPoliciesMap map[string]eventHub.RateLimitPolicy)

UpdateCRS cr update

Types

type API

type API struct {
	Name                   string                  `yaml:"name,omitempty"`
	ID                     string                  `yaml:"id,omitempty"`
	Version                string                  `yaml:"version,omitempty"`
	Context                string                  `yaml:"basePath,omitempty"`
	Type                   string                  `yaml:"type,omitempty"`
	DefaultVersion         bool                    `yaml:"defaultVersion"`
	DefinitionPath         string                  `yaml:"definitionPath,omitempty"`
	EndpointConfigurations *EndpointConfigurations `yaml:"endpointConfigurations,omitempty"`
	Operations             *[]Operation            `yaml:"operations,omitempty"`
	Authentication         *[]AuthConfiguration    `yaml:"authentication,omitempty"`
	CorsConfig             *CORSConfiguration      `yaml:"corsConfiguration,omitempty"`
	AdditionalProperties   *[]AdditionalProperty   `yaml:"additionalProperties,omitempty"`
	SubscriptionValidation bool                    `yaml:"subscriptionValidation,omitempty"`
	RateLimit              *RateLimit              `yaml:"rateLimit,omitempty"`
	APIPolicies            *OperationPolicies      `yaml:"apiPolicies,omitempty"`
}

API represents an main API type definition

type APIArtifact

type APIArtifact struct {
	APIJson              string               `json:"apiJson"`
	APIFileName          string               `json:"apiFileName"`
	EnvConfig            string               `json:"envConfig"`
	Schema               string               `json:"schema"`
	DeploymentDescriptor string               `json:"deploymentDescriptor"`
	CertArtifact         CertificateArtifact  `json:"certArtifact"`
	RevisionID           uint32               `json:"revisionId"`
	CertMeta             CertMetadata         `json:"certMeta"`
	EndpointCertMeta     EndpointCertMetadata `json:"endpintCertMeta"`
}

APIArtifact represents the artifact details of an API, including api details, environment configuration, Swagger definition, deployment descriptor, and revision ID extracted from the API Project Zip.

func DecodeAPIArtifact

func DecodeAPIArtifact(apiZip *zip.File) (*APIArtifact, error)

DecodeAPIArtifact decodes a zip-encoded API payload, extracting API details like JSON, Swagger, and deployment configuration. Returns the APIArtifact or an error if decoding or extraction fails.

type APIIdentifier

type APIIdentifier struct {
	ProviderName string `json:"providerName"`
	APIName      string `json:"apiName"`
	Version      string `json:"version"`
	UUID         string `json:"uuid"`
	ID           int    `json:"id"`
}

APIIdentifier holds information about an API associated for a given client certificate

type APIMApi

type APIMApi struct {
	ID                   string                 `yaml:"id"`
	Name                 string                 `yaml:"name"`
	Version              string                 `yaml:"version"`
	Context              string                 `yaml:"context"`
	DefaultVersion       bool                   `json:"isDefaultVersion"`
	Type                 string                 `yaml:"type"`
	AuthorizationHeader  string                 `yaml:"authorizationHeader"`
	SecuritySchemes      []string               `json:"securityScheme"`
	AdditionalProperties []AdditionalProperties `yaml:"additionalProperties"`
	// AdditionalPropertiesMap []AdditionalPropertiesMap `yaml:"additionalPropertiesMap"`
	CORSConfiguration   CORSConfiguration     `yaml:"corsConfiguration"`
	EndpointConfig      EndpointConfig        `yaml:"endpointConfig"`
	Operations          []APIMOperation       `yaml:"operations"`
	OrganizationID      string                `yaml:"organizationId"`
	RevisionID          uint32                `yaml:"revisionId"`
	RevisionedAPIID     string                `yaml:"revisionedApiId"`
	APIThrottlingPolicy string                `yaml:"apiThrottlingPolicy"`
	APIPolicies         APIMOperationPolicies `yaml:"apiPolicies"`
}

APIMApi represents an API along with it's all basic information and the operations.

type APIMOperation

type APIMOperation struct {
	Target            string                 `yaml:"target"`
	Verb              string                 `yaml:"verb"`
	Scopes            []string               `yaml:"scopes"`
	OperationPolicies *APIMOperationPolicies `yaml:"operationPolicies"`
	ThrottlingPolicy  string                 `yaml:"throttlingPolicy"`
}

APIMOperation represents an API operation with its target, verb, scopes, and associated policies.

type APIMOperationPolicies

type APIMOperationPolicies struct {
	Request  []APIMOperationPolicy `yaml:"request"`
	Response []APIMOperationPolicy `yaml:"response"`
	Fault    []APIMOperationPolicy `yaml:"fault"`
}

APIMOperationPolicies organizes request, response, and fault policies for an API operation.

type APIMOperationPolicy

type APIMOperationPolicy struct {
	PolicyName    string                 `yaml:"policyName,omitempty"`
	PolicyVersion string                 `yaml:"policyVersion,omitempty"`
	PolicyID      string                 `yaml:"policyId,omitempty"`
	Parameters    map[string]interface{} `yaml:"parameters,omitempty"`
}

APIMOperationPolicy defines policies, including interceptor parameters, for API operations.

type APIYaml

type APIYaml struct {
	Data APIMApi `json:"data"`
}

APIYaml is a wrapper struct for YAML representation of an API.

type AdditionalProperties

type AdditionalProperties struct {
	Name               string `yaml:"name"`
	Value              string `yaml:"value"`
	DisplayInDevPortal bool   `yaml:"display"`
}

AdditionalProperties represents additional properties for an API in the form of a map.

type AdditionalProperty

type AdditionalProperty struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

AdditionalProperty stores the custom properties set by the user for a particular API

type AuthConfiguration

type AuthConfiguration struct {
	Required          string `yaml:"required,omitempty"`
	AuthType          string `yaml:"authType,omitempty"`
	HeaderName        string `yaml:"headerName,omitempty"`
	SendTokenUpStream bool   `yaml:"sendTokenToUpstream,omitempty"`
	Enabled           bool   `yaml:"enabled,omitempty"`
	QueryParamName    string `yaml:"queryParamName,omitempty"`
	HeaderEnabled     bool   `yaml:"headerEnable,omitempty"`

	Certificates []Certificate `yaml:"certificates,omitempty"`
	Audience     []string      `yaml:"audience,omitempty"`
	// contains filtered or unexported fields
}

AuthConfiguration represents the security configurations made for the API security

type BackendJWT

type BackendJWT struct {
	Encoding         string `yaml:"encoding,omitempty"`
	Header           string `yaml:"header,omitempty"`
	SigningAlgorithm string `yaml:"signingAlgorithm,omitempty"`
	TokenTTL         int    `yaml:"tokenTTL,omitempty"`
}

BackendJWT holds configuration details for configuring JWT for backend

type CORSConfiguration

type CORSConfiguration struct {
	CORSConfigurationEnabled      bool     `yaml:"corsConfigurationEnabled"`
	AccessControlAllowOrigins     []string `yaml:"accessControlAllowOrigins"`
	AccessControlAllowCredentials bool     `yaml:"accessControlAllowCredentials"`
	AccessControlAllowHeaders     []string `yaml:"accessControlAllowHeaders"`
	AccessControlAllowMethods     []string `yaml:"accessControlAllowMethods"`
}

CORSConfiguration represents the CORS (Cross-Origin Resource Sharing) configuration for an API.

type CertContainer

type CertContainer struct {
	ClientCertObj   CertMetadata
	EndpointCertObj EndpointCertMetadata
	SecretData      EndpointSecurityConfig
}

CertContainer acts as a wrapper to hold onto all the certificate details for both endpoint and client-side security configs belong to a particular API Project

type CertDescriptor

type CertDescriptor struct {
	CertData []ClientCert `json:"data"`
}

CertDescriptor contains data related to one or more client certificates for an API

type CertMetadata

type CertMetadata struct {
	CertAvailable   bool              `json:"certAvailable"`
	ClientCertFiles map[string]string `json:"clientCertFiles"`
}

CertMetadata marks the availability of the cert files provided by the client and their contents

type Certificate

type Certificate struct {
	Name string `json:"name"`
	Key  string `json:"key"`
}

Certificate struct stores the the alias and the name for a particular mTLS configuration

type CertificateArtifact

type CertificateArtifact struct {
	ClientCerts   string `json:"clientCert"`
	EndpointCerts string `json:"endpointCert"`
}

CertificateArtifact stores the parsed file content created inside the API project zip upon enabling certificate aided security options

type ClientCert

type ClientCert struct {
	Alias         string        `json:"alias"`
	Certificate   string        `json:"certificate"`
	TierName      string        `json:"tierName"`
	APIIdentifier APIIdentifier `json:"apiIdentifier"`
}

ClientCert holds the data belongs to a single client certificate configuration

type CustomParams

type CustomParams struct {
	CustomParamMapping map[string]string `json:"customParamMapping"`
}

CustomParams holds the custom parameter values that has been enabled for the selected security mode

type Deployment

type Deployment struct {
	APIFile        string         `json:"apiFile"`
	Environments   *[]Environment `json:"environments"`
	OrganizationID string         `json:"organizationId"`
}

Deployment represents the deployment details for a set of environments within an organization.

type DeploymentDescriptor

type DeploymentDescriptor struct {
	Type    string       `json:"type"`
	Version string       `json:"version"`
	Data    *Deployments `json:"data"`
}

DeploymentDescriptor represents deployment descriptor data which belongs to a particular API artifact

func ProcessDeploymentDescriptor

func ProcessDeploymentDescriptor(deploymentDescriptor []byte) (*DeploymentDescriptor, error)

ProcessDeploymentDescriptor processes the artifact and returns the deployment descriptor struct

type Deployments

type Deployments struct {
	Deployments *[]Deployment `json:"deployments"`
}

Deployments represents a collection of Deployment instances.

type EndpointCert

type EndpointCert struct {
	Alias       string `json:"alias"`
	Endpoint    string `json:"endpoint"`
	Certificate string `json:"certificate"`
	TenantID    int    `json:"tenantId"`
}

EndpointCert holds the data belongs to a single endpoint certificate configuration

type EndpointCertDescriptor

type EndpointCertDescriptor struct {
	EndpointCertData []EndpointCert `json:"data"`
}

EndpointCertDescriptor contains data related to one or more endpoint certificates for an API

type EndpointCertMetadata

type EndpointCertMetadata struct {
	CertAvailable     bool              `json:"certAvailable"`
	EndpointCertFiles map[string]string `json:"endpointCertFiles"`
}

EndpointCertMetadata marks the availability of the endpoint certificates and stores the cert contents

type EndpointCertificate

type EndpointCertificate struct {
	Name string `yaml:"secretName"`
	Key  string `yaml:"secretKey"`
}

EndpointCertificate struct stores the the alias and the name for a particular endpoint security configuration

type EndpointConfig

type EndpointConfig struct {
	EndpointType        string                 `json:"endpoint_type"`
	SandboxEndpoints    EndpointDetails        `json:"sandbox_endpoints"`
	ProductionEndpoints EndpointDetails        `json:"production_endpoints"`
	EndpointSecurity    EndpointSecurityConfig `json:"endpoint_security"`
}

EndpointConfig represents the configuration of an endpoint, including its type, sandbox, and production details.

type EndpointConfiguration

type EndpointConfiguration struct {
	Endpoint       string              `yaml:"endpoint,omitempty"`
	EndCertificate EndpointCertificate `yaml:"certificate,omitempty"`
	EndSecurity    EndpointSecurity    `yaml:"endpointSecurity,omitempty"`
}

EndpointConfiguration stores the data related to endpoints and their related

type EndpointConfigurations

type EndpointConfigurations struct {
	Production *EndpointConfiguration `yaml:"production,omitempty"`
	Sandbox    *EndpointConfiguration `yaml:"sandbox,omitempty"`
}

EndpointConfigurations holds production and sandbox endpoints.

type EndpointDetails

type EndpointDetails struct {
	URL string `json:"url"`
}

EndpointDetails represents the details of an endpoint, containing its URL.

type EndpointSecurity

type EndpointSecurity struct {
	Enabled      bool       `yaml:"enabled,omitempty"`
	SecurityType SecretInfo `yaml:"securityType,omitempty"`
}

EndpointSecurity comtains the information related to endpoint security configurations enabled by a user for a given API

type EndpointSecurityConfig

type EndpointSecurityConfig struct {
	Production SecurityObj `json:"production"`
	Sandbox    SecurityObj `json:"sandbox"`
}

EndpointSecurityConfig holds security configs enabled for endpoints from the API level

func GenerateAPKConf

func GenerateAPKConf(APIJson string, certArtifact CertificateArtifact, organizationID string) (string, string, uint32, map[string]eventHub.RateLimitPolicy, EndpointSecurityConfig, error)

GenerateAPKConf will Generate the mapped .apk-conf file for a given API Project zip

type Environment

type Environment struct {
	Name              string `json:"name"`
	Vhost             string `json:"vhost"`
	DeployedTimeStamp int64  `json:"deployedTimeStamp"`
	Type              string `json:"type"`
}

Environment represents the configuration details for a specific environment.

type InterceptorService

type InterceptorService struct {
	BackendURL      string `yaml:"backendUrl,omitempty"`
	HeadersEnabled  bool   `yaml:"headersEnabled,omitempty"`
	BodyEnabled     bool   `yaml:"bodyEnabled,omitempty"`
	TrailersEnabled bool   `yaml:"trailersEnabled,omitempty"`
	ContextEnabled  bool   `yaml:"contextEnabled,omitempty"`
	TLSSecretName   string `yaml:"tlsSecretName,omitempty"`
	TLSSecretKey    string `yaml:"tlsSecretKey,omitempty"`
}

InterceptorService holds configuration details for configuring interceptor for a aperticular API requests or responses.

type K8sArtifacts

type K8sArtifacts struct {
	API                 dpv1alpha2.API
	HTTPRoutes          map[string]*gwapiv1.HTTPRoute
	GQLRoutes           map[string]*dpv1alpha2.GQLRoute
	Backends            map[string]*v1alpha1.Backend
	Scopes              map[string]*v1alpha1.Scope
	Authentication      map[string]*dpv1alpha2.Authentication
	APIPolicies         map[string]*dpv1alpha2.APIPolicy
	InterceptorServices map[string]*v1alpha1.InterceptorService
	ConfigMaps          map[string]*corev1.ConfigMap
	Secrets             map[string]*corev1.Secret
	BackendJWT          *v1alpha1.BackendJWT
	RateLimitPolicies   map[string]*v1alpha1.RateLimitPolicy
}

K8sArtifacts k8s artifact representation of API

func GenerateCRs

func GenerateCRs(apkConf string, apiDefinition string, certContainer CertContainer, k8ResourceGenEndpoint string, organizationID string) (*K8sArtifacts, error)

GenerateCRs takes the .apk-conf, api definition, vHost and the organization for a particular API and then generate and returns the relavant CRD set as a zip

type Operation

type Operation struct {
	Target            string             `yaml:"target,omitempty"`
	Verb              string             `yaml:"verb,omitempty"`
	Scopes            []string           `yaml:"scopes"`
	Secured           bool               `yaml:"secured,omitempty"`
	OperationPolicies *OperationPolicies `yaml:"operationPolicies,omitempty"`
	RateLimit         *RateLimit         `yaml:"rateLimit,omitempty"`
}

Operation represents an API operation with target, verb, scopes, security, and associated policies.

type OperationPolicies

type OperationPolicies struct {
	Request  []OperationPolicy `yaml:"request,omitempty"`
	Response []OperationPolicy `yaml:"response,omitempty"`
}

OperationPolicies organizes request and response policies for an API operation.

type OperationPolicy

type OperationPolicy struct {
	PolicyName    string    `yaml:"policyName,omitempty"`
	PolicyVersion string    `yaml:"policyVersion,omitempty"`
	PolicyID      string    `yaml:"policyId,omitempty"`
	Parameters    Parameter `yaml:"parameters,omitempty"`
}

OperationPolicy defines policies, including interceptor parameters, for API operations.

type Parameter

type Parameter interface {
	// contains filtered or unexported methods
}

Parameter interface is used to define the type of parameters that can be used in an operation policy.

type RateLimit

type RateLimit struct {
	RequestsPerUnit int    `yaml:"requestsPerUnit,omitempty"`
	Unit            string `yaml:"unit,omitempty"`
}

RateLimit is a placeholder for future rate-limiting configuration.

type SecretInfo

type SecretInfo struct {
	SecretName  string `yaml:"secretName,omitempty"`
	UsernameKey string `yaml:"userNameKey,omitempty"`
	PasswordKey string `yaml:"passwordKey,omitempty"`
}

SecretInfo holds the info related to the created secret upon enabling the endpoint security options like basic auth

type SecurityObj

type SecurityObj struct {
	Enabled          bool                   `json:"enabled"`
	Type             string                 `json:"type"`
	Username         string                 `json:"username"`
	Password         string                 `json:"password"`
	GrantType        string                 `json:"grantType"`
	TokenURL         string                 `json:"tokenUrl"`
	ClientID         string                 `json:"clientId"`
	ClientSecret     string                 `json:"clientSecret"`
	CustomParameters map[string]interface{} `json:"customParameters"`
}

SecurityObj holds the idividual attribute values for each endpoint security config

type VHost

type VHost struct {
	Production []string `yaml:"production,omitempty"`
	Sandbox    []string `yaml:"sandbox,omitempty"`
}

VHost defines virtual hosts for production and sandbox environments.

Jump to

Keyboard shortcuts

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