apis

package
v1.125.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 20 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; Optionally deploy the API to an env",
	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 proxyFolder != "" {
			if _, err := os.Stat(proxyFolder); os.IsNotExist(err) {
				return err
			}
		}
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var respBody []byte
		if proxyZip != "" {
			respBody, err = apis.CreateProxy(name, proxyZip)
		} else if proxyFolder != "" {
			if stat, err := os.Stat(folder); err == nil && !stat.IsDir() {
				return fmt.Errorf("supplied path is not a folder")
			}
			if filepath.Base(proxyFolder) != "apiproxy" {
				return fmt.Errorf("--proxy-folder or -p must be a path to apiproxy folder")
			}
			tmpDir, err := os.MkdirTemp("", "proxy")
			if err != nil {
				return err
			}
			defer os.RemoveAll(tmpDir)

			proxyBundlePath := path.Join(tmpDir, name+zipExt)

			if err = proxybundle.GenerateArchiveBundle(proxyFolder, proxyBundlePath, false); err != nil {
				return err
			}
			if respBody, err = apis.CreateProxy(name, proxyBundlePath); err != nil {
				return err
			}
			if err = os.Remove(proxyBundlePath); err != nil {
				return err
			}
		}
		if env != "" {
			clilog.Info.Printf("Deploying the API Proxy %s to environment %s\n", name, env)
			if revision, err = GetRevision(respBody); err != nil {
				return err
			}
			if _, err = apis.DeployProxy(name, revision, overrides,
				sequencedRollout, safeDeploy, serviceAccountName); err != nil {
				return err
			}
			if wait {
				return Wait(name, revision)
			}
		}
		return err
	},
}
View Source
var CleanCmd = &cobra.Command{
	Use:   "clean",
	Short: "Deletes undeployed/unused revisions of an API proxy",
	Long:  "Deletes undeployed/unused revisions 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 CloneCmd = &cobra.Command{
	Use:   "clone",
	Short: "Clone an API proxy from an Zip or folder",
	Long:  "Clone 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 proxyFolder != "" {
			if _, err := os.Stat(proxyFolder); os.IsNotExist(err) {
				return err
			}
		}
		if !strings.HasPrefix(basePath, "/") {
			return fmt.Errorf("basePath must start with /")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		if proxyZip != "" {

			if proxyFolder, err = unzipBundle(); err != nil {
				return err
			}
		}

		if proxyFolder != "" {
			var tmpDir string

			if proxyZip != "" {
				tmpDir = proxyFolder
			} else {
				if tmpDir, err = copyDirectory(); err != nil {
					return err
				}
				defer os.RemoveAll(tmpDir)
			}

			if err = renameProxy(tmpDir); err != nil {
				return err
			}

			proxyBundlePath := path.Join(tmpDir, name+zipExt)

			if err = proxybundle.GenerateArchiveBundle(path.Join(tmpDir, "apiproxy"), proxyBundlePath, false); err != nil {
				return err
			}
			if _, err = apis.CreateProxy(name, proxyBundlePath); err != nil {
				return err
			}

			return err
		}

		return err
	},
}
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 err
	},
}

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
			}
		}
		if _, err = apis.DeployProxy(name,
			revision,
			overrides,
			sequencedRollout,
			safeDeploy,
			serviceAccountName); err != nil {
			return err
		}

		if wait {
			err = Wait(name, revision)
		}
		return err
	},
}

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 err
			}
		}
		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. Check apigeecli prefs for GH on-prem options",
	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.Debug.Println("github token is not set as an env var. Running unauthenticated")
		}
		if err = proxybundle.GitHubImportBundle(ghOwner, ghRepo, ghPath, false); err != nil {
			proxybundle.ProxyCleanUp()
			return err
		}
		_, err = apis.CreateProxy(name, bundleName)
		proxybundle.ProxyCleanUp()
		return err
	},
}

GhCreateCmd create an api from a github repo

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+zipExt)
		}

		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) {
		if stat, err := os.Stat(folder); err == nil && !stat.IsDir() {
			return fmt.Errorf("supplied path is not a folder")
		}
		return apis.ImportProxies(conn, folder)
	},
}

ImpCmd to import api bundles

