ilink

package module
v0.0.0-...-70fea51 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 16 Imported by: 1

README

A go client for the Interlink Configuration Management Database HTTP API.

Usage

An example of how to use is below:

// import the library
package main 

import "southwinds.dev/interlink-client"

func main() {
    // prepares the client configuration
    cfg := &ilink.ClientConf{
         BaseURI:            "http://localhost:8080",
         InsecureSkipVerify: true,
         AuthMode:           ilink.Basic,
         Username:           "admin",
         Password:           "0n1x",
         // uncomment below & reset configuration vars
         // to test using an OAuth bearer token
         // AuthMode:           	OIDC,
         // TokenURI:     		"https://dev-447786.okta.com/oauth2/default/v1/token",
         // ClientId:			"0oalyh...356",
         // AppSecret:			"Tsed........OP0oEf9H7",
    }
    // create an instance of the web api client
    client, err := ilink.NewClient(cfg)

    if err != nil {
       panic(err)
    }

    // create a new model
    model := &ilink.Model {
        Key:         "test_model",
        Name:        "Test Model",
        Description: "Test Model",
    }

    // put the model
    result, err := client.PutModel(model)
    
    if err != nil {
       panic(err)
    }

    if result.Error {
        panic(result.Message)
    }
}

// create an instance of the client
func createClient() *ilink.Client {
    client, err := ilink.NewClient(&ilink.ClientConf{
        BaseURI:            "http://localhost:8080",
        InsecureSkipVerify: true,
        AuthMode:           ilink.Basic,
        Username:           "admin",
        Password:           "0n1x",
        // uncomment below & reset configuration vars
        // to test using an OAuth bearer token
        // AuthMode:           	OIDC,
        // TokenURI:     		"https://dev-447786.okta.com/oauth2/default/v1/token",
        // ClientId:			"0oalyh...356",
        // AppSecret:			"Tsed........OP0oEf9H7",
	})
	if err != nil { panic(err) }
	return client
}

More examples can be found here.

Documentation

Index

Constants

View Source
const (
	DELETE = "DELETE"
	PUT    = "PUT"
	GET    = "GET"
	POST   = "POST"
)

Variables

This section is empty.

Functions

func ToJson

func ToJson(object interface{}) ([]byte, error)

convert the passed-in object to a JSON byte slice NOTE: json.Marshal is purposely not used as it will escape any < > characters

Types

type AccessControl

type AccessControl struct {
	Realm  string
	URI    string
	Method string
}

type AuthenticationMode

type AuthenticationMode int

the authentication mode type

const (
	// no authentication used
	None AuthenticationMode = iota
	// use basic access authentication
	Basic
	// use OpenId Connect token
	OIDC
)

the different authentication modes available to the client

type ChangeNotifyType

type ChangeNotifyType string
const (
	NotifyTypeNone ChangeNotifyType = "N"
	NotifyTypeType ChangeNotifyType = "T"
	NotifyTypeItem ChangeNotifyType = "I"
)

func FromString

func FromString(changeNotifyType string) ChangeNotifyType

func (*ChangeNotifyType) ToString

func (n *ChangeNotifyType) ToString() string

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Onix HTTP client

func NewClient

func NewClient(conf *ClientConf) (*Client, error)

creates a new Onix Web API client

func (*Client) Clear

func (c *Client) Clear() (*Result, error)

clear all data in the database

func (*Client) Delete

func (c *Client) Delete(url string, processor HttpRequestProcessor) (*http.Response, error)

Make a DELETE HTTP request to the specified URL

func (*Client) DeleteItem

func (c *Client) DeleteItem(item *Item) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeleteItemType

func (c *Client) DeleteItemType(itemType *ItemType) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeleteItemTypeAttr

func (c *Client) DeleteItemTypeAttr(typeAttr *ItemTypeAttribute) (*Result, error)

issue a Delete http request to the resource URI

func (c *Client) DeleteLink(link *Link) (*Result, error)

DeleteLink issue a Delete http request to the resource URI

func (*Client) DeleteLinkRule

func (c *Client) DeleteLinkRule(linkRule *LinkRule) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeleteLinkType

func (c *Client) DeleteLinkType(linkType *LinkType) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeleteLinkTypeAttr

func (c *Client) DeleteLinkTypeAttr(typeAttr *LinkTypeAttribute) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeleteMembership

