org

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: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HYBRID       = "HYBRID"
	CLOUD        = "CLOUD"
	SUBSCRIPTION = "SUBSCRIPTION"
	EVALUATION   = "EVALUATION"
)

Variables

View Source
var AcCmd = &cobra.Command{
	Use:   "enable-apigee-connect",
	Short: "Enable Apigee Connect for an Apigee Org",
	Long:  "Enable Apigee Connect for 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) {
		return orgs.SetOrgProperty("features.mart.apigee.connect.enabled", "true")
	},
}

AcCmd to set mart endpoint

View Source
var Cmd = &cobra.Command{
	Use:     "organizations",
	Aliases: []string{"orgs"},
	Short:   "Manage Apigee Orgs",
	Long:    "Manage Apigee Orgs",
}

Cmd to manage orgs

View Source
var CreateCmd = &cobra.Command{
	Use:   "create",
	Short: "Create a new Apigee Org",
	Long:  "Create a new Apigee Org",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if runtimeType != HYBRID && runtimeType != CLOUD {
			return fmt.Errorf("runtime type must be %s or %s", CLOUD, HYBRID)
		}

		if billingType != SUBSCRIPTION && billingType != EVALUATION {
			return fmt.Errorf("billing type must be %s or %s", SUBSCRIPTION, EVALUATION)
		}
		apiclient.SetProjectID(projectID)
		return apiclient.SetApigeeOrg(projectID)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = orgs.Create(description, analyticsRegion, authorizedNetwork,
			disableVpcPeering, runtimeType, billingType, runtimeDatabaseEncryptionKeyName,
			portalDisabled, apiConsumerDataEncryptionKeyName, controlPlaneEncryptionKeyName,
			apiConsumerDataLocation)
		return
	},
}

CreateCmd to get org details

View Source
var DelCmd = &cobra.Command{
	Use:   "delete",
	Short: "Delete an Apigee Org",
	Long:  "Delete 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 = orgs.Delete(retention)
		return
	},
}

DelCmd to get org details

View Source
var DeployCmd = &cobra.Command{
	Use:   "deployments",
	Short: "Manage deployments in an Apigee org",
	Long:  "Manage deployments in an Apigee org",
}

DeployCmd to get api deployments in an org

