Categorygithub.com/cloudentity/go-apigee-edge
modulepackage
0.0.0-20200728211718-1f3e2c736c74
Repository: https://github.com/cloudentity/go-apigee-edge.git
Documentation: pkg.go.dev

# README

golang client library for Apigee administrative API

Use this from Go-lang programs to invoke administrative operations on Apigee.

The goal is to allow golang programs to easiy do these things:

entity typeactions
apislist, query, inquire revisions, inquire deployment status, import, export, delete, delete revision, deploy, undeploy
sharedflowslist, query, inquire revisions, inquire deployment status, import, export, delete, delete revision, deploy, undeploy
apiproductslist, query, create, delete, change quota, modify public/private, modify description, modify approvalType, modify scopes, add or remove proxy, modify custom attrs
developerslist, query, create, delete, make active or inactive, modify custom attrs
developerappslist, query, create, delete, revoke, approve, add new credential, remove credential, modify custom attrs
credentiallist, revoke, approve, add apiproduct, remove apiproduct
kvmlist, query, create, delete, get all entries, get entry, add entry, modify entry, remove entry
cachelist, query, create, delete, clear
environmentlist, query

The Apigee administrative API is just a REST-ful API, so of course any go program could invoke it directly. This library will provide a wrapper, which will make it easier.

Not yet in scope:

  • OAuth2.0 tokens - Listing, Querying, Approving, Revoking, Deleting, or Updating
  • TargetServers: list, create, edit, etc
  • keystores and truststores: adding certs, listing certs
  • data masks
  • virtualhosts
  • API specifications
  • analytics or custom reports
  • DebugSessions (trace). Can be handy for automating the verification of tests.
  • OPDK-specific things. Like starting or stopping services, manipulating pods, adding servers into environments, etc.

These items may be added later as need and demand warrants.

This is not an official Google product

This library and any example tools included here are not an official Google product, nor are they part of an official Google product. Support is available on a best-effort basis via github or community.apigee.com .

Copyright and License

This code is Copyright (c) 2016 Apigee Corp, 2017-2019 Google LLC. it is licensed under the Apache 2.0 Source Licese.

Status

This project is a work-in-progress. Here's the status:

entity typeimplementednot implemented yet
apislist, query, inquire revisions, import, export, delete, delete revision, deploy, undeploy, inquire deployment status
sharedflowslist, query, inquire revisions, import, export, delete, delete revision, deploy, undeploy, inquire deployment status
apiproductslist, query, create, delete modify description, modify approvalType, modify scopes, add or remove proxy, add or remove custom attrs, modify public/private, change quota
developerslist, query, create, update, delete, modify custom attrs, make active or inactive, modify custom attrs
developerappslist, query, create, delete, revoke, approve, modify custom attrsadd new credential, remove credential
credentiallist, revoke, approve, add apiproduct, remove apiproduct
kvmlist, query, create, delete, get all entries, get entry, add entry, modify entry, remove entry
cachelist, querycreate, delete, clear
environmentlist, query

Pull requests are welcomed.

Usage Examples

Importing a Proxy

package main

import (
  "fmt"
  "flag"
  "time"
  "github.com/DinoChiesa/go-apigee-edge"
)

func usage() {
  fmt.Printf("import-proxy -user [email protected] -org cap500 -name foobar -src /path/to/apiproxy\n\n")
}


func main() {
  proxyName := ""
  namePtr := flag.String("name", "", "name for the API Proxy")
  srcPtr := flag.String("src", "", "a directory containing an exploded apiproxy bundle, or a zipped bundle")
  orgPtr := flag.String("org", "", "an Apigee Organization")
  flag.Parse()

  if *namePtr != "" {
    proxyName = *namePtr
  }

  if *srcPtr == "" || *orgPtr == "" {
    usage()
    return
  }

  var auth *apigee.AdminAuth = nil

  // Specifying nil for Auth implies "read from .netrc"
  // Specify a password explicitly like so:
  // auth := apigee.AdminAuth{Username: "[email protected]", Password: "Secret*123"}

  opts := &apigee.ApigeeClientOptions{Org: *orgPtr, Auth: auth, Debug: false }
  client, e := apigee.NewApigeeClient(opts)
  if e != nil {
    fmt.Printf("while initializing Edge client, error:\n%#v\n", e)
    return
  }

  fmt.Printf("\nImporting...\n")
  proxyRev, resp, e := client.Proxies.Import(proxyName, *srcPtr)
  if e != nil {
    fmt.Printf("while importing, error:\n%#v\n", e)
    return
  }
  fmt.Printf("status: %s\n", resp.Status)
  defer resp.Body.Close()
  fmt.Printf("proxyRev: %#v\n", proxyRev)
}

Deleting a specific API Proxy Revision

func main() {
  opts := &apigee.ApigeeClientOptions{Org: *orgPtr, Auth: nil, Debug: false }
  client, e := apigee.NewApigeeClient(opts)
  if e != nil {
    fmt.Printf("while initializing Apigee client, error:\n%#v\n", e)
    return
  }
  fmt.Printf("Deleting...\n")
  deletedRev, resp, e := client.Proxies.DeleteRevision(proxyName, Revision{2})
  if e != nil {
    fmt.Printf("while deleting, error:\n%#v\n", e)
    return
  }
  fmt.Printf("status: %s\n", resp.Status)
  defer resp.Body.Close()
  fmt.Printf("proxyRev: %#v\n", deletedRev)
}

