{"modulePath":"github.com/api7/cloud-cli","version":"v0.0.0-20240523012138-b9cffea42484","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package persistence\n\n## Variables\n\n```go\nvar (\n\t// HomeDir is the home directory of the api7 cloud.\n\tHomeDir = filepath.Join(os.Getenv(\"HOME\"), \".api7cloud\")\n\t// TLSDir is the directory to store TLS certificates.\n\tTLSDir string\n\t// APISIXConfigDir is the directory to store APISIX configuration file.\n\tAPISIXConfigDir string\n)\n```\n\n## Functions\n\n```go\nfunc CheckConfigurationAndInitCloudClient() error\n```\nCheckConfigurationAndInitCloudClient checks if cloud-cli configured the server address and token correctly. Then use this token to initialize the cloud client.\n\n```go\nfunc DownloadNewCertificate(clusterID sdk.ID) error\n```\nDownloadNewCertificate 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.\n\n```go\nfunc Init() error\n```\nInit initializes the persistence context.\n\n```go\nfunc PrepareCertificate(clusterID sdk.ID) error\n```\nPrepareCertificate downloads the client certificate and key from API7 Cloud. This certificate is used for the communication between APISIX and API7 Cloud.\n\n```go\nfunc SaveCloudLuaModule() (string, error)\n```\nSaveCloudLuaModule downloads the cloud lua module and unzip and untar it, finally it'll be saved to the filesystem and the directory will be returned.\n\n```go\nfunc SaveConfiguration(config *CloudConfiguration) error\n```\nSaveConfiguration to file for persistence\n\n## Types\n\n```go\ntype CloudConfiguration struct {\n\t// DefaultProfile is the active profile.\n\tDefaultProfile string `json:\"default_profile\" yaml:\"default_profile\"`\n\t// Profiles is the list of profiles.\n\tProfiles []Profile `json:\"profiles\" yaml:\"profiles\"`\n}\n```\nCloudConfiguration is the configuration for the cloud cli.\n\n```go\nfunc LoadConfiguration() (*CloudConfiguration, error)\n```\nLoadConfiguration from file\n\n```go\nfunc (c *CloudConfiguration) ConfigureProfile(profile Profile)\n```\nConfigureProfile adds a profile to the configuration if not exists, otherwise update profile by name.\n\n```go\nfunc (c *CloudConfiguration) GetDefaultProfile() (*Profile, error)\n```\nGetDefaultProfile returns the default profile.\n\n```go\nfunc (c *CloudConfiguration) GetProfile(name string) (*Profile, error)\n```\nGetProfile returns the profile by name.\n\n```go\nfunc (c *CloudConfiguration) Validate() error\n```\nValidate validates the configuration.\n\n```go\ntype Profile struct {\n\t// Name is the name of the profile.\n\tName string `json:\"name\" yaml:\"name\"`\n\t// Address is the address of API7 Cloud server.\n\tAddress string `json:\"address\" yaml:\"address\"`\n\t// User is the user credential.\n\tUser User `json:\"user\" yaml:\"user\"`\n}\n```\nProfile represents a configuration profile.\n\n```go\ntype User struct {\n\tAccessToken string `json:\"-\" yaml:\"access_token\"`\n}\n```\nUser is credential for authentication.\n\n","path":"github.com/api7/cloud-cli/internal/persistence","name":"persistence","synopsis":"","isRedistributable":true}
