edgegrid

package module
v0.0.0-...-e5bcfb3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2016 License: Apache-2.0 Imports: 15 Imported by: 0

README

EdgeGrid for GoLang

Build Status Coverage 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.

GET Example:

  package main

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

  func main() {
    client := http.Client{}

    config := edgegrid.InitConfig("~/.edgerc", "default")

    // Retrieve all locations for diagnostic tools
    req, _ := http.NewRequest("GET", fmt.Sprintf("https://%s/diagnostic-tools/v1/locations", config.Host), nil)
    req = edgegrid.AddRequestHeader(config, req)
    resp, _ := client.Do(req)

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

Parameter Example:

  package main

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

  func main() {
    client := http.Client{}

    config := edgegrid.InitConfig("~/.edgerc", "default")

    // Retrieve dig information for specified location
    req, _ := http.NewRequest("GET", fmt.Sprintf("https://%sdiagnostic-tools/v1/dig", config.Host), 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()
    req = edgegrid.AddRequestHeader(config, req)
    resp, _ := client.Do(req)

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

POST Example:

  package main

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

  func main() {
    client := http.Client{}

    config := edgegrid.InitConfig("~/.edgerc", "default")
    
    // Acknowledge a map
    req, _ := http.NewRequest("POST", fmt.Sprintf("https://%s/siteshield/v1/maps/1/acknowledge", config.Host), nil)
    req = edgegrid.AddRequestHeader(config, req)
    resp, _ := client.Do(req)

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

PUT Example:

  package main

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

  func main() {
    client := http.Client{}

    config := edgegrid.InitConfig("~/.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, _ := http.NewRequest("PUT", fmt.Sprintf("https://%s/network-list/v1/network_lists/unique-id?extended=extended", config.Host), bytes.NewBuffer(body))
    req = edgegrid.AddRequestHeader(config, req)
    resp, _ := client.Do(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"
    "github.com/akamai-open/AkamaiOPEN-edgegrid-golang"
    "io/ioutil"
    "net/http"
  )

  func main() {
    client := http.Client{}
    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, _ := http.NewRequest("GET", fmt.Sprintf("https://%s/diagnostic-tools/v1/locations", config.Host), nil)
    req = edgegrid.AddRequestHeader(config, req)
    resp, _ := client.Do(req)

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

Installation

  $ go get github.com/akamai-open/AkamaiOPEN-edgegrid-golang

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

Documentation

Overview

Package edgegrid provides the Akamai {OPEN} Edgegrid Authentication scheme

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRequestHeader

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

AddRequestHeader sets the authorization header to use Akamai Open API

Types

type Config

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

func InitConfig

func InitConfig(filepath string, section string) Config

InitConfig initializes configuration file

Directories

Path Synopsis
Godeps
_workspace/src/github.com/go-ini/ini
Package ini provides INI file read and write functionality in Go.
Package ini provides INI file read and write functionality in Go.
_workspace/src/github.com/sirupsen/logrus
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
_workspace/src/github.com/stretchr/testify/assert
A set of comprehensive testing tools for use with the normal Go testing system.
A set of comprehensive testing tools for use with the normal Go testing system.

Jump to

Keyboard shortcuts

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