Deleting all revisions of an API Proxy

func main() {
  opts := &apigee.ApigeeClientOptions{Org: *orgPtr, Auth: nil, Debug: false }
  client, e := apigee.NewApigeeClient(opts)
  if e != nil {
    fmt.Printf("while initializing Apigee client, error:\n%#v\n", e)
    return
  }
  fmt.Printf("Deleting...\n")
  // works only if no revisions are deployed
  deletedItem, resp, e := client.Proxies.Delete(proxyName)
  if e != nil {
    fmt.Printf("while deleting, error:\n%#v\n", e)
    return
  }
  fmt.Printf("status: %s\n", resp.Status)
  defer resp.Body.Close()
  fmt.Printf("deleted: %#v\n", deletedItem)
}

Listing API Products

func main() {
  orgPtr := flag.String("org", "", "an Edge Organization")
  flag.Parse()
  if *orgPtr == "" {
    usage()
    return
  }

  opts := &apigee.ApigeeClientOptions{Org: *orgPtr, Auth: nil, Debug: false }
  client, e := apigee.NewApigeeClient(opts)
  if e != nil {
    fmt.Printf("while initializing Edge client, error:\n%#v\n", e)
    return
  }

  fmt.Printf("\nListing...\n")
  list, resp, e := client.Products.List()
  if e != nil {
    fmt.Printf("while listing, error:\n%#v\n", e)
    return
  }
  showStatus(resp)
  fmt.Printf("products: %#v\n", list)
  resp.Body.Close()

  for _, element := range list {
    product, resp, e := client.Products.Get(element)
    if e != nil {
      fmt.Printf("while getting, error:\n%#v\n", e)
      return
    }
    showStatus(resp)
    fmt.Printf("product: %#v\n", product)
    resp.Body.Close()
  }

  fmt.Printf("\nall done.\n")
}

Bugs

  • The function is incomplete.

  • There tests are incomplete.

  • The examples are thin.

  • There is no package versioning strategy (eg, no use of GoPkg.in)

  • When deploying a proxy, there's no way currently to specify the override and delay parameters for "hot deployment".

# Functions

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
CheckResponse checks the API response for errors, and returns them if present.
Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.
NewApigeeClient returns a new ApigeeClient.
No description provided by the author
StreamToString converts a reader to a string.
String is a helper routine that allocates a new string value to store v and returns a pointer to it.

# Constants

No description provided by the author

# Structs

AdminAuth holds information about how to authenticate to the Edge Management server.
ApigeeClient manages communication with Apigee V1 Admin API.
No description provided by the author
When inquiring the deployment status of an API PRoxy revision, even implicitly as when performing a Deploy or Undeploy, the response includes the deployment status for each particular Edge Server in the environment.
ApiProduct contains information about an API Product within an Edge organization.
Cache contains information about a cache within an Edge organization.
CacheExpiry represents the expiry settings on a cache.
No description provided by the author
When Delete returns successfully, it returns a payload that contains very little useful information.
No description provided by the author
DeployableAsset contains information about an API Proxy or SharedFlow within an Apigee organization.
ProxyMetadata contains information related to the creation and last modified time and actor for an API Proxy within an organization.
DeployableRevision holds information about a revision of an API Proxy, or a SharedFlow.
Deployment (nee ProxyDeployment) holds information about the deployment state of a all revisions of an API Proxy or SharedFlow.
Developer contains information about a registered Developer within an Edge organization.
DeveloperApp holds information about a registered DeveloperApp.
No description provided by the author
No description provided by the author
Environment contains information about an environment within an Edge organization.
No description provided by the author
No description provided by the author
An ErrorResponse reports the error caused by an API request.
ListOptions holds optional parameters to various List methods.
No description provided by the author
No description provided by the author
No description provided by the author
This is just a wrapper struct to aid in serialization and de-serialization.
No description provided by the author
wrap the standard http.Response returned from Apigee Edge.
No description provided by the author
Timespan represents a timespan that can be parsed from a string like "3d" meaning "3 days".
Timestamp represents a time that can be unmarshalled from a JSON string formatted as "java time" = milliseconds-since-unix-epoch.

# Interfaces

CachesService is an interface for interfacing with the Apigee Edge Admin API dealing with caches.
DeveloperAppsService is an interface for interfacing with the Apigee Edge Admin API dealing with apps that belong to a particular developer.
DevelopersService is an interface for interfacing with the Apigee Edge Admin API dealing with developers.
EnvironmentsService is an interface for interfacing with the Apigee Edge Admin API querying Edge environments.
OrganizationsService is an interface for interfacing with the Apigee Edge Admin API querying Edge environments.
ProductsService is an interface for interfacing with the Apigee Edge Admin API dealing with apiproducts.
ProxiesService is an interface for interfacing with the Apigee Admin API dealing with apiproxies.

# Type aliases

Attributes represents a revision number.
RequestCompletionCallback defines the type of the request callback function.
Revision represents a revision number.