apisix

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 32 Imported by: 1

Documentation

Overview

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClusterNotExist means a cluster doesn't exist.
	ErrClusterNotExist = errors.New("cluster not exist")
	// ErrDuplicatedCluster means the cluster adding request was
	// rejected since the cluster was already created.
	ErrDuplicatedCluster = errors.New("duplicated cluster")
	// ErrFunctionDisabled means the APISIX function is disabled
	ErrFunctionDisabled = errors.New("function disabled")

	// ErrRouteNotFound means the [route, ssl, upstream] was not found.
	ErrNotFound = cache.ErrNotFound
)
View Source
var (
	ErrUnknownApisixResourceType = errors.New("unknown apisix resource type")
)

Functions

func AesDecrypt added in v1.7.0

func AesDecrypt(crypted, key []byte) ([]byte, error)

func AesEencryptPrivatekey added in v1.7.0

func AesEencryptPrivatekey(data []byte, aeskey []byte) (string, error)

func AesEncrypt added in v1.7.0

func AesEncrypt(origData, key []byte) ([]byte, error)

func CompareResourceEqualFromCluster added in v1.7.0

func CompareResourceEqualFromCluster[T ResourceTypes](cluster *cluster, id string, Resource T) bool

func PKCS5Padding added in v1.7.0

func PKCS5Padding(plaintext []byte, blockSize int) []byte

func PKCS5UnPadding added in v1.7.0

func PKCS5UnPadding(origData []byte) []byte

Types

type APISIX

type APISIX interface {
	// Cluster specifies the target cluster to talk.
	Cluster(name string) Cluster
	// AddCluster adds a new cluster.
	AddCluster(context.Context, *ClusterOptions) error
	// UpdateCluster updates an existing cluster.
	UpdateCluster(context.Context, *ClusterOptions) error
	// ListClusters lists all APISIX clusters.
	ListClusters() []Cluster
	// DeleteCluster deletes the target APISIX cluster by its name.
	DeleteCluster(name string)
}

APISIX is the unified client tool to communicate with APISIX.

func NewClient

func NewClient(version string) (APISIX, error)

NewClient creates an APISIX client to perform resources change pushing.

type APISIXSchema added in v1.7.0

type APISIXSchema struct {
	Plugins       map[string]SchemaPlugin `json:"plugins"`
	StreamPlugins map[string]SchemaPlugin `json:"stream_plugins"`
}

type APISIXSchemaValidator added in v1.7.0

type APISIXSchemaValidator interface {
	ValidateStreamPluginSchema(plugins v1.Plugins) (bool, error)
	ValidateHTTPPluginSchema(plugins v1.Plugins) (bool, error)
}

func NewReferenceFile added in v1.7.0

func NewReferenceFile(source string) (APISIXSchemaValidator, error)

type Cluster

type Cluster interface {
	// Route returns a Route interface that can operate Route resources.
	Route() Route
	// Upstream returns a Upstream interface that can operate Upstream resources.
	Upstream() Upstream
	// SSL returns a SSL interface that can operate SSL resources.
	SSL() SSL
	// StreamRoute returns a StreamRoute interface that can operate StreamRoute resources.
	StreamRoute() StreamRoute
	// GlobalRule returns a GlobalRule interface that can operate GlobalRule resources.
	GlobalRule() GlobalRule
	// String exposes the client information in human-readable format.
	String() string
	// HasSynced checks whether all resources in APISIX cluster is synced to cache.
	HasSynced(context.Context) error
	// Consumer returns a Consumer interface that can operate Consumer resources.
	Consumer() Consumer
	// HealthCheck checks apisix cluster health in realtime.
	HealthCheck(context.Context) error
	// Plugin returns a Plugin interface that can operate Plugin resources.
	Plugin() Plugin
	// PluginConfig returns a PluginConfig interface that can operate PluginConfig resources.
	PluginConfig() PluginConfig
	// Schema returns a Schema interface that can fetch schema of APISIX objects.
	Schema() Schema

	PluginMetadata() PluginMetadata
	// UpstreamServiceRelation returns a UpstreamServiceRelation interface that can fetch UpstreamServiceRelation of APISIX objects.
	UpstreamServiceRelation() UpstreamServiceRelation

	Validator() APISIXSchemaValidator
}

