Documentation
¶
Overview ¶
Package remedy provides a Go client for the BMC Remedy AR System REST API.
The client handles authentication, request serialization (to avoid session conflicts), rate limiting, and provides a type-safe interface for interacting with Remedy forms and entries.
Basic usage:
client := remedy.New("https://remedy.example.com:8443",
remedy.WithTimeout(30*time.Second),
remedy.WithRateLimit(10), // 10 requests/second
)
err := client.Login(ctx, "username", "password")
if err != nil {
log.Fatal(err)
}
defer client.Logout(ctx)
entries, err := client.Entries().List(ctx, "HPD:Help Desk",
remedy.WithQualification("'Status' = \"Open\""),
remedy.WithLimit(100),
)
Index ¶
- Constants
- Variables
- type APIError
- type AttachmentServicer
- type Client
- func (c *Client) Attachments() AttachmentServicer
- func (c *Client) ClearCredentials()
- func (c *Client) Close()
- func (c *Client) Entries() EntryServicer
- func (c *Client) IsAuthenticated() bool
- func (c *Client) Login(ctx context.Context, username, password string) error
- func (c *Client) LoginWithAuth(ctx context.Context, username, password, authString string) error
- func (c *Client) Logout(ctx context.Context) error
- type DeleteOption
- type Entry
- type EntryList
- type EntryServicer
- type Field
- type HTTPDoer
- type Link
- type Option
- type Query
- func (q *Query) And(field, op string, value any) *Query
- func (q *Query) AndSafe(field, op string, value any) *Query
- func (q *Query) Build() string
- func (q *Query) BuildSafe() (string, error)
- func (q *Query) Or(field, op string, value any) *Query
- func (q *Query) OrSafe(field, op string, value any) *Query
- func (q *Query) Raw(qualification string) *Query
- type QueryOption
- type RemedyClient
- type SortOrder
Constants ¶
const ( OpEqual = "=" OpNotEqual = "!=" OpLessThan = "<" OpLessEqual = "<=" OpGreaterThan = ">" OpGreaterEqual = ">=" OpLike = "LIKE" )
Common operators for convenience.
Variables ¶
var ( ErrUnauthorized = errors.New("remedy: unauthorized") // ErrForbidden indicates the user lacks permission (HTTP 403). ErrForbidden = errors.New("remedy: forbidden") // ErrNotFound indicates the requested resource does not exist (HTTP 404). ErrNotFound = errors.New("remedy: not found") // ErrNotAuthenticated indicates no valid token is available. ErrNotAuthenticated = errors.New("remedy: not authenticated") // ErrNoCredentials indicates credentials are not stored for automatic token refresh. ErrNoCredentials = errors.New("remedy: no credentials stored for token refresh") // ErrEmptyFormName indicates a form name parameter was empty. ErrEmptyFormName = errors.New("remedy: form name cannot be empty") // ErrEmptyEntryID indicates an entry ID parameter was empty. ErrEmptyEntryID = errors.New("remedy: entry ID cannot be empty") )
Sentinel errors for common API error conditions.
var ErrTokenTooLarge = errors.New("remedy: token too large")
ErrTokenTooLarge is returned when a token response exceeds maxTokenSize.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// StatusCode is the HTTP status code of the response.
StatusCode int
// MessageType indicates the severity: ERROR, WARNING, FATAL, BAD STATUS.
MessageType string
// MessageText is the primary error description.
MessageText string
// MessageAppendedText provides additional context for the error.
MessageAppendedText string
// MessageNumber is the numeric error identifier.
MessageNumber int
}
APIError represents an error returned by the BMC Remedy REST API. It contains the structured error information from the API response.
type AttachmentServicer ¶
type AttachmentServicer interface {
// Get retrieves an attachment from an entry.
Get(ctx context.Context, form, entryID, fieldName string) (io.ReadCloser, error)
// Upload uploads an attachment to an entry.
Upload(ctx context.Context, form, entryID, fieldName, filename string, data io.Reader) error
}
AttachmentServicer defines attachment operations for the Remedy API. This interface enables mocking the attachment service in tests.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a BMC Remedy REST API client. It handles authentication, request serialization, and rate limiting.
TODO(go1.26): Consider using runtime/secret package for token storage when Go 1.26 is available. See: https://go.dev/doc/go1.26#new-experimental-runtimesecret-package
func (*Client) Attachments ¶
func (c *Client) Attachments() AttachmentServicer
Attachments returns the attachment service for file operations.
func (*Client) ClearCredentials ¶
func (c *Client) ClearCredentials()
ClearCredentials removes stored credentials from memory. After calling this, automatic token refresh will be disabled.
func (*Client) Close ¶
func (c *Client) Close()
Close releases resources associated with the client.
func (*Client) Entries ¶
func (c *Client) Entries() EntryServicer
Entries returns the entry service for CRUD operations on form entries.
func (*Client) IsAuthenticated ¶
IsAuthenticated returns true if the client has a valid token. Note: This only checks if a token exists, not if it's still valid.
func (*Client) Login ¶
Login authenticates with the Remedy server using username and password. The JWT token is stored internally and used for subsequent requests. Credentials are stored for automatic token refresh.
func (*Client) LoginWithAuth ¶
LoginWithAuth authenticates with an additional authentication string. This is used for servers that require additional authentication context. Credentials are stored for automatic token refresh.
type DeleteOption ¶
type DeleteOption string
DeleteOption defines options for delete operations.
const ( // DeleteOptionNone performs a standard delete. DeleteOptionNone DeleteOption = "NONE" // DeleteOptionForce forces deletion even if entry is locked. DeleteOptionForce DeleteOption = "FORCE" // DeleteOptionNoCascade prevents cascade delete of related entries. DeleteOptionNoCascade DeleteOption = "NOCASCADE" )
type EntryServicer ¶
type EntryServicer interface {
// Get retrieves a single entry by ID.
Get(ctx context.Context, form, entryID string, opts ...QueryOption) (*Entry, error)
// List retrieves multiple entries with optional filtering and pagination.
List(ctx context.Context, form string, opts ...QueryOption) (*EntryList, error)
// Create creates a new entry in the specified form.
Create(ctx context.Context, form string, values map[string]any) (*Entry, error)
// Update updates an existing entry.
Update(ctx context.Context, form, entryID string, values map[string]any) error
// Delete removes an entry.
Delete(ctx context.Context, form, entryID string, opts ...DeleteOption) error
// Merge creates or updates an entry based on matching criteria.
Merge(ctx context.Context, form string, values map[string]any) (*Entry, error)
}
EntryServicer defines entry operations for the Remedy API. This interface enables mocking the entry service in tests.
type Field ¶
type Field struct {
ID int `json:"fieldId"`
Name string `json:"fieldName"`
DataType string `json:"dataType"`
}
Field represents metadata about a form field.
type HTTPDoer ¶
HTTPDoer abstracts the HTTP client for testing. *http.Client implements this interface.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithAutoRefresh ¶
WithAutoRefresh enables or disables automatic token refresh. When enabled (default), the client will automatically re-authenticate using stored credentials when the token is near expiry.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client for the Remedy client. This allows customizing transport, timeouts, and other HTTP settings. The client must implement the HTTPDoer interface (e.g., *http.Client).
func WithRateLimit ¶
WithRateLimit enables rate limiting with the specified requests per second. This helps prevent overwhelming the Remedy server.
func WithRefreshThreshold ¶
WithRefreshThreshold sets how long before expiry to refresh the token. The default is 5 minutes before expiry.
func WithTimeout ¶
WithTimeout sets the timeout for individual API requests. The default is 30 seconds.
func WithTokenLifetime ¶
WithTokenLifetime sets how long tokens are considered valid. The default is 1 hour, matching BMC Remedy's standard token lifetime.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query builds AR System qualification strings in a type-safe manner.
Example usage:
q := remedy.NewQuery().
And("Status", "=", "Open").
And("Priority", "<", 3).
Build()
// Result: 'Status' = "Open" AND 'Priority' < 3
func (*Query) AndSafe ¶
AndSafe adds a condition with AND conjunction, validating the operator. If the operator is invalid, the error is stored and returned by BuildSafe.
func (*Query) BuildSafe ¶
BuildSafe returns the qualification string and any validation errors. Use this with AndSafe/OrSafe for validated query building.
type QueryOption ¶
type QueryOption func(*queryOptions)
QueryOption configures entry query operations.
func WithExpand ¶
func WithExpand(associations ...string) QueryOption
WithExpand specifies associations to expand in the response.
func WithFields ¶
func WithFields(fields ...string) QueryOption
WithFields specifies which fields to return in the response.
func WithLimit ¶
func WithLimit(limit int) QueryOption
WithLimit sets the maximum number of entries to return.
func WithOffset ¶
func WithOffset(offset int) QueryOption
WithOffset sets the starting offset for pagination.
func WithQualification ¶
func WithQualification(q string) QueryOption
WithQualification sets the AR qualification string for filtering entries.
func WithSort ¶
func WithSort(field string, order SortOrder) QueryOption
WithSort sets the field and order for sorting results.
type RemedyClient ¶
type RemedyClient interface {
// Login authenticates with the Remedy server.
Login(ctx context.Context, username, password string) error
// LoginWithAuth authenticates with additional auth string.
LoginWithAuth(ctx context.Context, username, password, authString string) error
// Logout terminates the current session.
Logout(ctx context.Context) error
// Entries returns the entry service.
Entries() EntryServicer
// Attachments returns the attachment service.
Attachments() AttachmentServicer
}
RemedyClient defines the full client interface for the Remedy API. This interface enables mocking the entire client in consumer tests.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
queue
Package queue provides request serialization for BMC Remedy API clients.
|
Package queue provides request serialization for BMC Remedy API clients. |
|
ratelimit
Package ratelimit provides a token bucket rate limiter for API requests.
|
Package ratelimit provides a token bucket rate limiter for API requests. |