edgegrid

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

README

Akamai OPEN EdgeGrid for GoLang

Build Status GoDoc Go Report Card License

This library implements an Authentication handler for net/http that provides the Akamai OPEN Edgegrid Authentication scheme. For more information visit the Akamai OPEN Developer Community.

Installation

This package uses Glide to manage to dependencies and installation. To install Glide, see the Glide install documentation

  $ glide get github.com/akamai/AkamaiOPEN-edgegrid-golang

Usage

GET Example:

  package main

  import (
    "fmt"
    "io/ioutil"
    "net/http"
    
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
  )

  func main() {
    config, _ := edgegrid.Init("~/.edgerc", "default")

    // Retrieve all locations for diagnostic tools
    req, _ := client.NewRequest(config, "GET", "/diagnostic-tools/v1/locations", nil)
    resp, _ := client.Do(config, req)

    defer resp.Body.Close()
    byt, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(byt))
  }

Parameter Example:

  package main

  import (
    "fmt"
    "io/ioutil"
    "net/http"
    
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
  )

  func main() {
    config, _ := edgegrid.Init("~/.edgerc", "default")

    // Retrieve dig information for specified location
    req, _ := client.NewRequest(config, "GET", "/diagnostic-tools/v1/dig", nil)

    q := req.URL.Query()
    q.Add("hostname", "developer.akamai.com")
    q.Add("queryType", "A")
    q.Add("location", "Auckland, New Zealand")

    req.URL.RawQuery = q.Encode()
    resp, _ := client.Do(config, req)

    defer resp.Body.Close()
    byt, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(byt))
  }

POST Example:

  package main

  import (
    "fmt"
    "io/ioutil"
    "net/http"
    
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
  )

  func main() {
    config, _ := edgegrid.Init("~/.edgerc", "default")
    
    // Acknowledge a map
    req, _ := client.NewRequest(config, "POST", "/siteshield/v1/maps/1/acknowledge", nil)
    resp, _ := client.Do(config, req)

    defer resp.Body.Close()
    byt, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(byt))
  }

PUT Example:

  package main

  import (
    "fmt"
    "io/ioutil"
    "net/http"
    
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
  )

  func main() {

    config, _ := edgegrid.Init("~/.edgerc", "default")
    body := []byte("{\n  \"name\": \"Simple List\",\n  \"type\": \"IP\",\n  \"unique-id\": \"345_BOTLIST\",\n  \"list\": [\n    \"192.168.0.1\",\n    \"192.168.0.2\",\n  ],\n  \"sync-point\": 0\n}")
    
    // Update a Network List
    req, _ := client.NewJSONRequest(config, "PUT", "/network-list/v1/network_lists/unique-id?extended=extended", body)
    resp, _ := client.Do(config, req)

    defer resp.Body.Close()
    byt, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(byt))
  }

Alternatively, your program can read it from config struct.

  package main

  import (
    "fmt"
    "io/ioutil"
    "net/http"
    
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
    "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
  )

  func main() {
    config := edgegrid.Config{
      Host : "xxxxxx.luna.akamaiapis.net",
      ClientToken:  "xxxx-xxxxxxxxxxx-xxxxxxxxxxx",
      ClientSecret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      AccessToken:  "xxxx-xxxxxxxxxxx-xxxxxxxxxxx",
      MaxBody:      1024,
      HeaderToSign: []string{
        "X-Test1",
        "X-Test2",
        "X-Test3",
      },
      Debug:        false,
    }
    
    // Retrieve all locations for diagnostic tools
    req, _ := client.NewRequest(config, "GET", fmt.Sprintf("https://%s/diagnostic-tools/v1/locations", config.Host), nil)
    resp, _ := client.Do(config, req)

    defer resp.Body.Close()
    byt, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(byt))
  }

Contribute

  1. Fork the repository to start making your changes to the master branch
  2. Send a pull request.

Author

Nick Juettner - Software Engineer @ Zalando SE
Davey Shafik - Developer Evangelist @ Akamai Technologies

Documentation

Overview

Package edgegrid provides the Akamai OPEN Edgegrid Authentication scheme

Deprecated: use client-v1/client instead

Package edgegrid provides the Akamai OPEN Edgegrid Authentication scheme

Deprecated: use edgegrid/config and edgegrid/signer instead

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRequestHeader deprecated