View Source
var IntegrationCmd = &cobra.Command{
	Use:   "integration",
	Short: "Creates an API proxy template for Application Integration",
	Long:  "Creates an API proxy template for Application Integration with an API Trigger",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		tmpDir, err := os.MkdirTemp("", "proxy")
		if err != nil {
			return err
		}

		defer os.RemoveAll(tmpDir)

		if err = bundlegen.GenerateIntegrationAPIProxy(name, apitrigger); err != nil {
			return err
		}

		if err = proxybundle.GenerateIntegrationAPIProxyBundle(name, integration, apitrigger, true); err != nil {
			return err
		}

		if importProxy {
			_, err = apis.CreateProxy(name, tmpDir)
		}
		return err
	},
}
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 err
	},
}

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")
		}
		if integration != "" && apitrigger == "" {
			return fmt.Errorf("apitrigger must be passed if integration is set")
		}
		if integration == "" && apitrigger != "" {
			return fmt.Errorf("integration must be passed if apitrigger is set")
		}
		if (targetURL != "" || targetURLRef != "") && (integration != "" || apitrigger != "") {
			return fmt.Errorf("integration or apitrigger cannot be set if targetURL or targetURLRef is set")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var content []byte
		var oasDocName string

		integrationEndpoint := false

		if oasFile != "" {
			oasDocName, content, err = bundle.LoadDocumentFromFile(oasFile, validateSpec, formatValidation)
		} else {
			oasDocName, content, err = bundle.LoadDocumentFromURI(oasURI, validateSpec, formatValidation)
		}
		if err != nil {
			return err
		}

		targetOptions := bundle.TargetOptions{
			IntegrationBackend: bundle.IntegrationBackendOptions{
				IntegrationName: integration,
				TriggerName:     apitrigger,
			},
			HttpBackend: bundle.HttpBackendOptions{
				OasGoogleAcessTokenScopeLiteral: oasGoogleAcessTokenScopeLiteral,
				OasGoogleIDTokenAudLiteral:      oasGoogleIDTokenAudLiteral,
				OasGoogleIDTokenAudRef:          oasGoogleIDTokenAudRef,
				OasTargetURLRef:                 targetURLRef,
				TargetURL:                       targetURL,
			},
		}

		if integration != "" {
			integrationEndpoint = true
		}

		err = bundle.GenerateAPIProxyDefFromOAS(name,
			oasDocName,
			skipPolicy,
			addCORS,
			integrationEndpoint,
			oasGoogleAcessTokenScopeLiteral,
			oasGoogleIDTokenAudLiteral,
			oasGoogleIDTokenAudRef,
			targetURLRef,
			targetURL)

		if err != nil {
			return err
		}

		err = proxybundle.GenerateAPIProxyBundleFromOAS(name,
			string(content),
			oasDocName,
			skipPolicy,
			addCORS,
			targetOptions)

		if err != nil {
			return err
		}

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

		return err
	},
}
View Source
var SwaggerCreateCmd = &cobra.Command{
	Use:   "swagger",
	Short: "Creates an API proxy from a Swagger Spec",
	Long:  "Creates an API proxy from a Swagger Spec for Cloud Endpoints/API Gateway",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if swaggerFile == "" && swaggerURI == "" {
			return fmt.Errorf("either swaggerfile or swaggeruri must be passed")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		// var content []byte
		var oasDocName string

		if swaggerURI != "" {
			if oasDocName, _, err = bundle.LoadSwaggerFromUri(swaggerURI); err != nil {
				return err
			}
		}

		if swaggerFile != "" {
			if oasDocName, _, err = bundle.LoadSwaggerFromFile(swaggerFile); err != nil {
				return err
			}
		}

		name, err = bundle.GenerateAPIProxyFromSwagger(name,
			oasDocName,
			basePath,
			addCORS)

		if err != nil {
			return err
		}

		err = proxybundle.GenerateAPIProxyBundleFromSwagger(name,
			skipPolicy,
			addCORS)

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

		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
			}
		}
		_, err = apis.UndeployProxy(name, revision, safeUndeploy)
		return err
	},
}

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

func GetRevision

func GetRevision(respBody []byte) (revision int, err error)

func Wait

func Wait(name string, revision int) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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