View Source
var ExportCmd = &cobra.Command{
	Use:   "export",
	Short: "Export Apigee Configuration",
	Long:  "Export Apigee Configuration",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var productResponse, appsResponse, targetServerResponse, referencesResponse, appGroupAppsResponse [][]byte
		var respBody, listKVMBytes, appGroupsRespBody []byte

		apiclient.DisableCmdPrintHttpResponse()

		runtimeType, _ := orgs.GetOrgField("runtimeType")

		if cleanPath {
			if err = cleanExportData(); err != nil {
				return err
			}
		}

		if err = createFolders(); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting API Proxies...")
		if err = apis.ExportProxies(conn, proxiesFolderName, allRevisions); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting Sharedflows...")
		if err = sharedflows.Export(conn, sharedFlowsFolderName, allRevisions); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting API Products...")
		if productResponse, err = products.Export(conn); proceedOnError(err) != nil {
			return err
		}
		if err = apiclient.WriteArrayByteArrayToFile(
			productsFileName,
			false, productResponse); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Printf("Exporting KV Map names for org %s\n", org)
		if listKVMBytes, err = kvm.List(""); proceedOnError(err) != nil {
			return err
		}
		if err = apiclient.WriteByteArrayToFile(
			org+"_"+kvmFileName,
			false, listKVMBytes); proceedOnError(err) != nil {
			return err
		}

		if exportEntries {
			if err = exportKVMEntries("org", "", listKVMBytes); proceedOnError(err) != nil {
				return err
			}
		}

		clilog.Info.Printf("Exporting Proxy scoped KV Map entries for org %s\n", org)
		if err = kvm.ExportAllEntries(); err != nil {
			return err
		}

		clilog.Info.Println("Exporting Developers...")
		if respBody, err = developers.Export(); proceedOnError(err) != nil {
			return err
		}
		if err = apiclient.WriteByteArrayToFile(
			developersFileName,
			false, respBody); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting AppGroups...")
		if appGroupsRespBody, err = appgroups.Export(); proceedOnError(err) != nil {
			return err
		}
		if err = apiclient.WriteByteArrayToFile(
			appGroupsFileName,
			false, appGroupsRespBody); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting Developer Apps...")
		if appsResponse, err = apps.Export(conn); proceedOnError(err) != nil {
			return err
		}
		if err = apiclient.WriteArrayByteArrayToFile(
			appsFileName,
			false, appsResponse); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting AppGroups Apps...")
		if appGroupAppsResponse, err = appgroups.ExportAllApps(appGroupsRespBody, conn); proceedOnError(err) != nil {
			return err
		}
		if err = apiclient.WriteArrayByteArrayToFile(
			appsFileName,
			false, appGroupAppsResponse); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting Environment Group Configuration...")
		if respBody, err = envgroups.List(); proceedOnError(err) != nil {
			return err
		}
		if err = apiclient.WriteByteArrayToFile(
			envGroupsFileName,
			false, respBody); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting Data collectors Configuration...")
		if respBody, err = datacollectors.List(); proceedOnError(err) != nil {
			return err
		}
		if err = apiclient.WriteByteArrayToFile(
			dataCollFileName,
			false, respBody); proceedOnError(err) != nil {
			return err
		}

		if orgs.GetAddOn("apiSecurityConfig") {
			clilog.Info.Println("Exporting API Security Configuration...")
			if err = securityprofiles.Export(conn, securityProfilesFolderName); proceedOnError(err) != nil {
				return err
			}
		}

		clilog.Info.Println("Exporting API Portal apidocs Configuration...")
		if err = apidocs.Export(portalsFolderName); proceedOnError(err) != nil {
			return err
		}

		clilog.Info.Println("Exporting API Portal apicategories Configuration...")
		if err = apicategories.Export(portalsFolderName); proceedOnError(err) != nil {
			return err
		}

		if runtimeType == "HYBRID" {
			clilog.Info.Println("Exporting Sync Authorization Identities...")
			if respBody, err = sync.Get(); err != nil {
				return err
			}
			if err = apiclient.WriteByteArrayToFile(
				syncAuthFileName,
				false, respBody); proceedOnError(err) != nil {
				return err
			}
		}

		var envRespBody []byte
		if envRespBody, err = env.List(); proceedOnError(err) != nil {
			return err
		}

		environments := []string{}
		if err = json.Unmarshal(envRespBody, &environments); proceedOnError(err) != nil {
			return err
		}

		for _, environment := range environments {
			clilog.Info.Println("Exporting configuration for environment " + environment)
			apiclient.SetApigeeEnv(environment)
			clilog.Info.Println("\tExporting Target servers...")
			if targetServerResponse, err = targetservers.Export(conn); proceedOnError(err) != nil {
				return err
			}
			if err = apiclient.WriteArrayByteArrayToFile(
				environment+"_"+targetServerFileName,
				false,
				targetServerResponse); proceedOnError(err) != nil {
				return err
			}

			clilog.Info.Printf("\tExporting KV Map names for environment %s...\n", environment)
			if listKVMBytes, err = kvm.List(""); err != nil {
				return err
			}
			if err = apiclient.WriteByteArrayToFile(
				environment+"_"+kvmFileName,
				false,
				listKVMBytes); proceedOnError(err) != nil {
				return err
			}

			if exportEntries {
				if err = exportKVMEntries("env", environment, listKVMBytes); proceedOnError(err) != nil {
					return err
				}
			}

			clilog.Info.Println("\tExporting Key store names...")
			if respBody, err = keystores.List(); proceedOnError(err) != nil {
				return err
			}
			if err = apiclient.WriteByteArrayToFile(
				environment+"_"+keyStoresFileName,
				false,
				respBody); proceedOnError(err) != nil {
				return err
			}

			clilog.Info.Println("\tExporting debugmask configuration...")
			if respBody, err = env.GetDebug(); err != nil {
				return err
			}
			if err = apiclient.WriteByteArrayToFile(
				environment+debugmaskFileName,
				false,
				respBody); proceedOnError(err) != nil {
				return err
			}

			clilog.Info.Println("\tExporting traceconfig...")
			if respBody, err = env.GetTraceConfig(); err != nil {
				return err
			}
			if err = apiclient.WriteByteArrayToFile(
				environment+tracecfgFileName,
				false,
				respBody); proceedOnError(err) != nil {
				return err
			}

			clilog.Info.Println("\tExporting references...")
			if referencesResponse, err = references.Export(conn); proceedOnError(err) != nil {
				return err
			}
			if err = apiclient.WriteArrayByteArrayToFile(
				environment+"_"+referencesFileName,
				false,
				referencesResponse); proceedOnError(err) != nil {
				return err
			}

		}

		return err
	},
}