func (c *Client) DeleteMembership(member *Membership) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeleteModel

func (c *Client) DeleteModel(model *Model) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeletePartition

func (c *Client) DeletePartition(partition *Partition) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeletePrivilege

func (c *Client) DeletePrivilege(privilege *Privilege) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeleteRole

func (c *Client) DeleteRole(role *Role) (*Result, error)

issue a Delete http request to the resource URI

func (*Client) DeleteUser

func (c *Client) DeleteUser(user *User) (*Result, error)

DeleteUser issue a Delete http request to the resource URI

func (*Client) Get

func (c *Client) Get(url string, processor HttpRequestProcessor) (*http.Response, error)

Make a GET HTTP request to the specified URL

func (*Client) GetChildrenByType

func (c *Client) GetChildrenByType(item *Item, childType string) (*ItemList, error)

GetChildrenByType get a list of first level children of the specified type

func (*Client) GetItem

func (c *Client) GetItem(item *Item) (*Item, error)

issue a Get http request to the resource URI

func (*Client) GetItemChildren

func (c *Client) GetItemChildren(item *Item) (*ItemList, error)

Get a list of items which are linked to the specified item

func (*Client) GetItemType

func (c *Client) GetItemType(itemType *ItemType) (*ItemType, error)

issue a Get http request to the resource URI itemType: an instance of the Item Type with the key of the item to retrieve

func (*Client) GetItemTypeAttr

func (c *Client) GetItemTypeAttr(typeAttr *ItemTypeAttribute) (*ItemTypeAttribute, error)

issue a Get http request to the resource URI

func (*Client) GetItemsByType

func (c *Client) GetItemsByType(itemType string) (*ItemList, error)

func (*Client) GetItemsOfType

func (c *Client) GetItemsOfType(itemType string) (*ItemList, error)
func (c *Client) GetLink(link *Link) (*Link, error)

GetLink issue a Get http request to the resource URI

func (*Client) GetLinkRule

func (c *Client) GetLinkRule(linkRule *LinkRule) (*LinkRule, error)

issue a Get http request to the resource URI

func (*Client) GetLinkType

func (c *Client) GetLinkType(linkType *LinkType) (*LinkType, error)

issue a Get http request to the resource URI

func (*Client) GetLinkTypeAttr

func (c *Client) GetLinkTypeAttr(typeAttr *LinkTypeAttribute) (*LinkTypeAttribute, error)

issue a Get http request to the resource URI

func (c *Client) GetLinks() (*LinkList, error)

func (*Client) GetMembership

func (c *Client) GetMembership(member *Membership) (*Membership, error)

issue a Get http request to the resource URI

func (*Client) GetModel

func (c *Client) GetModel(model *Model) (*Model, error)

issue a Get http request to the resource URI

func (*Client) GetPartition

func (c *Client) GetPartition(partition *Partition) (*Partition, error)

issue a Get http request to the resource URI

func (*Client) GetPrivilege

func (c *Client) GetPrivilege(privilege *Privilege) (*Privilege, error)

issue a Get http request to the resource URI

func (*Client) GetRole

func (c *Client) GetRole(role *Role) (*Role, error)

issue a Get http request to the resource URI

func (*Client) GetUser

func (c *Client) GetUser(user *User) (*User, error)

GetUser issue a Get http request to the resource URI

func (*Client) Login

func (c *Client) Login(credentials *Login) (*h.UserPrincipal, error)

Login check that the user is authenticated using the CMDB as user store and returns a list of access controls for the user

func (*Client) MakeRequest

func (c *Client) MakeRequest(method string, url string, payload Serializable, processor HttpRequestProcessor) (*http.Response, error)

Make a generic HTTP request

func (*Client) Post

func (c *Client) Post(url string, payload Serializable, processor HttpRequestProcessor) (*http.Response, error)

Make a POST HTTP request to the specified URL

func (*Client) Put

func (c *Client) Put(url string, payload Serializable, processor HttpRequestProcessor) (*http.Response, error)

Make a PUT HTTP request to the specified URL

func (*Client) PutData

func (c *Client) PutData(data *GraphData) (*Result, error)

issue a Put http request with the GraphData as payload to the resource URI

func (*Client) PutItem

func (c *Client) PutItem(item *Item) (*Result, error)

issue a Put http request with the Item data as payload to the resource URI

func (*Client) PutItemType

