tdr

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package tdr provides support for HSDP TDR operations

Index

Constants

View Source
const (
	APIVersion = "5"
)

Variables

View Source
var (
	ErrBaseTDRCannotBeEmpty           = errors.New("base TDR URL cannot be empty")
	ErrMissingTDRScopes               = errors.New("missing TDR scopes. Need 'tdr.contract' and 'tdr.dataitem'")
	ErrEmptyResult                    = errors.New("empty result")
	ErrCouldNoReadResourceAfterCreate = errors.New("could not read resource after create")
	ErrEmptyResults                   = errors.New("empty results")
)

Errors

Functions

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type Client

type Client struct {

	// User agent used when communicating with the HSDP IAM API.
	UserAgent string

	Contracts *ContractsService
	DataItems *DataItemsService
	// contains filtered or unexported fields
}

A Client manages communication with HSDP IAM API

func NewClient

func NewClient(iamClient *iam.Client, config *Config) (*Client, error)

NewClient returns a new HSDP TDR API client. If a nil httpClient is provided, http.DefaultClient will be used. A configured IAM client must be provided as well

func (*Client) Close

func (c *Client) Close()

Close releases allocated resources of clients

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do executes a http request. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) SetBaseTDRURL

func (c *Client) SetBaseTDRURL(urlStr string) error

SetBaseTDRURL sets the base URL for API requests to a custom endpoint. urlStr should always be specified with a trailing slash.

type Config

type Config struct {
	TDRURL   string
	Debug    bool
	DebugLog io.Writer
}

Config contains the configuration of a client

type Contract

type Contract struct {
	ID                         string          `json:"id,omitempty"`
	Meta                       *Meta           `json:"meta,omitempty"`
	DataType                   DataType        `json:"dataType,omitempty"`
	Schema                     json.RawMessage `json:"schema,omitempty"`
	Organization               string          `json:"organization,omitempty"`
	SendNotifications          bool            `json:"sendNotifications"`
	NotificationServiceTopicID string          `json:"notificationServiceTopicId,omitempty"`
	DeletePolicy               DeletePolicy    `json:"deletePolicy"`
}

Contract describes a TDR Contract

func (*Contract) String

func (c *Contract) String() string

String pretty prints a Contract

type ContractsService

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

ContractsService provides operations on TDR contracts

func (*ContractsService) CreateContract

func (c *ContractsService) CreateContract(contract Contract) (bool, *Response, error)

CreateContract creates a new contract in TDR

func (*ContractsService) GetContract

func (c *ContractsService) GetContract(opt *GetContractOptions, options ...OptionFunc) ([]*Contract, *Response, error)

GetContract searches for contracts in TDR

type DataItem

type DataItem struct {
	ID                string            `json:"id,omitempty"`
	Meta              Meta              `json:"meta,omitempty"`
	ResourceType      string            `json:"resourceType,omitempty"`
	Timestamp         string            `json:"timestamp,omitempty"`
	SequenceNumber    int               `json:"sequenceNumber,omitempty"`
	Device            Device            `json:"device,omitempty"`
	User              User              `json:"user,omitempty"`
	RelatedPeripheral RelatedPeripheral `json:"relatedPeripheral,omitempty"`
	RelatedUser       RelatedUser       `json:"relatedUser,omitempty"`
	DataType          DataType          `json:"dataType,omitempty"`
	Organization      string            `json:"organization,omitempty"`
	Application       string            `json:"application,omitempty"`
	Proposition       string            `json:"proposition,omitempty"`
	Subscription      string            `json:"subscription,omitempty"`
	DataSource        string            `json:"dataSource,omitempty"`
	DataCategory      string            `json:"dataCategory,omitempty"`
	Data              json.RawMessage   `json:"data,omitempty"`
	Blob              string            `json:"blob,omitempty"`
	DeleteTimestamp   string            `json:"deleteTimestamp,omitempty"`
	CreationTimestamp string            `json:"creationTimestamp,omitempty"`
	Tombstone         bool              `json:"tombstone,omitempty"`
}

DataItem describes a TDR Data item

type DataItemsService

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

DataItemsService provides operations on TDR data items

func (*DataItemsService) GetDataItem

func (d *DataItemsService) GetDataItem(opt *GetDataItemOptions, options ...OptionFunc) ([]*DataItem, *Response, error)

GetDataItem searches for data items in TDR Use the DataSearch OptionFunc to search in the data part. When using this the DataType must be added as part of the options

type DataType

type DataType struct {
	System string `json:"system,omitempty"`
	Code   string `json:"code,omitempty"`
}

DataType describes the system and code of a resource

func (DataType) String

func (d DataType) String() string

String pretty prints a DataType

type DeletePolicy

type DeletePolicy struct {
	Duration int    `json:"duration,omitempty"`
	Unit     string `json:"unit,omitempty"`
}

type Device

type Device struct {
	System string `json:"system"`
	Value  string `json:"value"`
}

Device describes a TDR device

type ErrorResponse added in v0.30.0

type ErrorResponse struct {
	Response *http.Response `json:"-"`
	Code     string         `json:"responseCode"`
	Message  string         `json:"responseMessage"`
}

ErrorResponse represents an IAM errors response containing a code and a human readable message

func (*ErrorResponse) Error added in v0.30.0

func (e *ErrorResponse) Error() string

type GetContractOptions

type GetContractOptions struct {
	Organization *string `url:"organization,omitempty"`
	DataType     *string `url:"dataType,omitempty"`
	Count        *int    `url:"_count,omitempty"`
}

GetContractOptions describes the fields on which you can search for contracts

type GetDataItemOptions

type GetDataItemOptions struct {
	Organization *string `url:"organization,omitempty"`
	DataType     *string `url:"dataType,omitempty"`
	Count        *int    `url:"_count,omitempty"`
}

GetDataItemOptions describes the fields on which you can search for data items

type KeyValue

type KeyValue map[string]string

KeyValue is backed by a string hash map

type Meta

type Meta struct {
	LastUpdated string `json:"lastUpdated,omitempty"`
	VersionID   string `json:"versionId,omitempty"`
}

Meta contains versioning info about the resource

type OptionFunc

type OptionFunc func(*http.Request) error

OptionFunc is the function signature function for options

func DataSearch

func DataSearch(kv KeyValue) OptionFunc

DataSearch builds a custom query for TDR searches on the data element

func WithContext

func WithContext(ctx context.Context) OptionFunc

WithContext runs the request with the provided context

type RelatedPeripheral

type RelatedPeripheral struct {
	System string `json:"system"`
	Value  string `json:"value"`
}

RelatedPeripheral describes a TDR related peripheral

type RelatedUser

type RelatedUser struct {
	System string `json:"system"`
	Value  string `json:"value"`
}

RelatedUser describes a TDR related user

type Response

type Response struct {
	*http.Response
}

Response is a HSDP IAM API response. This wraps the standard http.Response returned from HSDP IAM and provides convenient access to things like errors

func (*Response) StatusCode added in v0.73.0

func (r *Response) StatusCode() int

type User

type User struct {
	System string `json:"system"`
	Value  string `json:"value"`
}

User describes a TDR user

Jump to

Keyboard shortcuts

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