clients

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 29 Imported by: 3

README

go-cf-clients-helper

Convenient way to have all cloud foundry go client api from https://github.com/cloudfoundry/cli .

The Cloud foundry cli provide go client to call cloud foundry api like v2/v3 api, uaa api, network policy api, logs and metrics api, tcp router api ... But, how to to build and call them can be very difficult and is not documented.

This repo leverage this situation and is an extract of the code we do for cloud foundry terraform provider.

Usage

package main

import (
	"github.com/cloudfoundry-community/go-cf-clients-helper" // package name is clients
	"fmt"
)

func main() {
	config := clients.Config{
		Endpoint: "https://api.my.cloudfoundry.com",
		User: "admin",
		Password: "password",
	}
	session, err := clients.NewSession(config)
	if err != nil {
		panic(err)
	}
	
	// get access to cf api v2 (incomplete api)
	session.V2()
	
	// get access to cf api v3 (complete and always up to date api) 
	session.V3()
	
	// Get access to api uaa (incomplete)
	session.UAA()
	
	// Get access to TCP Routing api
	session.TCPRouter()
	
	// Get access to networking policy api
	session.Networking()
	
	// Get access to logs api and metrics through noaa
	session.NOAA()
	// you can use helper for retrieving log messages for an app
	h := clients.NewNOAAHelper(session.NOAA(), session.ConfigStore())
	msgs, err := h.RecentLogs("app-guid", 0) // 0 means no limit of messages to see
	if err != nil {
            panic(err)
        }
	fmt.Println(msgs)
	
	// Get an http client which pass authorization header to call api(s) directly 
	session.Raw()
    
	// Get config store for client which need, for example, current access token (e.g.: NOAA) 
	session.ConfigStore()
}

Documentation

Index

Constants

View Source
const LogTimestampFormat = "2006-01-02T15:04:05.00-0700"
View Source
const RedactedValue = "[PRIVATE DATA HIDDEN]"

RedactedValue is the text that is displayed for redacted content. (eg authorization tokens, passwords, etc.)

Variables

This section is empty.

Functions

func RedactHeaders

func RedactHeaders(header http.Header) http.Header

func SanitizeJSON

func SanitizeJSON(raw []byte) ([]byte, error)

Types

type Config

type Config struct {
	// Cloud foundry api endoint
	Endpoint string
	// cloud foundry user to call api (CFClientID can be set instead)
	User string
	// cloud foundry password to call api (CFClientID can be set instead)
	Password string
	// cloud foundry client id to call api or to identify user (User can be set in addition)
	// If empty and user set this value will be set as `cf`
	CFClientID string
	// cloud foundry client secret to call api or to identify user (user can be set in addition)
	CFClientSecret string
	// uaa client id to call uaa api
	UaaClientID string
	// uaa client secret to call uaa api
	UaaClientSecret string
	// Skip ssl verification
	SkipSslValidation bool
	// Show debug trace
	Debug bool
}

config -

type NOAAHelper

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

func NewNOAAHelper

func NewNOAAHelper(consumer *noaaconsumer.Consumer, configStore *configv3.Config) *NOAAHelper

func (NOAAHelper) RecentLogs

func (c NOAAHelper) RecentLogs(appGUID string, maxMessages int) (string, error)

type RawClient

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

Raw http client has uaa client authentication to make raw request with golang native api.

func NewRawClient

func NewRawClient(config RawClientConfig, wrappers ...ccv3.ConnectionWrapper) *RawClient

NewRawClient -

func (RawClient) Do

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

Do - Do the request with given http client and wrappers

func (RawClient) NewRequest

func (c RawClient) NewRequest(method, path string, body io.ReadCloser) (*http.Request, error)

NewRequest - Create a new request with setting api endpoint to the path

type RawClientConfig

type RawClientConfig struct {
	DialTimeout       time.Duration
	SkipSSLValidation bool
	ApiEndpoint       string
}

RawClientConfig - configuration for RawClient

type RequestLogger

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

func NewRequestLogger

func NewRequestLogger() *RequestLogger

func (*RequestLogger) DisplayBody

func (display *RequestLogger) DisplayBody([]byte) error

func (*RequestLogger) DisplayDump

func (display *RequestLogger) DisplayDump(dump string) error

func (*RequestLogger) DisplayHeader

func (display *RequestLogger) DisplayHeader(name string, value string) error

func (*RequestLogger) DisplayHost

func (display *RequestLogger) DisplayHost(name string) error

func (*RequestLogger) DisplayJSONBody

func (display *RequestLogger) DisplayJSONBody(body []byte) error

func (*RequestLogger) DisplayMessage

func (display *RequestLogger) DisplayMessage(msg string) error

func (*RequestLogger) DisplayRequestHeader

func (display *RequestLogger) DisplayRequestHeader(method string, uri string, httpProtocol string) error

func (*RequestLogger) DisplayResponseHeader

func (display *RequestLogger) DisplayResponseHeader(httpProtocol string, status string) error

func (*RequestLogger) DisplayType

func (display *RequestLogger) DisplayType(name string, requestDate time.Time) error

func (*RequestLogger) HandleInternalError

func (display *RequestLogger) HandleInternalError(err error)

func (*RequestLogger) Start

func (display *RequestLogger) Start() error

func (*RequestLogger) Stop

func (display *RequestLogger) Stop() error

type RetryRequest

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

RetryRequest is a wrapper that retries failed requests if they contain a 5XX status code. copy of wrapper retry request in cli but remove the necessary of have a readseeker body (annoying for sending in fullstream)

func NewRetryRequest

func NewRetryRequest(maxRetries int) *RetryRequest

NewRetryRequest returns a pointer to a RetryRequest wrapper.

func (*RetryRequest) Make

func (retry *RetryRequest) Make(request *cloudcontroller.Request, passedResponse *cloudcontroller.Response) error

Make retries the request if it comes back with a 5XX status code.

func (*RetryRequest) Wrap

func (retry *RetryRequest) Wrap(innerconnection cloudcontroller.Connection) cloudcontroller.Connection

Wrap sets the connection in the RetryRequest and returns itself.

type Session

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

Session - wraps the available clients from CF cli

func NewSession

func NewSession(c Config) (s *Session, err error)

NewSession -

func (*Session) ConfigStore

func (s *Session) ConfigStore() *configv3.Config

Give config store for client which need access token (e.g.: NOAA)

func (*Session) IsDebugMode

func (s *Session) IsDebugMode() bool

func (*Session) NOAA

func (s *Session) NOAA() *noaaconsumer.Consumer

Give access to logs api and metrics through noaa

func (*Session) Networking

func (s *Session) Networking() *cfnetv1.Client

Give access to networking policy api

func (*Session) Raw

func (s *Session) Raw() *RawClient

Give an http client which pass authorization header to call api(s) directly

func (*Session) TCPRouter

func (s *Session) TCPRouter() *router.Client

Give access to TCP Routing api

func (*Session) UAA

func (s *Session) UAA() *uaa.Client

Give access to api uaa (incomplete)

func (*Session) V2

func (s *Session) V2() *ccv2.Client

Give access to api cf v2 (incomplete)

func (*Session) V3

func (s *Session) V3() *ccv3.Client

Give access to api cf v3 (complete and always up to date, thanks to cli v7 team)

Jump to

Keyboard shortcuts

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