Documentation
¶
Index ¶
- Constants
- type APIKeyAuth
- type AuthProvider
- type BasicAuth
- type Client
- func NewClientAPIKey(instanceURL, apiKey string) (*Client, error)
- func NewClientBasicAuth(instanceURL, username, password string) (*Client, error)
- func NewClientOAuth(instanceURL, clientID, clientSecret string) (*Client, error)
- func NewClientOAuthRefresh(instanceURL, clientID, clientSecret, refreshToken string) (*Client, error)
- func (c *Client) GetRateLimiter() *ratelimit.ServiceNowLimiter
- func (c *Client) GetRetryConfig() retry.Config
- func (c *Client) GetTimeout() time.Duration
- func (c *Client) HandleResponse(resp *resty.Response, err error, target interface{}, format string) error
- func (c *Client) RawRequest(method, path string, body interface{}, params map[string]string, ...) error
- func (c *Client) RawRequestWithContext(ctx context.Context, method, path string, body interface{}, ...) error
- func (c *Client) RawRootRequest(method, path string, body interface{}, params map[string]string, ...) error
- func (c *Client) RawRootRequestWithContext(ctx context.Context, method, path string, body interface{}, ...) error
- func (c *Client) SetRateLimitConfig(config ratelimit.ServiceNowLimiterConfig)
- func (c *Client) SetRetryConfig(config retry.Config)
- func (c *Client) SetTimeout(timeout time.Duration)
- type ColumnMetadata
- type DisplayValueOptions
- type ErrorType
- type FileTokenStorage
- type OAuthAuthorizationCode
- type OAuthClientCredentials
- type OAuthToken
- type Response
- type SchemaResponse
- type ServiceNowError
- func IsServiceNowError(err error) (*ServiceNowError, bool)
- func NewAuthenticationError(message string) *ServiceNowError
- func NewRateLimitError(message string) *ServiceNowError
- func NewServiceNowError(statusCode int, message string) *ServiceNowError
- func NewServiceNowErrorWithDetail(statusCode int, message, detail string) *ServiceNowError
- func NewTimeoutError(message string) *ServiceNowError
- func NewValidationError(message string) *ServiceNowError
- type TokenStorage
Constants ¶
const ( FormatJSON = "json" FormatXML = "xml" )
const ( ErrorTypeAuthentication = types.ErrorTypeAuthentication ErrorTypeAuthorization = types.ErrorTypeAuthorization ErrorTypeRateLimit = types.ErrorTypeRateLimit ErrorTypeValidation = types.ErrorTypeValidation ErrorTypeNotFound = types.ErrorTypeNotFound ErrorTypeTimeout = types.ErrorTypeTimeout ErrorTypeNetwork = types.ErrorTypeNetwork ErrorTypeServer = types.ErrorTypeServer ErrorTypeClient = types.ErrorTypeClient ErrorTypeUnknown = types.ErrorTypeUnknown )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyAuth ¶
type APIKeyAuth struct {
// contains filtered or unexported fields
}
APIKeyAuth handles ServiceNow API key authentication
func NewAPIKeyAuth ¶
func NewAPIKeyAuth(apiKey string) *APIKeyAuth
NewAPIKeyAuth creates a new API key authentication provider
func (*APIKeyAuth) Apply ¶
func (a *APIKeyAuth) Apply(client *resty.Client) error
func (*APIKeyAuth) IsExpired ¶
func (a *APIKeyAuth) IsExpired() bool
func (*APIKeyAuth) Refresh ¶
func (a *APIKeyAuth) Refresh() error
type AuthProvider ¶
type AuthProvider interface { Apply(client *resty.Client) error IsExpired() bool Refresh() error // For refreshable auth methods }
AuthProvider defines the interface for authentication methods
type BasicAuth ¶
type BasicAuth struct {
// contains filtered or unexported fields
}
BasicAuth handles username/password authentication
func NewBasicAuth ¶
type Client ¶
type Client struct { InstanceURL string // Root instance URL for non-/api/now endpoints BaseURL string Client *resty.Client Auth AuthProvider // contains filtered or unexported fields }
func NewClientAPIKey ¶
func NewClientBasicAuth ¶
func NewClientOAuth ¶
func NewClientOAuthRefresh ¶
func (*Client) GetRateLimiter ¶
func (c *Client) GetRateLimiter() *ratelimit.ServiceNowLimiter
GetRateLimiter returns the rate limiter for advanced usage
func (*Client) GetRetryConfig ¶
GetRetryConfig returns the current retry configuration
func (*Client) GetTimeout ¶
GetTimeout returns the current request timeout
func (*Client) HandleResponse ¶
func (c *Client) HandleResponse(resp *resty.Response, err error, target interface{}, format string) error
HandleResponse processes API responses with format support
func (*Client) RawRequest ¶
func (c *Client) RawRequest(method, path string, body interface{}, params map[string]string, result interface{}) error
RawRequest allows low-level API calls with auth handling (default JSON)
func (*Client) RawRequestWithContext ¶
func (c *Client) RawRequestWithContext(ctx context.Context, method, path string, body interface{}, params map[string]string, result interface{}) error
RawRequestWithContext allows low-level API calls with context support
func (*Client) RawRootRequest ¶
func (c *Client) RawRootRequest(method, path string, body interface{}, params map[string]string, result interface{}, format string) error
RawRootRequest allows low-level calls to root instance URL (e.g., for .do endpoints) with format
func (*Client) RawRootRequestWithContext ¶
func (c *Client) RawRootRequestWithContext(ctx context.Context, method, path string, body interface{}, params map[string]string, result interface{}, format string) error
RawRootRequestWithContext allows low-level calls to root instance URL with context support
func (*Client) SetRateLimitConfig ¶
func (c *Client) SetRateLimitConfig(config ratelimit.ServiceNowLimiterConfig)
SetRateLimitConfig updates the rate limiting configuration
func (*Client) SetRetryConfig ¶
SetRetryConfig updates the retry configuration
func (*Client) SetTimeout ¶
SetTimeout sets the request timeout for the client
type ColumnMetadata ¶
type ColumnMetadata struct { Name string `json:"name"` Label string `json:"label"` Type string `json:"type"` MaxLength int `json:"max_length,omitempty"` DefaultValue string `json:"default_value,omitempty"` Mandatory bool `json:"mandatory,omitempty"` ReadOnly bool `json:"read_only,omitempty"` Unique bool `json:"unique,omitempty"` Reference string `json:"reference,omitempty"` Choice bool `json:"choice,omitempty"` Calculated bool `json:"calculated,omitempty"` }
ColumnMetadata represents field details from schema
type DisplayValueOptions ¶
type DisplayValueOptions string
const ( DisplayTrue DisplayValueOptions = "true" DisplayFalse DisplayValueOptions = "false" DisplayAll DisplayValueOptions = "all" )
type FileTokenStorage ¶
type FileTokenStorage struct {
// contains filtered or unexported fields
}
FileTokenStorage implements token storage using local files
func NewFileTokenStorage ¶
func NewFileTokenStorage(directory string) *FileTokenStorage
NewFileTokenStorage creates a new file-based token storage
func (*FileTokenStorage) Delete ¶
func (f *FileTokenStorage) Delete(key string) error
func (*FileTokenStorage) Load ¶
func (f *FileTokenStorage) Load(key string) (*OAuthToken, error)
func (*FileTokenStorage) Save ¶
func (f *FileTokenStorage) Save(key string, token *OAuthToken) error
type OAuthAuthorizationCode ¶
type OAuthAuthorizationCode struct {
// contains filtered or unexported fields
}
OAuthAuthorizationCode handles OAuth 2.0 authorization code flow with refresh tokens
func NewOAuthAuthorizationCode ¶
func NewOAuthAuthorizationCode(instanceURL, clientID, clientSecret string, refreshToken string) *OAuthAuthorizationCode
NewOAuthAuthorizationCode creates OAuth authorization code flow auth
func NewOAuthAuthorizationCodeWithStorage ¶
func NewOAuthAuthorizationCodeWithStorage(instanceURL, clientID, clientSecret string, refreshToken string, storage TokenStorage) *OAuthAuthorizationCode
NewOAuthAuthorizationCodeWithStorage creates OAuth authorization code flow with custom storage
func (*OAuthAuthorizationCode) Apply ¶
func (o *OAuthAuthorizationCode) Apply(client *resty.Client) error
OAuth Authorization Code methods
func (*OAuthAuthorizationCode) IsExpired ¶
func (o *OAuthAuthorizationCode) IsExpired() bool
func (*OAuthAuthorizationCode) Refresh ¶
func (o *OAuthAuthorizationCode) Refresh() error
type OAuthClientCredentials ¶
type OAuthClientCredentials struct {
// contains filtered or unexported fields
}
OAuthClientCredentials handles OAuth 2.0 client credentials flow
func NewOAuthClientCredentials ¶
func NewOAuthClientCredentials(instanceURL, clientID, clientSecret string) *OAuthClientCredentials
func NewOAuthClientCredentialsWithStorage ¶
func NewOAuthClientCredentialsWithStorage(instanceURL, clientID, clientSecret string, storage TokenStorage) *OAuthClientCredentials
NewOAuthClientCredentialsWithStorage creates OAuth client credentials with custom storage
func (*OAuthClientCredentials) Apply ¶
func (o *OAuthClientCredentials) Apply(client *resty.Client) error
func (*OAuthClientCredentials) IsExpired ¶
func (o *OAuthClientCredentials) IsExpired() bool
func (*OAuthClientCredentials) Refresh ¶
func (o *OAuthClientCredentials) Refresh() error
type OAuthToken ¶
type OAuthToken struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` ExpiresIn int `json:"expires_in"` RefreshToken string `json:"refresh_token,omitempty"` Scope string `json:"scope"` }
OAuthToken holds OAuth token response data
type Response ¶
type Response struct { Result interface{} `json:"result"` Error string `json:"error,omitempty"` }
Response wraps ServiceNow API responses
type SchemaResponse ¶
type SchemaResponse struct {
Columns []ColumnMetadata `json:"columns"` // Adjust key if response differs (e.g., "fields")
}
SchemaResponse wraps the schema endpoint response
type ServiceNowError ¶
type ServiceNowError struct { Type ErrorType `json:"type"` Message string `json:"message"` Code string `json:"code"` StatusCode int `json:"status_code"` Detail string `json:"detail,omitempty"` Retryable bool `json:"retryable"` }
ServiceNowError represents errors from ServiceNow API
func IsServiceNowError ¶
func IsServiceNowError(err error) (*ServiceNowError, bool)
IsServiceNowError checks if an error is a ServiceNowError
func NewAuthenticationError ¶
func NewAuthenticationError(message string) *ServiceNowError
NewAuthenticationError creates a new authentication error
func NewRateLimitError ¶
func NewRateLimitError(message string) *ServiceNowError
NewRateLimitError creates a new rate limit error
func NewServiceNowError ¶
func NewServiceNowError(statusCode int, message string) *ServiceNowError
NewServiceNowError creates a new ServiceNow error with status code classification
func NewServiceNowErrorWithDetail ¶
func NewServiceNowErrorWithDetail(statusCode int, message, detail string) *ServiceNowError
NewServiceNowErrorWithDetail creates a new ServiceNow error with additional detail
func NewTimeoutError ¶
func NewTimeoutError(message string) *ServiceNowError
NewTimeoutError creates a new timeout error
func NewValidationError ¶
func NewValidationError(message string) *ServiceNowError
NewValidationError creates a new validation error
func (*ServiceNowError) Error ¶
func (e *ServiceNowError) Error() string
func (*ServiceNowError) GetErrorType ¶
func (e *ServiceNowError) GetErrorType() ErrorType
GetErrorType returns the error type (implements RetryableError interface)
func (*ServiceNowError) IsAuthError ¶
func (e *ServiceNowError) IsAuthError() bool
IsAuthError returns whether the error is an authentication error
func (*ServiceNowError) IsRateLimit ¶
func (e *ServiceNowError) IsRateLimit() bool
IsRateLimit returns whether the error is a rate limit error
func (*ServiceNowError) IsRetryable ¶
func (e *ServiceNowError) IsRetryable() bool
IsRetryable returns whether the error is retryable
func (*ServiceNowError) IsTemporary ¶
func (e *ServiceNowError) IsTemporary() bool
IsTemporary returns whether the error is temporary
type TokenStorage ¶
type TokenStorage interface { Save(key string, token *OAuthToken) error Load(key string) (*OAuthToken, error) Delete(key string) error }
TokenStorage defines interface for token persistence