persistence

package
v0.0.0-...-f7e4e28 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HomeDir is the home directory of the api7 cloud.
	HomeDir = filepath.Join(os.Getenv("HOME"), ".api7cloud")
	// TLSDir is the directory to store TLS certificates.
	TLSDir string
	// APISIXConfigDir is the directory to store APISIX configuration file.
	APISIXConfigDir string
)

Functions

func CheckConfigurationAndInitCloudClient

func CheckConfigurationAndInitCloudClient() error

CheckConfigurationAndInitCloudClient checks if cloud-cli configured the server address and token correctly. Then use this token to initialize the cloud client.

func DownloadNewCertificate

func DownloadNewCertificate(clusterID sdk.ID) error

DownloadNewCertificate downloads the new TLS bundle for communicating with API7 Cloud. Note this function doesn't restore the old TLS bundle if the new one is not saved normally on disk. Try to recall this function multiple times to eliminate the corrupted TLS bundle files.

func Init

func Init() error

Init initializes the persistence context.

func PrepareCertificate

func PrepareCertificate(clusterID sdk.ID) error

PrepareCertificate downloads the client certificate and key from API7 Cloud. This certificate is used for the communication between APISIX and API7 Cloud.

func SaveCloudLuaModule

func SaveCloudLuaModule() (string, error)

SaveCloudLuaModule downloads the cloud lua module and unzip and untar it, finally it'll be saved to the filesystem and the directory will be returned.

func SaveConfiguration

func SaveConfiguration(config *CloudConfiguration) error

SaveConfiguration to file for persistence

Types

type CloudConfiguration

type CloudConfiguration struct {
	// DefaultProfile is the active profile.
	DefaultProfile string `json:"default_profile" yaml:"default_profile"`
	// Profiles is the list of profiles.
	Profiles []Profile `json:"profiles" yaml:"profiles"`
}

CloudConfiguration is the configuration for the cloud cli.

func LoadConfiguration

func LoadConfiguration() (*CloudConfiguration, error)

LoadConfiguration from file

func (*CloudConfiguration) ConfigureProfile

func (c *CloudConfiguration) ConfigureProfile(profile Profile)

ConfigureProfile adds a profile to the configuration if not exists, otherwise update profile by name.

func (*CloudConfiguration) GetDefaultProfile

func (c *CloudConfiguration) GetDefaultProfile() (*Profile, error)

GetDefaultProfile returns the default profile.

func (*CloudConfiguration) GetProfile

func (c *CloudConfiguration) GetProfile(name string) (*Profile, error)

GetProfile returns the profile by name.

func (*CloudConfiguration) Validate

func (c *CloudConfiguration) Validate() error

Validate validates the configuration.

type Profile

type Profile struct {
	// Name is the name of the profile.
	Name string `json:"name" yaml:"name"`
	// Address is the address of API7 Cloud server.
	Address string `json:"address" yaml:"address"`
	// User is the user credential.
	User User `json:"user" yaml:"user"`
}

Profile represents a configuration profile.

type User

type User struct {
	AccessToken string `json:"-" yaml:"access_token"`
}

User is credential for authentication.

Jump to

Keyboard shortcuts

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