jerakia

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

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

README

go-jerakia

A Go client library for Jerakia.

Quickstart

package main

import (
  "fmt"
  "net/http"

  "github.com/jerakia/go-jerakia"
)

func main() {
  config := jerakia.ClientConfig{
    URL:   "http://localhost:9992/v1",
    Token: "mytok:abcd",
  }

  client := jerakia.NewClient(http.DefaultClient, config)

  lookupOpts := jerakia.LookupOpts{
    Namespace: "test",
    Metadata: map[string]string{
      "hostname": "example",
    },
  }

  result, err := jerakia.Lookup(&client, "users", &lookupOpts)
  if err != nil {
    panic(err)
  }

  fmt.Printf("%#v\n", result)
}

Development

Installation
$ go get github.com/jerakia/go-jerakia
Unit Tests
$ cd $GOPATH/github.com/jerakia/go-jerakia
$ make test
Acceptance Tests

Make sure you have the following environment variables set:

  • JERAKIA_URL
  • JERAKIA_TOKEN
$ cd $GOPATH/github.com/jerakia/go-jerakia
$ make testacc

You can use the supplied acceptance/deploy.sh script to install all requirements (including Jerakia and Go) on an Ubuntu 16.04 system.

The script will create a ~/jrc file with all required environment variables set.

Vendor Dependencies

go-jerakia uses Go modules for dependency/vendor management.

Documentation

Index

Constants

View Source
const DefaultUserAgent = "go-jerakia/1.0.0"

DefaultUserAgent is the default User-Agent string set in the request handler.

View Source
const LookupURL = "lookup"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a Jerakia REST client.

func NewClient

func NewClient(httpClient *http.Client, c ClientConfig) Client

NewClient will create and return a Client.

func (*Client) Get

func (client *Client) Get(url string, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error)

Get calls `Request` with the "GET" HTTP verb.

func (*Client) Request

func (client *Client) Request(method, url string, opts *RequestOpts) (*http.Response, error)

Request performs an HTTP request.

type ClientConfig

type ClientConfig struct {
	// URL is the URL to the Jerakia server.
	URL string

	// Token is the authentication token.
	Token string

	// UserAgent is a custom User-Agent.
	UserAgent UserAgent
}

ClientConfig represents options used for creating a Jerakia client.

type LookupOpts

type LookupOpts struct {
	// Namespace is the namespace to use for the request.
	// Nested namespaces should be delimited with /.
	Namespace string

	// Policy optionally override the policy used for the request.
	Policy string

	// LookupType optionally overrides the type of lookup (first, cascade).
	LookupType string

	// Merge optionally override the merge strategy to use (array,
	// deep_hash, hash).
	Merge string

	// Scope optionally provides an alternative scope handler to use
	// for the request (eg: puppetdb).
	Scope string

	// ScopeOptions are sent as parameters for the Scope.
	ScopeOptions map[string]string

	// Metadata specifies metadata for the request.
	Metadata map[string]string
}

LookupOpts represents options for a lookup.

func (LookupOpts) ToLookupQuery

func (opts LookupOpts) ToLookupQuery() (string, error)

ToLookupQuery converts LookupOpts to a query string.

type LookupResult

type LookupResult struct {
	// Status is the result of the request.
	Status string `json:"status"`

	// Found is if a value was found or not.
	Found bool `json:"found"`

	// Payload is the data returned from the lookup.
	Payload interface{} `json:"payload"`

	// Message provides details of the error if status is "failed".
	Message string `json:"message"`
}

LookupResult represents a lookup result.

func Lookup

func Lookup(client *Client, key string, opts *LookupOpts) (*LookupResult, error)

Lookup performs a lookup.

type RequestOpts

type RequestOpts struct {
	// JSONResponse, if provided, will be populated with the contents of the
	// response body parsed as JSON.
	JSONResponse interface{}
}

RequestOpts represents options used on a per-request basis.

type UserAgent

type UserAgent struct {
	// contains filtered or unexported fields
}

UserAgent represents a User-Agent header.

func (*UserAgent) Join

func (ua *UserAgent) Join() string

Join concatenates all the user-defined User-Agend strings with the default User-Agent string.

func (*UserAgent) Prepend

func (ua *UserAgent) Prepend(s ...string)

Prepend prepends a user-defined string to the default User-Agent string. Users may pass in one or more strings to prepend.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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