genericinterface

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package genericinterface provides the GenericInterface service for web service execution. This is the core execution engine for both inbound (Provider) and outbound (Requester) operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutocompleteResult

type AutocompleteResult struct {
	StoredValue  string                 `json:"StoredValue"`    // The stored value (e.g., ID) - OTRS compatible
	DisplayValue string                 `json:"DisplayValue"`   // The displayed text - OTRS compatible
	Data         map[string]interface{} `json:"Data,omitempty"` // Additional data for autofill
	// Legacy aliases for frontend compatibility (same values, different keys)
	Value string `json:"value,omitempty"` // Alias for StoredValue
	Label string `json:"label,omitempty"` // Alias for DisplayValue
}

AutocompleteResult represents a single autocomplete suggestion. JSON field names match OTRS's expected format for compatibility.

type FieldConfig

type FieldConfig struct {
	Webservice               string
	InvokerSearch            string
	InvokerGet               string
	StoredValue              string
	DisplayedValues          []string
	DisplayedValuesSeparator string
	SearchKeys               []string
	AutocompleteMinLength    int
	Limit                    int
	CacheTTL                 int
}

FieldConfig holds the configuration needed to query a webservice field.

func ParseFieldConfigFromMap

func ParseFieldConfigFromMap(configMap map[string]interface{}) FieldConfig

ParseFieldConfigFromMap parses a DynamicFieldConfig-like map into FieldConfig.

type RESTTransport

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

RESTTransport implements the Transport interface for HTTP REST APIs.

func NewRESTTransport

func NewRESTTransport() *RESTTransport

NewRESTTransport creates a new REST transport.

func (*RESTTransport) Execute

func (t *RESTTransport) Execute(ctx context.Context, config models.TransportHTTPConfig, request *Request) (*Response, error)

Execute performs an HTTP request to the remote REST API.

func (*RESTTransport) ExecuteRaw

func (t *RESTTransport) ExecuteRaw(ctx context.Context, method, url string, headers map[string]string, body []byte) (*Response, error)

ExecuteRaw performs a raw HTTP request with minimal processing. Useful for testing and debugging.

func (*RESTTransport) TestConnection

func (t *RESTTransport) TestConnection(ctx context.Context, config models.TransportHTTPConfig) error

TestConnection tests connectivity to the remote host.

func (*RESTTransport) Type

func (t *RESTTransport) Type() string

Type returns the transport type.

type Request

type Request struct {
	// Operation is the invoker/operation name.
	Operation string
	// Data contains the request payload.
	Data map[string]interface{}
	// Method is the HTTP method (GET, POST, PUT, DELETE).
	Method string
	// Path is the endpoint path (can contain placeholders like :id).
	Path string
}

Request represents an outbound request to a remote system.

type Response

type Response struct {
	// Success indicates if the request succeeded.
	Success bool
	// Data contains the response payload.
	Data map[string]interface{}
	// RawData contains the raw response body.
	RawData []byte
	// StatusCode is the HTTP status code.
	StatusCode int
	// Error contains any error message.
	Error string
	// Headers contains response headers.
	Headers map[string]string
}

Response represents a response from a remote system.

type SOAPBody

type SOAPBody struct {
	Content []byte `xml:",innerxml"`
	Fault   *SOAPFault
}

SOAPBody represents the SOAP body.

type SOAPEnvelope

type SOAPEnvelope struct {
	XMLName xml.Name    `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
	Header  *SOAPHeader `xml:"Header,omitempty"`
	Body    SOAPBody    `xml:"Body"`
}

SOAPEnvelope represents the SOAP envelope structure.

type SOAPFault

type SOAPFault struct {
	XMLName     xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault"`
	FaultCode   string   `xml:"faultcode"`
	FaultString string   `xml:"faultstring"`
	Detail      string   `xml:"detail,omitempty"`
}

SOAPFault represents a SOAP fault response.

func (*SOAPFault) Error

func (f *SOAPFault) Error() string

Error implements the error interface for SOAPFault.

type SOAPHeader

type SOAPHeader struct {
	Content []byte `xml:",innerxml"`
}

SOAPHeader represents the SOAP header.

type SOAPTransport

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

SOAPTransport implements the Transport interface for SOAP web services.

func NewSOAPTransport

func NewSOAPTransport() *SOAPTransport

NewSOAPTransport creates a new SOAP transport.

func (*SOAPTransport) BuildSOAPRequest

func (t *SOAPTransport) BuildSOAPRequest(config models.TransportHTTPConfig, request *Request) ([]byte, error)

BuildSOAPRequest creates a complete SOAP request envelope for debugging/testing.

func (*SOAPTransport) Execute

func (t *SOAPTransport) Execute(ctx context.Context, config models.TransportHTTPConfig, request *Request) (*Response, error)

Execute performs a SOAP request to the remote service.

func (*SOAPTransport) TestConnection

func (t *SOAPTransport) TestConnection(ctx context.Context, config models.TransportHTTPConfig) error

TestConnection tests connectivity to the SOAP endpoint.

func (*SOAPTransport) Type

func (t *SOAPTransport) Type() string

Type returns the transport type.

type Service

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

Service is the main GenericInterface execution service.

func NewService

func NewService(db *sql.DB) *Service