func (c *Client) PutItemType(itemType *ItemType) (*Result, error)

issue a Put http request with the Item Type data as payload to the resource URI

func (*Client) PutItemTypeAttr

func (c *Client) PutItemTypeAttr(typeAttr *ItemTypeAttribute) (*Result, error)

issue a Put http request with the Item Type Attribute data as payload to the resource URI

func (c *Client) PutLink(link *Link) (*Result, error)

PutLink issue a Put http request with the Link data as payload to the resource URI

func (*Client) PutLinkRule

func (c *Client) PutLinkRule(linkRule *LinkRule) (*Result, error)

issue a Put http request with the Link rule data as payload to the resource URI

func (*Client) PutLinkType

func (c *Client) PutLinkType(linkType *LinkType) (*Result, error)

issue a Put http request with the link type data as payload to the resource URI

func (*Client) PutLinkTypeAttr

func (c *Client) PutLinkTypeAttr(typeAttr *LinkTypeAttribute) (*Result, error)

issue a Put http request with the Link Type Attribute data as payload to the resource URI

func (*Client) PutMembership

func (c *Client) PutMembership(member *Membership) (*Result, error)

issue a Put http request with the Membership data as payload to the resource URI

func (*Client) PutModel

func (c *Client) PutModel(model *Model) (*Result, error)

issue a Put http request with the Model data as payload to the resource URI

func (*Client) PutPartition

func (c *Client) PutPartition(partition *Partition) (*Result, error)

issue a Put http request with the Partition data as payload to the resource URI

func (*Client) PutPrivilege

func (c *Client) PutPrivilege(privilege *Privilege) (*Result, error)

issue a Put http request with the Privilege data as payload to the resource URI

func (*Client) PutRole

func (c *Client) PutRole(role *Role) (*Result, error)

issue a Put http request with the Role data as payload to the resource URI

func (*Client) PutUser

func (c *Client) PutUser(user *User, notify bool) (*Result, error)

PutUser issue a Put http request with the User data as payload to the resource URI notify: if true, emails new users to make them aware of the new account

requires the service to have email integration enabled

type ClientConf

type ClientConf struct {
	// the base URI for the service
	BaseURI string
	// disables TLS certificate verification
	InsecureSkipVerify bool
	// how to authenticate with the Web API
	AuthMode AuthenticationMode
	// the user username for Basic and OpenId user authentication
	Username string
	// the user password for Basic and OpenId user authentication
	Password string
	// the URI of the OpenId server token endpoint
	// used by the client to retrieve an OpenId token
	TokenURI string
	// the username to authenticate with the token service
	ClientId string
	// the password to authenticate with the token service
	AppSecret string
	// time out
	Timeout time.Duration
}

client configuration information

func (*ClientConf) SetAuthMode

func (cfg *ClientConf) SetAuthMode(authMode string)

sets the AuthMode from a passed-in string

type EventConfig

type EventConfig struct {
	// the MQTT Server url
	Server string
	// the item type for which to get notification changes (itemInstance must be empty)
	ItemType string
	// the item instance for which to get notification changes (ItemType must be empty)
	ItemInstance string
	// the quality of service for message delivery - 0: at most once, 1: at least once, 2: exactly once
	Qos int
	// authentication Username
	Username string
	// authentication Password
	Password string
	// skip tls certificate verification
	InsecureSkipVerify bool
	// the policy the Server will follow for TLS Client Authentication
	ClientAuthType tls.ClientAuthType
	// a function to process received messages
	OnMsgReceived MQTT.MessageHandler
}

configuration for the event manager (mqtt broker)

type EventManager

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

EventManager MQTT client for change notifications

func NewEventManager

func NewEventManager(cfg *EventConfig) (*EventManager, error)

NewEventManager creates a new event manager subscribed to a specific topic cfg: the mqtt server configuration

func (*EventManager) Connect

func (m *EventManager) Connect() error

Connect to the message broker

func (*EventManager) Disconnect

func (m *EventManager) Disconnect(timeoutMilSecs uint)

Disconnect from the message broker

type GraphData

type GraphData struct {
	Models             []Model             `json:"models"`
	ItemTypes          []ItemType          `json:"itemTypes"`
	ItemTypeAttributes []ItemTypeAttribute `json:"itemTypeAttributes"`
	LinkTypes          []LinkType          `json:"linkTypes"`
	LinkTypeAttribute  []LinkTypeAttribute `json:"linkTypeAttributes"`
	LinkRules          []LinkRule          `json:"linkRules"`
	Items              []Item              `json:"items"`
	Links              []Link              `json:"links"`
}