func AddRequestHeader(c Config, req *http.Request) *http.Request

AddRequestHeader sets the authorization header to use Akamai Open API

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid

Types

type Client deprecated

type Client struct {
	http.Client

	// Base URL for API requests.
	BaseURL *url.URL

	// User agent for client
	UserAgent string

	Config Config
}

Client is a simple http.Client wrapper that transparently signs requests

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func New deprecated

func New(httpClient *http.Client, config Config) (*Client, error)

New creates a new Client with a given Config

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func NewClient deprecated

func NewClient(httpClient *http.Client) *Client

NewClient creates a new Client

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Client) Do deprecated

func (c *Client) Do(req *http.Request) (*Response, error)

Do executes the HTTP request

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Client) Get deprecated

func (c *Client) Get(url string) (*Response, error)

Get performs an HTTP GET request

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Client) Head deprecated

func (c *Client) Head(url string) (*Response, error)

Head performs an HTTP HEAD request

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Client) NewJSONRequest deprecated

func (c *Client) NewJSONRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewJSONRequest creates an API request with JSON body. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. If specified, the value pointed to by body is JSON encoded and included in as the request body.

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Client) NewRequest deprecated

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. If specified, the value pointed to by body is JSON encoded and included in as the request body.

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Client) Post deprecated

func (c *Client) Post(url string, bodyType string, body interface{}) (*Response, error)

Post performs an HTTP POST request

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Client) PostForm deprecated

func (c *Client) PostForm(url string, data url.Values) (*Response, error)

PostForm performs an HTTP POST request with a form body

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Client) PostJSON deprecated

func (c *Client) PostJSON(url string, data interface{}) (*Response, error)

PostJSON performs an HTTP POST request with a JSON body

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

type Config deprecated

type Config struct {
	Host         string   `ini:"host"`
	ClientToken  string   `ini:"client_token"`
	ClientSecret string   `ini:"client_secret"`
	AccessToken  string   `ini:"access_token"`
	HeaderToSign []string `ini:"headers_to_sign"`
	MaxBody      int      `ini:"max_body"`
	Debug        bool     `ini:"debug"`
}

Config struct provides all the necessary fields to create authorization header, debug is optional

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid

func Init deprecated

func Init(filepath string, section string) (Config, error)

Init initializes Config using first ENV variables, with fallback to .edgerc file

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid

func InitConfig deprecated

func InitConfig(filepath string, section string) Config

InitConfig initializes Config using .edgerc files

Deprecated: Backwards compatible wrapper around InitEdgeRc which should be used instead

func InitEdgeRc deprecated

func InitEdgeRc(filepath string, section string) (Config, error)

InitEdgeRc initializes Config using an .edgerc (INI) configuration file

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid

func InitEnv deprecated

func InitEnv(section string) (Config, error)

InitEnv initializes Config using ENV variables

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid

func (Config) AddRequestHeader deprecated

func (c Config) AddRequestHeader(req *http.Request) *http.Request

AddRequestHeader set the authorization header to use Akamai OPEN API

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid

type JSONBody deprecated

type JSONBody map[string]interface{}

JSONBody represents a generic JSON response

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

type Response deprecated

type Response http.Response

Response is a Wrapper for http.Response

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

func (*Response) BodyJSON deprecated

func (r *Response) BodyJSON(data interface{}) error

BodyJSON retrieves and unmarshals a responses JSON body

Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client

Directories

Path Synopsis
Package client is a simple library for http.Client to sign Akamai OPEN Edgegrid API requests
Package client is a simple library for http.Client to sign Akamai OPEN Edgegrid API requests
Package edgegrid allows you to sign http.Request's using the Akamai OPEN Edgegrid Signing Scheme
Package edgegrid allows you to sign http.Request's using the Akamai OPEN Edgegrid Signing Scheme
An example Diagnostic Tools v1 API Client
An example Diagnostic Tools v1 API Client
Package jsonhooks adds hooks that are automatically called before JSON marshaling (PreMarshalJSON) and after JSON unmarshaling (PostUnmarshalJSON).
Package jsonhooks adds hooks that are automatically called before JSON marshaling (PreMarshalJSON) and after JSON unmarshaling (PostUnmarshalJSON).
Package papi provides a simple wrapper for the Akamai Property Manager API
Package papi provides a simple wrapper for the Akamai Property Manager API

Jump to

Keyboard shortcuts

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