Cluster defines specific operations that can be applied in an APISIX cluster.

type ClusterOptions

type ClusterOptions struct {
	AdminAPIVersion string
	Name            string
	AdminKey        string
	BaseURL         string
	Timeout         time.Duration
	// SyncInterval is the interval to sync schema.
	SyncInterval      types.TimeDuration
	SyncComparison    bool
	MetricsCollector  metrics.Collector
	EnableEtcdServer  bool
	Prefix            string
	ListenAddress     string
	SchemaSynced      bool
	CacheSynced       bool
	SSLKeyEncryptSalt string
}

ClusterOptions contains parameters to customize APISIX client.

type Consumer added in v1.0.0

type Consumer interface {
	Get(ctx context.Context, name string) (*v1.Consumer, error)
	List(ctx context.Context) ([]*v1.Consumer, error)
	Create(ctx context.Context, consumer *v1.Consumer, shouldCompare bool) (*v1.Consumer, error)
	Delete(ctx context.Context, consumer *v1.Consumer) error
	Update(ctx context.Context, consumer *v1.Consumer, shouldCompare bool) (*v1.Consumer, error)
}

Consumer is the specific client interface to take over the create, update, list and delete for APISIX Consumer resource.

type GlobalRule added in v1.0.0

type GlobalRule interface {
	Get(ctx context.Context, id string) (*v1.GlobalRule, error)
	List(ctx context.Context) ([]*v1.GlobalRule, error)
	Create(ctx context.Context, rule *v1.GlobalRule, shouldCompare bool) (*v1.GlobalRule, error)
	Delete(ctx context.Context, rule *v1.GlobalRule) error
	Update(ctx context.Context, rule *v1.GlobalRule, shouldCompare bool) (*v1.GlobalRule, error)
}

GlobalRule is the specific client interface to take over the create, update, list and delete for APISIX Global Rule resource.

type IntOrString added in v1.0.0

type IntOrString struct {
	IntValue int `json:"int_value"`
}

IntOrString processing number and string types, after json deserialization will output int

func (*IntOrString) UnmarshalJSON added in v1.0.0

func (ios *IntOrString) UnmarshalJSON(p []byte) error

type Plugin added in v1.2.0

type Plugin interface {
	List(ctx context.Context) ([]string, error)
}

Plugin is the specific client interface to fetch APISIX Plugin resource.

type PluginConfig added in v1.4.0

type PluginConfig interface {
	Get(ctx context.Context, name string) (*v1.PluginConfig, error)
	List(ctx context.Context) ([]*v1.PluginConfig, error)
	Create(ctx context.Context, plugin *v1.PluginConfig, shouldCompare bool) (*v1.PluginConfig, error)
	Delete(ctx context.Context, plugin *v1.PluginConfig) error
	Update(ctx context.Context, plugin *v1.PluginConfig, shouldCompare bool) (*v1.PluginConfig, error)
}

PluginConfig is the specific client interface to take over the create, update, list and delete for APISIX PluginConfig resource.

type PluginMetadata added in v1.7.0

type PluginMetadata interface {
	Get(ctx context.Context, name string) (*v1.PluginMetadata, error)
	List(ctx context.Context) ([]*v1.PluginMetadata, error)
	Delete(ctx context.Context, metadata *v1.PluginMetadata) error
	Update(ctx context.Context, metadata *v1.PluginMetadata, shouldCompare bool) (*v1.PluginMetadata, error)
	Create(ctx context.Context, metadata *v1.PluginMetadata, shouldCompare bool) (*v1.PluginMetadata, error)
}