type HttpRequestProcessor

type HttpRequestProcessor func(req *http.Request, payload Serializable) error

modify the http request for example by adding any relevant http headers payload is provided for example, in case a Content-MD5 header has to be added to the request

type Item

type Item struct {
	Key         string                 `json:"key"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Status      int                    `json:"status"`
	Type        string                 `json:"type"`
	Tag         []interface{}          `json:"tag"`
	Meta        map[string]interface{} `json:"meta"`
	Txt         string                 `json:"txt"`
	Attribute   map[string]interface{} `json:"attribute"`
	Partition   string                 `json:"partition"`
	Version     int64                  `json:"version"`
	Created     string                 `json:"created"`
	Updated     string                 `json:"updated"`
	EncKeyIx    int64                  `json:"encKeyIx"`
	ChangedBy   string                 `json:"changedBy"`
}

the Item resource

func (*Item) GetBoolAttr

func (item *Item) GetBoolAttr(name string) bool

GetBoolAttr return the value of the boolean attribute for the specified name or false if the attribute does not exist

func (*Item) GetStringAttr

func (item *Item) GetStringAttr(name string) string

GetStringAttr return the value of the string attribute for the specified name or empty if the attribute does not exist

type ItemList

type ItemList struct {
	Values []Item
}

type ItemType

type ItemType struct {
	Key          string                 `json:"key"`
	Name         string                 `json:"name"`
	Description  string                 `json:"description"`
	Filter       map[string]interface{} `json:"filter"`
	MetaSchema   map[string]interface{} `json:"metaSchema"`
	Model        string                 `json:"modelKey"`
	NotifyChange ChangeNotifyType       `json:"notifyChange"`
	Tag          []interface{}          `json:"tag"`
	EncryptMeta  bool                   `json:"encryptMeta"`
	EncryptTxt   bool                   `json:"encryptTxt"`
	Style        map[string]interface{} `json:"style"`
	Version      int64                  `json:"version"`
	Created      string                 `json:"created"`
	Updated      string                 `json:"updated"`
	ChangedBy    string                 `json:"changedBy"`
}

the Item Type resource

type ItemTypeAttribute

type ItemTypeAttribute struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Type        string `json:"type"`
	DefValue    string `json:"defValue"`
	Required    bool   `json:"required"`
	Regex       string `json:"regex"`
	ItemTypeKey string `json:"itemTypeKey"`
	Version     int64  `json:"version"`
	Created     string `json:"created"`
	Updated     string `json:"updated"`
	ChangedBy   string `json:"changedBy"`
}

type ItemTypeAttributeList

type ItemTypeAttributeList struct {
	Values []ItemTypeAttribute
}

type ItemTypeList

type ItemTypeList struct {
	Values []ItemType
}
type Link struct {
	Key          string                 `json:"key"`
	Description  string                 `json:"description"`
	Type         string                 `json:"type"`
	Tag          []interface{}          `json:"tag"`
	Meta         map[string]interface{} `json:"meta"`
	Attribute    map[string]interface{} `json:"attribute"`
	StartItemKey string                 `json:"startItemKey"`
	EndItemKey   string                 `json:"endItemKey"`
	Version      int64                  `json:"version"`
	Created      string                 `json:"created"`
	Updated      string                 `json:"updated"`
	ChangedBy    string                 `json:"changedBy"`
}
type LinkList struct {
	Values []Link
}

type LinkRule

type LinkRule struct {
	Key              string `json:"key"`
	Name             string `json:"name"`
	Description      string `json:"description"`
	LinkTypeKey      string `json:"linkTypeKey"`
	StartItemTypeKey string `json:"startItemTypeKey"`
	EndItemTypeKey   string `json:"endItemTypeKey"`
	Version          int64  `json:"version"`
	Created          string `json:"created"`
	Updated          string `json:"updated"`
	ChangedBy        string `json:"changedBy"`
}

type LinkRuleList

type LinkRuleList struct {
	Values []LinkRule
}

type LinkType

type LinkType struct {
	Key         string                 `json:"key"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	MetaSchema  map[string]interface{} `json:"metaSchema"`
	Model       string                 `json:"modelKey"`
	Tag         []interface{}          `json:"tag"`
	EncryptMeta bool                   `json:"encryptMeta"`
	EncryptTxt  bool                   `json:"encryptTxt"`
	Style       map[string]interface{} `json:"style"`
	Version     int64                  `json:"version"`
	Created     string                 `json:"created"`
	Updated     string                 `json:"updated"`
	ChangedBy   string                 `json:"changedBy"`
}