ExportCmd to get org details

View Source
var GetCmd = &cobra.Command{
	Use:   "get",
	Short: "Show details of an Apigee Org",
	Long:  "Show details of 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 = orgs.Get()
		return
	},
}

GetCmd to get org details

View Source
var GetDeployCmd = &cobra.Command{
	Use:   "get",
	Short: "Get deployments for an Apigee org",
	Long:  "Get deployments for 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) {
		if all {
			_, err = orgs.GetAllDeployments()
		} else {
			_, err = orgs.GetDeployments(sf)
		}
		return err
	},
}

GetDeployCmd to get deployed apis in an env

View Source
var ImportCmd = &cobra.Command{
	Use:   "import",
	Short: "Import Apigee Configuration",
	Long:  "Import Apigee Configuration",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var kvmList []string

		if stat, err := os.Stat(folder); err == nil && !stat.IsDir() {
			return fmt.Errorf("supplied path is not a folder")
		}

		apiclient.DisableCmdPrintHttpResponse()

		clilog.Info.Println("Importing API Proxies...")
		if err = apis.ImportProxies(conn, path.Join(folder, proxiesFolderName)); err != nil {
			return err
		}

		clilog.Info.Println("Importing Sharedflows...")
		if err = sharedflows.Import(conn, path.Join(folder, sharedFlowsFolderName)); err != nil {
			return err
		}

		clilog.Info.Println("Check for files with KVM Entries")
		orgKVMFileList, envKVMFileList, _, _ := utils.ListKVMFiles(folder)

		if utils.FileExists(path.Join(folder, "org_"+org+"_"+kvmFileName)) {
			clilog.Info.Println("Importing Org scoped KVMs...")
			if kvmList, err = utils.ReadEntityFile(path.Join(folder, "org_"+org+"_"+kvmFileName)); err != nil {
				return err
			}
			for _, kvmName := range kvmList {

				if _, err = kvm.Create("", kvmName, true); err != nil {
					return err
				}
				if orgKVMFileList[kvmName] != "" {
					if err = kvm.ImportEntries("", kvmName, conn, orgKVMFileList[kvmName]); err != nil {
						return err
					}
				}
			}
		}

		if utils.FileExists(path.Join(folder, productsFileName)) {
			clilog.Info.Println("Importing Products...")
			if err = products.Import(conn, path.Join(folder, productsFileName), false); err != nil {
				return err
			}
		}

		if utils.FileExists(path.Join(folder, developersFileName)) {
			clilog.Info.Println("Importing Developers...")
			if err = developers.Import(conn, path.Join(folder, developersFileName)); err != nil {
				return err
			}

			clilog.Info.Println("Importing Apps...")
			if err = apps.Import(conn,
				path.Join(folder, appsFileName),
				path.Join(folder, developersFileName)); err != nil {
				return err
			}
		}

		if utils.FileExists(path.Join(folder, envGroupsFileName)) {
			clilog.Info.Println("Importing Environment Group Configuration...")
			if err = envgroups.Import(path.Join(folder, envGroupsFileName)); err != nil {
				return err
			}
		}

		if utils.FileExists(path.Join(folder, dataCollFileName)) {
			clilog.Info.Println("Importing Data Collectors Configuration...")
			if err = datacollectors.Import(path.Join(folder, dataCollFileName)); err != nil {
				return err
			}
		}

		if orgs.GetAddOn("apiSecurityConfig") {
			clilog.Info.Println("Importing Security Profile Configuration...")
			if err = securityprofiles.Import(conn, path.Join(folder, securityProfilesFolderName)); err != nil {
				return err
			}
		}

		var envRespBody []byte
		if envRespBody, err = env.List(); err != nil {
			return err
		}

		environments := []string{}

		if envRespBody != nil {
			if err = json.Unmarshal(envRespBody, &environments); err != nil {
				return err
			}
		}

		for _, environment := range environments {
			clilog.Info.Println("Importing configuration for environment " + environment)
			apiclient.SetApigeeEnv(environment)

			if utils.FileExists(path.Join(folder, environment+"_"+keyStoresFileName)) {
				clilog.Info.Println("\tImporting Keystore names...")
				if err = keystores.Import(conn, path.Join(folder, environment+"_"+keyStoresFileName)); err != nil {
					return err
				}
			}

			if utils.FileExists(path.Join(folder, environment+"_"+targetServerFileName)) {
				clilog.Info.Println("\tImporting Target servers...")
				if err = targetservers.Import(conn, path.Join(folder, environment+"_"+targetServerFileName)); err != nil {
					return err
				}
			}

			if utils.FileExists(path.Join(folder, environment+"_"+referencesFileName)) {
				clilog.Info.Println("\tImporting References...")
				if err = references.Import(conn, path.Join(folder, environment+"_"+referencesFileName)); err != nil {
					return err
				}
			}

			if utils.FileExists(path.Join(folder, "env_"+environment+"_"+kvmFileName)) {
				clilog.Info.Println("\tImporting KVM Names only...")
				if kvmList, err = utils.ReadEntityFile(path.Join(folder, "env_"+environment+"_"+kvmFileName)); err != nil {
					return err
				}
				for _, kvmName := range kvmList {

					if _, err = kvm.Create("", kvmName, true); err != nil {
						return err
					}
					if envKVMFileList[kvmName] != "" {
						if err = kvm.ImportEntries("", kvmName, conn, envKVMFileList[kvmName]); err != nil {
							return err
						}
					}
				}
			}

			if importDebugmask {
				if utils.FileExists(path.Join(folder, environment+debugmaskFileName)) {
					clilog.Info.Println("\tImporting Debug Mask configuration...")
					debugMask, _ := readEntityFileAsString(path.Join(folder, environment+debugmaskFileName))
					if _, err = env.SetDebug(debugMask); err != nil {
						return err
					}
				}
			}

			if importTrace {
				if utils.FileExists(path.Join(folder, environment+tracecfgFileName)) {
					clilog.Info.Println("\tImporting Trace configuration...")
					traceCfg, _ := readEntityFileAsString(path.Join(folder, environment+tracecfgFileName))
					if _, err = env.ImportTraceConfig(traceCfg); err != nil {
						return err
					}
				}
			}
		}

		return err
	},
}

