apis

package
v1.113.5-beta Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BundleCreateCmd = &cobra.Command{
	Use:   "bundle",
	Short: "Creates an API proxy from an Zip or folder",
	Long:  "Creates an API proxy from an Zip or folder",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if proxyZip != "" && proxyFolder != "" {
			return fmt.Errorf("proxy bundle (zip) and folder to an API proxy cannot be combined")
		}
		if proxyZip == "" && proxyFolder == "" {
			return fmt.Errorf("either proxy bundle (zip) or folder must be specified, not both")
		}
		if proxyZipFolder != "" {
			if _, err := os.Stat(proxyZipFolder); os.IsNotExist(err) {
				return err
			}
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var curDir string

		if proxyZip != "" {
			_, err = apis.CreateProxy(name, proxyZip)
		} else if proxyFolder != "" {
			if proxyZipFolder == "" {
				curDir, _ = os.Getwd()
			} else {
				curDir = proxyZipFolder
			}

			proxyBundlePath := path.Join(curDir, name+".zip")

			if err = proxybundle.GenerateArchiveBundle(proxyFolder, proxyBundlePath); err != nil {
				return err
			}
			if _, err = apis.CreateProxy(name, proxyBundlePath); err != nil {
				return err
			}

			err = os.Remove(proxyBundlePath)
		}
		return err
	},
}
View Source
var CleanCmd = &cobra.Command{
	Use:   "clean",
	Short: "Deletes undeployed/unused reivisions of an API proxy",
	Long:  "Deletes undeployed/unused reivisions of an API proxy",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		return apis.CleanProxy(name, reportOnly, keepList)
	},
}

CleanCmd to delete api

View Source
var Cmd = &cobra.Command{
	Use:   "apis",
	Short: "Manage Apigee API proxies in an org",
	Long:  "Manage Apigee API proxies in an org",
}

Cmd to manage apis

View Source
var CreateCmd = &cobra.Command{
	Use:   "create",
	Short: "Creates an API proxy in an Apigee Org",
	Long:  "Creates an API proxy in an Apigee Org",
}

CreateCmd to create api

View Source
var CreateKvmCmd = &cobra.Command{
	Use:   "create",
	Short: "Create an API Proxy scoped KVM",
	Long:  "Create an API Proxy scoped KVM",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.CreateProxyKVM(proxyName, name, encrypted)
		return
	},
}

CreateKvmCmd to manage tracing of apis

View Source
var CreateTrcCmd = &cobra.Command{
	Use:   "create",
	Short: "Create a new debug session for an API proxy",
	Long:  "Create a new debug session for Apigee API proxy revision deployed in an environment",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		apiclient.SetApigeeEnv(env)
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.CreateTraceSession(name, revision, filter)
		return
	},
}

CreateTrcCmd to manage tracing of apis

View Source
var DelCmd = &cobra.Command{
	Use:   "delete",
	Short: "Deletes an API proxy",
	Long: "Deletes an API proxy and all associated endpoints, policies, resources, and revisions." +
		"The proxy must be undeployed first.",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		if revision == -1 {
			_, err = apis.DeleteProxy(name)
		} else {
			_, err = apis.DeleteProxyRevision(name, revision)
		}
		return
	},
}

DelCmd to delete api

View Source
var DelKvmCmd = &cobra.Command{
	Use:   "delete",
	Short: "Deletes an API Proxy scoped KVM",
	Long:  "Deletes an API Proxy scoped KVM",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.DeleteProxyKVM(proxyName, name)
		return
	},
}

DelKvmCmd to manage tracing of apis

View Source
var DepCmd = &cobra.Command{
	Use:   "deploy",
	Short: "Deploys a revision of an existing API proxy",
	Long:  "Deploys a revision of an existing API proxy to an environment in an organization, optionally waits for deployment",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		apiclient.SetApigeeEnv(env)
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		if revision == -1 {
			if revision, err = apis.GetHighestProxyRevision(name); err != nil {
				return
			}
		}
		_, err = apis.DeployProxy(name, revision, overrides, serviceAccountName)

		if wait {
			fmt.Printf("Checking deployment status in %d seconds\n", interval)

			apiclient.SetPrintOutput(false)

			stop := apiclient.Every(interval*time.Second, func(time.Time) bool {
				var respBody []byte
				respMap := make(map[string]interface{})
				if respBody, err = apis.ListProxyRevisionDeployments(name, revision); err != nil {
					return true
				}

				if err = json.Unmarshal(respBody, &respMap); err != nil {
					return true
				}

				if respMap["state"] == "PROGRESSING" {
					fmt.Printf("Proxy deployment status is: %s. Waiting %d seconds.\n", respMap["state"], interval)
					return true
				} else if respMap["state"] == "READY" {
					fmt.Println("Proxy deployment completed with status: ", respMap["state"])
					return false
				} else {
					fmt.Println("Proxy deployment failed with status: ", respMap["state"])
					return false
				}
			})

			<-stop
		}

		return
	},
}

