ipso

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 10 Imported by: 0

README

IPSO registry

License Godoc ReportCard


Functionality

  • Import registry from OMA API
  • Export registry to YAML-file
  • Import registry from file
  • Compare two registries
  • Find objects and resources by ID and version
  • Find resources by object ID and resource ID
  • Find resources by OIR string i.e. "3303/0/5700"
  • Sanitize objects and resources text fields

Usage examples

Initialize a registry from OMA API:

reg, err := registry.New(ipso.DefaultConfiguration())

Export initialized registry to YAML file:

err := reg.Export("registry.yaml")

Import a previously exported registry from YAML file:

err := reg.Import("registry.yaml")

Create a registry with custom configuration:

cfg := ipso.Configuration{
    InitOnNew:      false,
    SkipInitErrors: false,
    Sanitize: false,
}

reg, err := ipso.New(cfg)

Compare two registries:

comp := reg1.Compare(reg2.GetRegistry())

Remove unwanted strings from objects and resources description:

reg.Sanitize(ipso.DefaultSanitizer())

Linter

go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.38.0
golangci-lint run --enable-all

License

MIT

Documentation

Overview

Package ipso_registry provides methods to create and control OMA IPSO registry.

Index

Constants

View Source
const (
	DefaultLwM2MVersion  = "1.0"
	DefaultObjectVersion = "1.0"
)

Variables

This section is empty.

Functions

func DefaultSanitizer

func DefaultSanitizer() []string

DefaultSanitizer returns an array with default sanitizer strings.

Types

type Configuration

type Configuration struct {
	InitOnNew      bool     // indicates whether registry should be initialized from API on creation
	SkipInitErrors bool     // indicates whether to ignore particular resource or object initialization errors
	Sanitize       bool     // whether objects and Resources description should be cleaned up on registry init
	Sanitizer      []string // strings that should be removed from resource and object description

}

Configuration to control the registry.

func DefaultConfiguration

func DefaultConfiguration() Configuration

DefaultConfiguration creates a Configuration with the default settings.

type DifferenceType

type DifferenceType string

DifferenceType represents the objects difference explanation.

const (
	DifferenceTypeUnknown       DifferenceType = "Unknown reason"
	DifferenceTypeNewObject     DifferenceType = "New object added"
	DifferenceTypeObjectRemoved DifferenceType = "Object was removed"
)

DifferenceType constants.

func (DifferenceType) String

func (e DifferenceType) String() string

String for ResourceType.

type InstanceType

type InstanceType string

InstanceType represents the type of data.

const (
	InstanceTypeSingle   InstanceType = "Single"
	InstanceTypeMultiple InstanceType = "Multiple"
)

InstanceType constants.

func (InstanceType) String

func (e InstanceType) String() string

String for InstanceType.

type Lwm2M

type Lwm2M struct {
	Object Object `json:"Object,omitempty" xml:"Object"`
}

Lwm2M struct for Lwm2M wrapper entry.

type MandatoryType

type MandatoryType string

MandatoryType represents the type of data.

const (
	MandatoryTypeOptional  MandatoryType = "Optional"
	MandatoryTypeMandatory MandatoryType = "Mandatory"
)

MandatoryType constants.

func (MandatoryType) String

func (e MandatoryType) String() string

String for MandatoryType.

type Object

type Object struct {
	Name              string          `json:"Name" xml:"Name" yaml:"Name"`
	Description1      string          `json:"Description1,omitempty" xml:"Description1" yaml:"Description1"`
	Description2      string          `json:"Description2,omitempty" xml:"Description2" yaml:"Description2"`
	ObjectID          int32           `json:"ObjectID" xml:"ObjectID" yaml:"ObjectID"`
	ObjectURN         string          `json:"ObjectURN,omitempty" xml:"ObjectURN" yaml:"ObjectURN"`
	LWM2MVersion      string          `json:"LWM2MVersion,omitempty" xml:"LWM2MVersion" yaml:"LWM2MVersion"`
	ObjectVersion     string          `json:"ObjectVersion,omitempty" xml:"ObjectVersion" yaml:"ObjectVersion"`
	MultipleInstances InstanceType    `json:"MultipleInstances" xml:"MultipleInstances" yaml:"MultipleInstances"`
	Mandatory         MandatoryType   `json:"Mandatory" xml:"Mandatory" yaml:"Mandatory"`
	Resources         ObjectResources `json:"Resources" xml:"Resources" yaml:"Resources"`
}