ImportCmd to get org details

View Source
var IngressCmd = &cobra.Command{
	Use:   "ingressconfig",
	Short: "Show details of the Ingress configuration for an Apigee Org",
	Long:  "Show details of the Ingress configuration for 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 = orgs.GetDeployedIngressConfig(view)
		return
	},
}

IngressCmd to get org details

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List the Apigee organizations",
	Long:  "List the Apigee organizations, and the related projects that a user has permissions for",
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = orgs.List()
		return
	},
}

ListCmd to list orgs

View Source
var MartCmd = &cobra.Command{
	Use:   "setmart",
	Short: "Set MART endpoint for an Apigee Org",
	Long:  "Set MART endpoint for 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) {
		return orgs.SetOrgProperty("features.mart.server.endpoint", mart)
	},
}

MartCmd to set mart endpoint

View Source
var MonthlyCmd = &cobra.Command{
	Use:   "monthly",
	Short: "Report monthly usage for an Apigee Org",
	Long:  "Report monthly usage for 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) {
		var apiCalls int
		w := tabwriter.NewWriter(os.Stdout, 32, 4, 0, ' ', 0)

		clilog.Warning.Println("This API is rate limited to 1 API Call per second")

		if _, err = time.Parse("1/2006", fmt.Sprintf("%d/%d", month, year)); err != nil {
			return err
		}

		if envDetails {
			fmt.Fprintln(w, "ENVIRONMENT\tMONTH\tAPI CALLS")
			w.Flush()
		}

		if apiCalls, err = orgs.TotalAPICallsInMonth(month, year, envDetails, conn); err != nil {
			return err
		}

		if envDetails {
			fmt.Printf("\nSummary\n\n")
		}

		fmt.Fprintln(w, "ORGANIATION\tMONTH\tAPI CALLS")
		fmt.Fprintf(w, "%s\t%d/%d\t%d\n", apiclient.GetApigeeOrg(), month, year, apiCalls)
		fmt.Fprintln(w)
		w.Flush()

		return err
	},
}