DepCmd to deploy api

View Source
var ExpCmd = &cobra.Command{
	Use:   "export",
	Short: "export API proxy bundles from an org",
	Long:  "export API proxy bundles from an org",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		if err = apiclient.FolderExists(folder); err != nil {
			return err
		}
		return apis.ExportProxies(conn, folder, allRevisions)
	},
}

ExpCmd to export apis

View Source
var FetCmd = &cobra.Command{
	Use:   "fetch",
	Short: "Returns a zip-formatted proxy bundle ",
	Long:  "Returns a zip-formatted proxy bundle of code and config files",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		if revision == -1 {
			if revision, err = apis.GetHighestProxyRevision(name); err != nil {
				return
			}
		}
		return apis.FetchProxy(name, revision)
	},
}

FetCmd to download api

View Source
var GetCmd = &cobra.Command{
	Use:   "get",
	Short: "Gets an API Proxy by name",
	Long:  "Gets an API Proxy by name, including a list of its revisions.",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.GetProxy(name, revision)
		return
	},
}

GetCmd to get api details

View Source
var GetTrcCmd = &cobra.Command{
	Use:   "get",
	Short: "Get a debug session for an API proxy revision",
	Long:  "Get a debug session for an API proxy revision deployed in an environment",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		apiclient.SetApigeeEnv(env)
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.GetTraceSession(name, revision, sessionID, messageID)
		return
	},
}

GetTrcCmd to manage tracing of apis

View Source
var GhCreateCmd = &cobra.Command{
	Use:     "github",
	Aliases: []string{"gh"},
	Short:   "Creates an API proxy from a GitHub repo",
	Long:    "Creates an API proxy from a GitHub repo",
	Args: func(cmd *cobra.Command, args []string) (err error) {

		re := regexp.MustCompile(`(\w+)?\/apiproxy$`)
		if ok := re.Match([]byte(ghPath)); !ok {
			return fmt.Errorf("github path must end with /apiproxy")
		}

		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		if os.Getenv("GITHUB_TOKEN") == "" {
			clilog.Info.Println("github token is not set as an env var. Running unauthenticated")
		}
		if err = proxybundle.GitHubImportBundle(ghOwner, ghRepo, ghPath); err != nil {
			proxybundle.CleanUp()
			return err
		}
		_, err = apis.CreateProxy(name, bundleName)
		proxybundle.CleanUp()
		return err
	},
}
View Source
var GqlCreateCmd = &cobra.Command{
	Use:     "graphql",
	Aliases: []string{"gql"},
	Short:   "Creates an API proxy from a GraphQL schema",
	Long:    "Creates an API proxy from a GraphQL schema",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if gqlFile == "" && gqlURI == "" {
			return fmt.Errorf("either gqlfile or gqlurl must be passed")
		}
		if targetUrl != "" && targetUrlRef != "" {
			return fmt.Errorf("either target-url or target-url-ref must be passed, not both")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var content []byte
		var gqlDocName string
		if gqlFile != "" {
			gqlDocName, content, err = readSchemaFile()
		} else {
			gqlDocName, content, err = readSchemaURL()
		}
		if err != nil {
			return err
		}

		location, keyName, err := getKeyNameAndLocation()
		if err != nil {
			return err
		}

		err = bundle.GenerateAPIProxyDefFromGQL(name,
			gqlDocName,
			basePath,
			apiKeyLocation,
			skipPolicy,
			addCORS,
			targetUrlRef,
			targetUrl)

		if err != nil {
			return err
		}

		err = proxybundle.GenerateAPIProxyBundleFromGQL(name,
			string(content),
			gqlDocName,
			action,
			location,
			keyName,
			skipPolicy,
			addCORS,
			targetUrlRef,
			targetUrl)

		if err != nil {
			return err
		}

		if importProxy {
			_, err = apis.CreateProxy(name, name+".zip")
		}

		return err
	},
}
View Source
var ImpCmd = &cobra.Command{
	Use:   "import",
	Short: "Import a folder containing API proxy bundles",
	Long:  "Import a folder containing API proxy bundles",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		return apis.ImportProxies(conn, folder)
	},
}

ImpCmd to import api bundles

View Source
var KvmCmd = &cobra.Command{
	Use:   "kvm",
	Short: "Manage API proxy scoped KVMs",
	Long:  "Manage API proxy scoped KVMs",
}