type LinkTypeAttribute

type LinkTypeAttribute struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Type        string `json:"type"`
	DefValue    string `json:"defValue"`
	Required    bool   `json:"required"`
	Regex       string `json:"regex"`
	LinkTypeKey string `json:"linkTypeKey"`
	Version     int64  `json:"version"`
	Created     string `json:"created"`
	Updated     string `json:"updated"`
	ChangedBy   string `json:"changedBy"`
}

type LinkTypeAttributeList

type LinkTypeAttributeList struct {
	Values []LinkTypeAttribute
}

type LinkTypeList

type LinkTypeList struct {
	Values []Item
}

type Login

type Login struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

Login information for users authenticating with client devices such as web browsers

type Membership

type Membership struct {
	Key       string `json:"key"`
	User      string `json:"userKey"`
	Role      string `json:"roleKey"`
	Version   int64  `json:"version"`
	Created   string `json:"created"`
	Updated   string `json:"updated"`
	ChangedBy string `json:"changedBy"`
}

the Role resource

type MembershipList

type MembershipList struct {
	Values []Membership
}

type Model

type Model struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Partition   string `json:"partition"`
	Managed     bool   `json:"managed"`
	Version     int64  `json:"version"`
	Created     string `json:"created"`
	Updated     string `json:"updated"`
	ChangedBy   string `json:"changedBy"`
}

the Model resource

type ModelList

type ModelList struct {
	Values []Model
}

type OAuthTokenResponse

type OAuthTokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope"`
	IdToken     string `json:"id_token"`
}

Response to an OAUth 2.0 token request

type Partition

type Partition struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Owner       string `json:"owner"`
	Version     int64  `json:"version"`
	Created     string `json:"created"`
	Updated     string `json:"updated"`
	ChangedBy   string `json:"changedBy"`
}

the Partition resource

type PartitionList

type PartitionList struct {
	Values []Partition
}

type Privilege

type Privilege struct {
	Key       string `json:"key"`
	Role      string `json:"roleKey"`
	Partition string `json:"partitionKey"`
	Create    bool   `json:"canCreate"`
	Read      bool   `json:"canRead"`
	Delete    bool   `json:"canDelete"`
	Version   int64  `json:"version"`
	Created   string `json:"created"`
	Updated   string `json:"updated"`
	ChangedBy string `json:"changedBy"`
}

the Privilege resource

type PrivilegeList

type PrivilegeList struct {
	Values []Privilege
}

type Result

type Result struct {
	Changed   bool   `json:"changed"`
	Error     bool   `json:"error"`
	Message   string `json:"message"`
	Operation string `json:"operation"`
	Ref       string `json:"ref"`
}

Result data retrieved by PUT and DELETE WAPI resources

type Role

type Role struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Owner       string `json:"owner"`
	Level       int    `json:"level"`
	Version     int64  `json:"version"`
	Created     string `json:"created"`
	Updated     string `json:"updated"`
	ChangedBy   string `json:"changedBy"`
}

the Role resource

type RoleList

type RoleList struct {
	Values []Role
}

type Serializable

type Serializable interface {
	// contains filtered or unexported methods
}

all entities interface for payload serialisation

type StringPayload

type StringPayload string

a payload for an http operation in

type User

type User struct {
	Key       string `json:"key"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	Pwd       string `json:"pwd"`
	Expires   string `json:"expires"`
	Service   bool   `json:"service"`
	ACL       string `json:"acl"`
	Version   int64  `json:"version"`
	Created   string `json:"created"`
	Updated   string `json:"updated"`
	ChangedBy string `json:"changedBy"`
}

User the user resource

func (*User) Allowed

func (user *User) Allowed(acRealm, acURI, acMethod string) bool

func (*User) Controls

func (user *User) Controls() []AccessControl

type UserList

type UserList struct {
	Values []User
}

Jump to

Keyboard shortcuts

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