NewService creates a new GenericInterface service.

func (*Service) CreateWebservice

func (s *Service) CreateWebservice(ctx context.Context, ws *models.WebserviceConfig, userID int) (int, error)

CreateWebservice creates a new webservice configuration.

func (*Service) DeleteWebservice

func (s *Service) DeleteWebservice(ctx context.Context, id int) error

DeleteWebservice deletes a webservice configuration.

func (*Service) GetHistory

func (s *Service) GetHistory(ctx context.Context, configID int) ([]*models.WebserviceConfigHistory, error)

GetHistory returns the configuration history for a webservice.

func (*Service) GetTransport

func (s *Service) GetTransport(transportType string) (Transport, error)

GetTransport returns a transport by type.

func (*Service) GetWebservice

func (s *Service) GetWebservice(ctx context.Context, name string) (*models.WebserviceConfig, error)

GetWebservice returns a webservice configuration by name.

func (*Service) GetWebserviceByID

func (s *Service) GetWebserviceByID(ctx context.Context, id int) (*models.WebserviceConfig, error)

GetWebserviceByID returns a webservice configuration by ID.

func (*Service) GetWebservicesForField

func (s *Service) GetWebservicesForField(ctx context.Context) ([]*models.WebserviceConfig, error)

GetWebservicesForField returns webservices suitable for dynamic field configuration.

func (*Service) Invoke

func (s *Service) Invoke(ctx context.Context, webserviceName, invokerName string, data map[string]interface{}) (*Response, error)

Invoke executes an invoker on a webservice. This is the main method for making outbound requests.

func (*Service) InvokeWithController

func (s *Service) InvokeWithController(ctx context.Context, webserviceName, invokerName string, controller string, method string, data map[string]interface{}) (*Response, error)

InvokeWithController executes an invoker with specific controller/path settings. Used for REST APIs where the path may vary based on parameters.

func (*Service) ListValidWebservices

func (s *Service) ListValidWebservices(ctx context.Context) ([]*models.WebserviceConfig, error)

ListValidWebservices returns only valid (active) webservices.

func (*Service) ListWebservices

func (s *Service) ListWebservices(ctx context.Context) ([]*models.WebserviceConfig, error)

ListWebservices returns all webservice configurations.

func (*Service) RegisterTransport

func (s *Service) RegisterTransport(t Transport)

RegisterTransport registers a transport implementation.

func (*Service) RestoreFromHistory

func (s *Service) RestoreFromHistory(ctx context.Context, historyID int64, userID int) error

RestoreFromHistory restores a webservice configuration from a history entry.

func (*Service) SetDebug

func (s *Service) SetDebug(debug bool)

SetDebug enables or disables debug logging.

func (*Service) UpdateWebservice

func (s *Service) UpdateWebservice(ctx context.Context, ws *models.WebserviceConfig, userID int) error

UpdateWebservice updates an existing webservice configuration.

func (*Service) WebserviceExists

func (s *Service) WebserviceExists(ctx context.Context, name string) (bool, error)

WebserviceExists checks if a webservice with the given name exists.

func (*Service) WebserviceExistsExcluding

func (s *Service) WebserviceExistsExcluding(ctx context.Context, name string, excludeID int) (bool, error)

WebserviceExistsExcluding checks if a webservice name exists, excluding a specific ID.

type Transport

type Transport interface {
	// Execute performs an HTTP request using the transport configuration.
	Execute(ctx context.Context, config models.TransportHTTPConfig, request *Request) (*Response, error)
	// Type returns the transport type (e.g., "HTTP::REST", "HTTP::SOAP").
	Type() string
}

Transport defines the interface for HTTP transports (REST, SOAP).

type WebserviceFieldService

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

WebserviceFieldService handles autocomplete and display value retrieval for WebserviceDropdown and WebserviceMultiselect dynamic fields.

func NewWebserviceFieldService

func NewWebserviceFieldService(db *sql.DB) *WebserviceFieldService

NewWebserviceFieldService creates a new webservice field service.

func NewWebserviceFieldServiceWithGI

func NewWebserviceFieldServiceWithGI(giService *Service) *WebserviceFieldService

NewWebserviceFieldServiceWithGI creates a service using an existing GI service.

func (*WebserviceFieldService) ClearCache

func (s *WebserviceFieldService) ClearCache(webservice string)

ClearCache clears the cache for a specific webservice or all caches.

func (*WebserviceFieldService) GetDisplayValue

func (s *WebserviceFieldService) GetDisplayValue(ctx context.Context, config FieldConfig, storedValue string) (string, error)

GetDisplayValue retrieves the display value for a stored value. This is used to show the human-readable label when loading existing data.

func (*WebserviceFieldService) GetMultipleDisplayValues

func (s *WebserviceFieldService) GetMultipleDisplayValues(ctx context.Context, config FieldConfig, storedValues []string) (map[string]string, error)

GetMultipleDisplayValues retrieves display values for multiple stored values. Used for WebserviceMultiselect fields.

func (*WebserviceFieldService) Search

func (s *WebserviceFieldService) Search(ctx context.Context, config FieldConfig, searchTerm string) ([]AutocompleteResult, error)

Search performs a search/autocomplete query against the configured webservice.

Jump to

Keyboard shortcuts

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