KvmCmd to manage tracing of apis

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List APIs in an Apigee Org",
	Long:  "List APIs in an Apigee Org",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.ListProxies(includeRevisions)
		return
	},
}

ListCmd to list api

View Source
var ListDepCmd = &cobra.Command{
	Use:   "listdeploy",
	Short: "Lists all deployments of an API proxy",
	Long:  "Lists all deployments of an API proxy",
	Args: func(cmd *cobra.Command, args []string) error {

		apiclient.SetApigeeEnv(env)
		if apiclient.GetApigeeEnv() == "" && name == "" {
			return fmt.Errorf("proxy name or environment must be supplied")
		}
		if revision != -1 && name == "" {
			return fmt.Errorf("proxy name must be supplied with revision")
		}
		if name != "" && revision == -1 && apiclient.GetApigeeEnv() != "" {
			return fmt.Errorf("revision must be supplied with proxy name and env")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		if apiclient.GetApigeeEnv() != "" {
			if revision != -1 {
				if !report {
					_, err = apis.ListProxyRevisionDeployments(name, revision)
				} else {
					_, err = apis.GenerateDeployChangeReport(name, revision, false)
				}
			} else {
				_, err = apis.ListEnvDeployments()
			}
		} else {
			_, err = apis.ListProxyDeployments(name)
		}
		return
	},
}

ListDepCmd to list deployed api

View Source
var ListKvmCmd = &cobra.Command{
	Use:   "list",
	Short: "List all KVMs for an API proxy",
	Long:  "List all KVMs for an API proxy",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.ListProxyKVM(proxyName)
		return
	},
}

ListKvmCmd to manage tracing of apis

View Source
var ListTrcCmd = &cobra.Command{
	Use:   "list",
	Short: "List all debug sessions for an API proxy revision",
	Long:  "List all debug sessions for an API proxy revision deployed in an environment",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		apiclient.SetApigeeEnv(env)
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.ListTracceSession(name, revision)
		return
	},
}

ListTrcCmd to manage tracing of apis

View Source
var OasCreateCmd = &cobra.Command{
	Use:     "openapi",
	Aliases: []string{"oas"},
	Short:   "Creates an API proxy from an OpenAPI Specification",
	Long:    "Creates an API proxy from an OpenAPI Specification",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if oasFile == "" && oasURI == "" {
			return fmt.Errorf("either oasfile or oasuri must be passed")
		}
		if targetUrl != "" && targetUrlRef != "" {
			return fmt.Errorf("either target-url or target-url-ref must be passed, not both")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var content []byte
		var oasDocName string
		if oasFile != "" {
			oasDocName, content, err = bundle.LoadDocumentFromFile(oasFile, validateSpec, formatValidation)
		} else {
			oasDocName, content, err = bundle.LoadDocumentFromURI(oasURI, validateSpec, formatValidation)
		}
		if err != nil {
			return err
		}

		err = bundle.GenerateAPIProxyDefFromOAS(name,
			oasDocName,
			skipPolicy,
			addCORS,
			oasGoogleAcessTokenScopeLiteral,
			oasGoogleIdTokenAudLiteral,
			oasGoogleIdTokenAudRef,
			targetUrlRef,
			targetUrl)

		if err != nil {
			return err
		}

		err = proxybundle.GenerateAPIProxyBundleFromOAS(name,
			string(content),
			oasDocName,
			skipPolicy,
			addCORS,
			oasGoogleAcessTokenScopeLiteral,
			oasGoogleIdTokenAudLiteral,
			oasGoogleIdTokenAudRef,
			targetUrlRef,
			targetUrl)

		if err != nil {
			return err
		}

		if importProxy {
			_, err = apis.CreateProxy(name, name+".zip")
		}

		return err
	},
}
View Source
var TraceCmd = &cobra.Command{
	Use:   "debugsessions",
	Short: "Manage debusessions of Apigee API proxies",
	Long:  "Manage debusessions of Apigee API proxy revisions deployed in an environment",
}

TraceCmd to manage tracing of apis

View Source
var UndepCmd = &cobra.Command{
	Use:   "undeploy",
	Short: "Undeploys a revision of an existing API proxy",
	Long:  "Undeploys a revision of an existing API proxy to an environment in an organization",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		apiclient.SetApigeeEnv(env)
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		if revision == -1 {
			if revision, err = apis.GetHighestProxyRevision(name); err != nil {
				return
			}
		}
		_, err = apis.UndeployProxy(name, revision)
		return
	},
}

UndepCmd to undeloy api

View Source
var UpdateCmd = &cobra.Command{
	Use:   "update",
	Short: "Update APIs in an Apigee Org",
	Long:  "Update APIs in an Apigee Org",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = apis.Update(name, labels)
		return
	},
}

UpdateCmd to list api

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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