client

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package client contains generic client structs and methods that are designed to be used by specific PHPIPAM services and resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLevel added in v0.1.4

func SetLevel(level log.Level)

change logger level, default is info

Types

type Client

type Client struct {
	// The session for this client.
	Session *session.Session
}

Client encompasses a generic client object that is further extended by services. Any common configuration and functionality goes here.

func NewClient

func NewClient(s *session.Session) *Client

NewClient creates a new client.

func (*Client) GetCustomFields

func (c *Client) GetCustomFields(id int, controller string) (out map[string]interface{}, err error)

GetCustomFields GETs the custom fields for a resource, and returns them as a map[string]interface{}. A call out to GetCustomFields is performed first, and then a GET is performed on the subnet resource with only the custom fields returned.

Note that due to how PHPIPAM stringifies most output, this will, in most cases, mean that attribute values will be strings and will need to be convereted externally. This function does not explicitly lock to map[string]string to allow for possible cases where this is not the case, and to also allow for future de-stringification of the JSON.

This function is called out to in a controller to implement this functionality in a specific pacakge.

func (*Client) GetCustomFieldsSchema

func (c *Client) GetCustomFieldsSchema(controller string) (out map[string]phpipam.CustomField, err error)

GetCustomFieldsSchema GETs the custom fields for the supplied controller name and returns them as a map[string]phpipam.CustomField.

This function is called out to in a controller to implement this functionality in a specific pacakge.

func (*Client) SendRequest

func (c *Client) SendRequest(method, uri string, in, out interface{}) error

SendRequest sends a request to a request.Request object. It's expected that references to specific data types are passed - no checking is done to make sure that references are passed.

This function also wraps session management into the workflow, logging in and refreshing session tokens as needed.

func (*Client) UpdateCustomFields

func (c *Client) UpdateCustomFields(id int, in map[string]interface{}, controller string) (message string, err error)

UpdateCustomFields uses PATCH on a resource controller to update a specific resoruce ID with the custom fields provided in the key/value map defined by in.

Internal validation is preformed first to ensure that this field is not setting a custom field that is *not* defined in the schema. This is to prevent abuse - if this was not in place, this function could technically be used to update *any* field, as PHPIPAM does not maintain a separate subtype for custom fields.

This function is called out to in a controller to implement this functionality in a specific pacakge.

Jump to

Keyboard shortcuts

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