MonthlyCmd to get monthly usage

View Source
var ObCmd = &cobra.Command{
	Use:   "enable-ax-obfuscation",
	Short: "Obfuscate analytics fields",
	Long:  "Obfuscate analytics fields before sending to control plane",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		return orgs.SetOrgProperty("features.analytics.data.obfuscation.enabled", "true")
	},
}

ObCmd to enable AX obfuscation

View Source
var PropCmd = &cobra.Command{
	Use:   "set",
	Short: "Set organization property",
	Long:  "Set organization property",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		return orgs.SetOrgProperty(propName, propValue)
	},
}

PropCmd to set mart endpoint

View Source
var ReportCmd = &cobra.Command{
	Use:     "reports",
	Aliases: []string{"orgs"},
	Short:   "Report Apigee Org Usage",
	Long:    "Report Apigee Org Usage",
}

ReportCmd to manage org reprots

View Source
var SetAddonCmd = &cobra.Command{
	Use:   "setaddons",
	Short: "Enable addons for an Apigee organization",
	Long:  "Enable addons for an Apigee organization",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = orgs.SetAddons(advancedAPIOpsConfig, integrationConfig,
			monetizationConfig, connectorsConfig, apiSecurityConfig)
		return
	},
}

SetAddonCmd to set mart endpoint

View Source
var UpdateCmd = &cobra.Command{
	Use:   "update",
	Short: "Update settings of an Apigee Org",
	Long:  "Update settings of an Apigee Org",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if runtimeType != "HYBRID" && runtimeType != "CLOUD" {
			return fmt.Errorf("runtime type must be CLOUD or HYBRID")
		}
		apiclient.SetProjectID(projectID)
		return apiclient.SetApigeeOrg(projectID)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = orgs.Update(description, authorizedNetwork)
		return
	},
}

UpdateCmd to get org details

View Source
var YearlyCmd = &cobra.Command{
	Use:   "yearly",
	Short: "Report yearly usage for an Apigee Org",
	Long:  "Report yearly usage for 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) {
		var apiCalls int
		w := tabwriter.NewWriter(os.Stdout, 32, 4, 0, ' ', 0)

		clilog.Warning.Println("This API is rate limited to 1 API Call per second")

		if _, err = time.Parse("2006", fmt.Sprintf("%d", year)); err != nil {
			return err
		}

		if envDetails {
			fmt.Fprintln(w, "ENVIRONMENT\tMONTH\tAPI CALLS")
			w.Flush()
		}

		if apiCalls, err = orgs.TotalAPICallsInYear(year, envDetails, conn); err != nil {
			return err
		}

		if envDetails {
			fmt.Printf("\nSummary\n\n")
		}

		fmt.Fprintln(w, "ORGANIZATION\tYEAR\tAPI CALLS")
		fmt.Fprintf(w, "%s\t%d\t%d\n", apiclient.GetApigeeOrg(), year, apiCalls)
		fmt.Fprintln(w)
		w.Flush()

		return err
	},
}

YearlyCmd to get monthly usage

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