type PluginSchemaDef added in v1.7.0

type PluginSchemaDef map[string]gojsonschema.JSONLoader

type ResourceTypes added in v1.7.0

type ResourceTypes interface {
	*v1.Route | *v1.Ssl | *v1.Upstream | *v1.StreamRoute | *v1.GlobalRule | *v1.Consumer | *v1.PluginConfig
}

type Route

type Route interface {
	Get(ctx context.Context, name string) (*v1.Route, error)
	List(ctx context.Context) ([]*v1.Route, error)
	Create(ctx context.Context, route *v1.Route, shouldCompare bool) (*v1.Route, error)
	Delete(ctx context.Context, route *v1.Route) error
	Update(ctx context.Context, route *v1.Route, shouldCompare bool) (*v1.Route, error)
}

Route is the specific client interface to take over the create, update, list and delete for APISIX Route resource.

type SSL

type SSL interface {
	// name is namespace_sslname
	Get(ctx context.Context, name string) (*v1.Ssl, error)
	List(ctx context.Context) ([]*v1.Ssl, error)
	Create(ctx context.Context, ssl *v1.Ssl, shouldCompare bool) (*v1.Ssl, error)
	Delete(ctx context.Context, ssl *v1.Ssl) error
	Update(ctx context.Context, ssl *v1.Ssl, shouldCompare bool) (*v1.Ssl, error)
}

SSL is the specific client interface to take over the create, update, list and delete for APISIX SSL resource.

type Schema added in v1.2.0

type Schema interface {
	GetPluginSchema(ctx context.Context, pluginName string) (*v1.Schema, error)
	GetRouteSchema(ctx context.Context) (*v1.Schema, error)
	GetUpstreamSchema(ctx context.Context) (*v1.Schema, error)
	GetConsumerSchema(ctx context.Context) (*v1.Schema, error)
	GetSslSchema(ctx context.Context) (*v1.Schema, error)
	GetPluginConfigSchema(ctx context.Context) (*v1.Schema, error)
}

Schema is the specific client interface to fetch the schema of APISIX objects.

type SchemaPlugin added in v1.7.0

type SchemaPlugin struct {
	SchemaContent any `json:"schema"`
}

type StreamRoute added in v1.0.0

type StreamRoute interface {
	Get(ctx context.Context, name string) (*v1.StreamRoute, error)
	List(ctx context.Context) ([]*v1.StreamRoute, error)
	Create(ctx context.Context, route *v1.StreamRoute, shouldCompare bool) (*v1.StreamRoute, error)
	Delete(ctx context.Context, route *v1.StreamRoute) error
	Update(ctx context.Context, route *v1.StreamRoute, shouldCompare bool) (*v1.StreamRoute, error)
}

StreamRoute is the specific client interface to take over the create, update, list and delete for APISIX Stream Route resource.

type Upstream

type Upstream interface {
	Get(ctx context.Context, name string) (*v1.Upstream, error)
	List(ctx context.Context) ([]*v1.Upstream, error)
	Create(ctx context.Context, ups *v1.Upstream, shouldCompare bool) (*v1.Upstream, error)
	Delete(ctx context.Context, ups *v1.Upstream) error
	Update(ctx context.Context, ups *v1.Upstream, shouldCompare bool) (*v1.Upstream, error)
}

Upstream is the specific client interface to take over the create, update, list and delete for APISIX Upstream resource.

type UpstreamServiceRelation added in v1.7.0

type UpstreamServiceRelation interface {
	// Get relation based on namespace+"_"+service.name
	Get(ctx context.Context, svcName string) (*v1.UpstreamServiceRelation, error)
	List(ctx context.Context) ([]*v1.UpstreamServiceRelation, error)
	// Delete relation based on namespace+"_"+service.name
	Delete(ctx context.Context, svcName string) error
	// Build relation based on upstream.name
	Create(ctx context.Context, svcName string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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