Object structure represents OMA Object entity.

type ObjectComparison

type ObjectComparison struct {
	Difference DifferenceType
	Object     Object // object in existing registry
	ObjectComp Object // object in compared registry, which is passed as parameter to Compare function
}

ObjectComparison contains details of two objects comparison.

type ObjectMeta

type ObjectMeta struct {
	ObjectID          int32  `json:"ObjectID" xml:"ObjectID" yaml:"ObjectID"`
	Ver               string `json:"Ver,omitempty" xml:"Ver" yaml:"Ver"`
	URN               string `json:"URN,omitempty" xml:"URN" yaml:"URN"`
	Name              string `json:"Name" xml:"Name" yaml:"Name"`
	Description       string `json:"Description,omitempty" xml:"Description" yaml:"Description"`
	Owner             string `json:"Owner,omitempty" xml:"Owner" yaml:"Owner"`
	Label             string `json:"Label,omitempty" xml:"Label" yaml:"Label"`
	ObjectLink        string `json:"ObjectLink" xml:"ObjectLink" yaml:"ObjectLink"`
	ObjectLinkVisible string `json:"ObjectLinkVisible,omitempty" xml:"ObjectLinkVisible" yaml:"ObjectLinkVisible"`
	SpecLink          string `json:"SpecLink,omitempty" xml:"SpecLink" yaml:"SpecLink"`
	SpecLinkVisible   string `json:"SpecLinkVisible,omitempty" xml:"SpecLinkVisible" yaml:"SpecLinkVisible"`
	VortoLink         string `json:"VortoLink,omitempty" xml:"VortoLink" yaml:"VortoLink"`
}

ObjectMeta struct for ObjectMeta.

type ObjectResources

type ObjectResources struct {
	Item []Resource `json:"Item,omitempty" xml:"Item" yaml:"Item,omitempty"`
}

ObjectResources struct for ObjectResources field.

type OperationType

type OperationType string

OperationType represents the type of data.

const (
	OperationTypeRead      OperationType = "R"
	OperationTypeWrite     OperationType = "W"
	OperationTypeReadWrite OperationType = "RW"
	OperationTypeExecute   OperationType = "E"
)

OperationType constants.

func (OperationType) String

func (e OperationType) String() string

String for OperationType.

type Reg

type Reg struct {
	Config  Configuration
	Objects []Object
	// contains filtered or unexported fields
}

Reg contains registry objects and settings.

func (*Reg) Compare

func (r *Reg) Compare(reg *Reg) []ObjectComparison

Compare r and reg registries. Return a list of non-equal objects with difference explanation.

func (*Reg) Export

func (r *Reg) Export(filename string) error

Export store registry objects and resources in a specified file in YAML format.

func (*Reg) Find

func (r *Reg) Find(o Object) (Object, error)

Find look for an object in the current registry. Return an empty object and error, when the object not found.

func (*Reg) FindObjectByIDAndVer

func (r *Reg) FindObjectByIDAndVer(id int32, ver string) (Object, error)

FindObjectByIDAndVer find an object in the registry by ID and version. Return an empty object and error, when the object not found.

func (*Reg) FindObjectsByID

func (r *Reg) FindObjectsByID(id int32) ([]Object, error)

FindObjectsByID find objects in the registry by ID. Multiple objects with same ID and different versions could be returned. Return an error, when no objects found.

func (*Reg) FindResourceByOIR

func (r *Reg) FindResourceByOIR(oir string) (Resource, error)

FindResourceByOIR find specific resource in registry by OIR string (i.e. "3303/0/5700" - object/instance/resource). Use latest object version. Return a single matching resource of specific object. Return an empty resource and error, when resource or object not found.

func (*Reg) FindResourceByObjIDObjVerResID

func (r *Reg) FindResourceByObjIDObjVerResID(objID int32, objVer string, resID int32) (Resource, error)

FindResourceByObjIDObjVerResID find specific resource in registry by object ID, object version and resource ID. Return a single matching resource of specific object. Return an empty resource and error, when resource or object not found.

func (*Reg) FindResourcesByID

func (r *Reg) FindResourcesByID(id int32) ([]Resource, error)

FindResourcesByID find resources in registry by ID. Return matching resources from all objects of all versions. Return an error, when resource not found.

func (*Reg) FindResourcesByObjResIDs

func (r *Reg) FindResourcesByObjResIDs(objID, resID int32) ([]Resource, error)

FindResourcesByObjResIDs find resources in registry by object ID and resource ID. Return matching resources from all versions of specific object. Return an error, when resource or object not found.

func (*Reg) GetObjects

func (r *Reg) GetObjects() []Object

GetObjects return all objects from registry.

func (*Reg) GetRegistry

func (r *Reg) GetRegistry() *Reg

GetRegistry returns internal registry structure. Temporary solution, will be removed in next releases.

func (*Reg) Import

func (r *Reg) Import(filename string) error

Import load objects and resources from file. Overwrite current registry objects and resources.

func (*Reg) ImportFromAPI

func (r *Reg) ImportFromAPI() ([]Object, error)

ImportFromAPI initialize the registry from official OMA API. Overwrite current registry objects and resources. Fill empty object and LwM2M versions with default values "1.0".

func (*Reg) Sanitize

func (r *Reg) Sanitize(sanitizer []string)

Sanitize removes unwanted strings from objects and resources description fields using sanitizer strings from registry configuration. Also removes leading and trailing spaces. Description fields in objects and resources do not follow any single format or convention in regard to line breaks, lists presentation, special characters escaping etc. thus in some cases cannot be used directly in external applications (i.e. properly displayed in browser).

type Registry

type Registry interface {
	Import(filename string) error
	ImportFromAPI() ([]Object, error)
	Export(filename string) error
	Compare(reg *Reg) []ObjectComparison

	Find(o Object) (Object, error)
	FindObjectsByID(id int32) ([]Object, error)
	FindObjectByIDAndVer(id int32, ver string) (Object, error)
	FindResourcesByID(id int32) ([]Resource, error)
	FindResourcesByObjResIDs(objID, resID int32) ([]Resource, error)
	FindResourceByObjIDObjVerResID(objID int32, objVer string, resID int32) (Resource, error)
	FindResourceByOIR(oir string) (Resource, error)

	GetObjects() []Object

	Sanitize(sanitizer []string)

	GetRegistry() *Reg
}

Registry an interface defining public library functions.

func New

func New(cfg Configuration) (Registry, error)

New create a new registry, using provided or default configuration.

type Resource

type Resource struct {
	ID                int32         `json:"ID" xml:"ID,attr"`
	Name              string        `json:"Name" xml:"Name"`
	Operations        OperationType `json:"Operations" xml:"Operations"`
	MultipleInstances InstanceType  `json:"MultipleInstances" xml:"MultipleInstances"`
	Mandatory         MandatoryType `json:"Mandatory" xml:"Mandatory"`
	Type              ResourceType  `json:"Type" xml:"Type"`
	RangeEnumeration  string        `json:"RangeEnumeration,omitempty" xml:"RangeEnumeration"`
	Units             string        `json:"Units,omitempty" xml:"Units"`
	Description       string        `json:"Description,omitempty" xml:"Description"`
}

Resource structure represents OMA Resource entity.

type ResourceType

type ResourceType string

ResourceType represents the type of data.

const (
	ResourceTypeString          ResourceType = "String"
	ResourceTypeInteger         ResourceType = "Integer"
	ResourceTypeUnsignedInteger ResourceType = "Unsigned Integer"
	ResourceTypeFloat           ResourceType = "Float"
	ResourceTypeBoolean         ResourceType = "Boolean"
	ResourceTypeOpaque          ResourceType = "Opaque"
	ResourceTypeTime            ResourceType = "Time"
	ResourceTypeObjLink         ResourceType = "Objlnk"
	ResourceTypeCoreLink        ResourceType = "Corelnk"
	ResourceTypeNone            ResourceType = "none"
)

ResourceType constants according to OMA-TS-LightweightM2M_Core-V1_2-20201110-A Appendix C. Data types (Normative).

func (ResourceType) String

func (e ResourceType) String() string

String for ResourceType.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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