Documentation ¶
Overview ¶
Package rsat provides support for processing APIs hosted by a Red Hat Satellite (RSAT) instance.
See API documentation:
- https://access.redhat.com/documentation/en-us/red_hat_satellite - https://rsat.example.com/apidoc/v2.html
Index ¶
- Constants
- Variables
- type APIAuthInfo
- type APIClient
- type Hypervisor
- type NullString
- type Organization
- type Organizations
- func (orgs Organizations) HasCriticalState() bool
- func (orgs Organizations) HasWarningState() bool
- func (orgs Organizations) IsOKState() bool
- func (orgs Organizations) NumOrgs() int
- func (orgs Organizations) NumPlans() int
- func (orgs Organizations) NumPlansDisabled() int
- func (orgs Organizations) NumPlansEnabled() int
- func (orgs Organizations) NumPlansStuck() int
- func (orgs Organizations) NumProblemPlans() int
- func (orgs Organizations) ServiceState() nagios.ServiceState
- func (orgs Organizations) Sort()
- type OrganizationsResponse
- type PrepError
- type Product
- type Products
- type SortOptions
- type StandardAPITime
- type Subscription
- type SubscriptionsResponse
- type SyncPlan
- type SyncPlanPermissions
- type SyncPlans
- func (sps SyncPlans) Disabled() SyncPlans
- func (sps SyncPlans) Enabled() SyncPlans
- func (sps SyncPlans) IsOKState() bool
- func (sps SyncPlans) NumDisabled() int
- func (sps SyncPlans) NumEnabled() int
- func (sps SyncPlans) NumProblemPlans() int
- func (sps SyncPlans) NumStuck() int
- func (sps SyncPlans) Stuck() SyncPlans
- func (sps SyncPlans) Total() int
- type SyncPlansResponse
- type SyncTime
Constants ¶
const ( // StandardAPITimeLayout is the time layout format as used by the Red Hat // Satellite API for the majority of the date/time properties. // // Examples: // // - "created_at": "2020-12-03 15:05:00 UTC", // - "updated_at": "2020-12-03 15:05:00 UTC", StandardAPITimeLayout string = "2006-01-02 15:04:05 MST" // SyncTimeLayout is the time layout format as used by the Red Hat // Satellite Sync Plans API for the next_sync property. // // Example: "next_sync": "2022/03/28 20:05:00 +0000" // // See also https://rsat.example.com/apidoc/v2/sync_plans/index.html SyncTimeLayout string = "2006/01/02 15:04:05 -0700" )
const ( // OrganizationsAPIEndPointURLTemplate provides a template for a fully // qualified API endpoint URL for retrieving Organizations from a Red Hat // Satellite instance. OrganizationsAPIEndPointURLTemplate string = "https://%s:%d/api/v2/organizations?full_result=1" // SubscriptionsAPIEndPointURLTemplate provides a template for a fully // qualified API endpoint URL for retrieving Subscriptions associated with // a Red Hat Satellite Organization. SubscriptionsAPIEndPointURLTemplate string = "https://%s:%d/katello/api/v2/organizations/%d/subscriptions?full_result=1" // SyncPlansAPIEndPointURLTemplate provides a template for a fully // qualified API endpoint URL for retrieving Sync Plans associated with a // Red Hat Satellite Organization. SyncPlansAPIEndPointURLTemplate string = "https://%s:%d/katello/api/v2/organizations/%d/sync_plans?full_result=1" // ProductsAPIEndPointURLTemplate provides a template for a fully // qualified API endpoint URL for retrieving Products associated with a // Red Hat Satellite Organization. ProductsAPIEndPointURLTemplate string = "https://%s:%d/katello/api/v2/products?organization_id=%d&full_result=1" )
Red Hat Satellite API endpoints URL templates.
const ( PrepTaskParseURL string = "parse URL" PrepTaskPrepareRequest string = "prepare request" PrepTaskDecode string = "decode JSON data" PrepTaskSubmitRequest string = "submit request" PrepTaskValidateResponse string = "validate response" )
Prep tasks for processing of Red Hat Satellite API endpoints.
const JSONNullKeyword string = "null"
JSONNullKeyword is the keyword used in JSON to represent null.
Variables ¶
var ( // ErrMissingValue indicates that an expected value was missing. ErrMissingValue = errors.New("missing expected value") // ErrHTTPResponseOutsideRange indicates that a response was received // which falls outside of an acceptable range. ErrHTTPResponseOutsideRange = errors.New("response is outside acceptable range") // ErrJSONUnexpectedObjectCount indicates that a response was received // with more provided JSON objects than expected. ErrJSONUnexpectedObjectCount = errors.New("unexpected JSON object count") )
FIXME: Should we consistently use the PrepError type instead of using these sentinel errors?
Functions ¶
This section is empty.
Types ¶
type APIAuthInfo ¶
type APIAuthInfo struct { // ReadLimit is the size in bytes used to help prevent abuse when reading // input that could be larger than expected. ReadLimit int64 // Port is the TCP/IP port associated with the Red Hat Satellite server's // API endpoints. Port int // Server is the FQDN or IP Address of the Red Hat Satellite server. Server string // Username is the valid user for the specified Red Hat Satellite server. Username string // Password is the valid password for the specified Red Hat Satellite // Server user account. Password string // UserAgent is an optional custom user agent string used to override the // default Go user agent ("Go-http-client/1.1"). UserAgent string // NetworkType indicates whether an attempt should be made to connect to // only IPv4, only IPv6 or SSH servers listening on either of IPv4 or IPv6 // addresses ("auto"). NetworkType string // CACert is the optional certificate authority certificate used to // validate the certificate chain used by the Red Hat Satellite server. CACert []byte // PermitTLSRenegotiation controls whether the server is allowed to // request TLS renegotiation. PermitTLSRenegotiation bool // TrustCert indicates whether the certificate should be trusted as-is // without validation. TrustCert bool }
APIAuthInfo represents the settings needed to access Red Hat Satellite server API endpoints.
type APIClient ¶
type APIClient struct { *http.Client AuthInfo APIAuthInfo Logger zerolog.Logger }
APIClient represents a customized HTTP client for interacting with Red Hat Satellite API endpoints.
func NewAPIClient ¶
func NewAPIClient(apiAuthInfo APIAuthInfo, logger zerolog.Logger) *APIClient
NewAPIClient uses the provided API Auth details to construct a custom HTTP client used to interact with
type Hypervisor ¶
Hypervisor represents the hypervisor associated with a specific subscription. Not all subscriptions are associated with a hypervisor; subscriptions associated with a hypervisor require that a virtual guest be running on the indicated hypervisor (tracked via virt-who) to be eligible for that subscription (e.g., Red Hat Enterprise Linux Extended Life Cycle Support).
type NullString ¶
type NullString string
NullString represents a string value that may potentially be null in the input JSON feed.
func (NullString) MarshalJSON ¶
func (ns NullString) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface. This compliments the custom Unmarshaler implementation to handle potentially null string field values in place of using an empty interface.
func (*NullString) UnmarshalJSON ¶
func (ns *NullString) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface to handle potentially null string field values in place of using an empty interface.
type Organization ¶
type Organization struct { CreatedAt StandardAPITime `json:"created_at"` UpdatedAt StandardAPITime `json:"updated_at"` Description NullString `json:"description"` Label string `json:"label"` Name string `json:"name"` Title string `json:"title"` SyncPlans SyncPlans `json:"-"` // Products Products `json:"-"` // Hosts Hosts `json:"-"` ID int `json:"id"` }
Organization is an isolated collection of systems, content, and other functionality within a Red Hat Satellite deployment.
func GetOrganizations ¶
func GetOrganizations(ctx context.Context, client *APIClient) ([]Organization, error)
GetOrganizations uses the given client to retrieve all Red Hat Satellite organizations.
type Organizations ¶
type Organizations []Organization
Organizations is a collection of Red Hat Satellite organizations.
func GetOrgsWithSyncPlans ¶
func GetOrgsWithSyncPlans(ctx context.Context, client *APIClient) (Organizations, error)
GetOrgsWithSyncPlans uses the provided API client to retrieve all Red Hat Satellite organizations along with their sync plans.
func (Organizations) HasCriticalState ¶
func (orgs Organizations) HasCriticalState() bool
HasCriticalState indicates whether any items in the collection were evaluated to a CRITICAL state.
func (Organizations) HasWarningState ¶
func (orgs Organizations) HasWarningState() bool
HasWarningState indicates whether any items in the collection were evaluated to a WARNING state.
func (Organizations) IsOKState ¶
func (orgs Organizations) IsOKState() bool
IsOKState indicates whether all items in the collection were evaluated to an OK state.
func (Organizations) NumOrgs ¶
func (orgs Organizations) NumOrgs() int
NumOrgs returns the number of organizations in the collection.
func (Organizations) NumPlans ¶
func (orgs Organizations) NumPlans() int
NumPlans returns the number of sync plans for all organizations in the collection.
func (Organizations) NumPlansDisabled ¶
func (orgs Organizations) NumPlansDisabled() int
NumPlansDisabled returns the total number of sync plans for all organizations in the collection with disabled state.
func (Organizations) NumPlansEnabled ¶
func (orgs Organizations) NumPlansEnabled() int
NumPlansEnabled returns the total number of sync plans for all organizations in the collection with enabled state.
func (Organizations) NumPlansStuck ¶
func (orgs Organizations) NumPlansStuck() int
NumPlansStuck returns the total number of sync plans for all organizations in the collection with Next Sync state set to past date/time.
func (Organizations) NumProblemPlans ¶
func (orgs Organizations) NumProblemPlans() int
NumProblemPlans returns the total number of sync plans for all organizations in the collection with a non-OK state.
func (Organizations) ServiceState ¶
func (orgs Organizations) ServiceState() nagios.ServiceState
ServiceState returns the appropriate Service Check Status label and exit code for the collection's evaluation results.
func (Organizations) Sort ¶
func (orgs Organizations) Sort()
Sort sorts the Organizations in the collection by name.
type OrganizationsResponse ¶
type OrganizationsResponse struct { Organizations []Organization `json:"results"` Search NullString `json:"search"` Sort SortOptions `json:"sort"` Subtotal int `json:"subtotal"` Total int `json:"total"` Page int `json:"page"` PerPage int `json:"per_page"` }
OrganizationsResponse represents the API response from a request for all organizations in the Red Hat Satellite server.
type PrepError ¶
type PrepError struct { // Step indicates the specific prep task which failed. // // NOTE: Constants should be used to make comparisons more reliable. Task string // Message provides additional (brief) context describing why the error // occurred. // // e.g., "error parsing URL" or "error preparing request for URL" Message string // Source associated with the prep task. // // e.g., // "https://rsat.example.com/katello/api/v2/organizations/27/subscriptions" Source string // Cause is the underlying error which occurred while performing a task as // part of preparing a components set. This error is "bundled" for later // evaluation. Cause error }
PrepError represents a class of errors encountered while performing tasks related to preparing a components Set.
func (*PrepError) Error ¶
Error provides a human readable explanation for a components Set preparation task failure.
type Product ¶
type Product struct { LastSync StandardAPITime `json:"last_sync"` Description NullString `json:"description"` CpID string `json:"cp_id"` Label string `json:"label"` LastSyncText string `json:"last_sync_words"` Name string `json:"name"` SyncState string `json:"sync_state"` ID int `json:"id"` RepositoryCount int `json:"repository_count"` }
Product is a collection of content repositories used to group custom repositories.
type Products ¶
type Products []Product
Products is a collection of product values associated with a Red Hat Satellite sync plan.
type SortOptions ¶
type SortOptions struct { By NullString `json:"by"` Order NullString `json:"order"` }
SortOptions is the optional sorting criteria for API query responses.
type StandardAPITime ¶
StandardAPITime is time value as represented in the Red Hat Satellite API for the majority of the date/time properties. It uses the StandardAPITimeLayout format.
func (StandardAPITime) Format ¶
func (dt StandardAPITime) Format(layout string) string
Format calls (time.Time).Format as a convenience for the caller.
func (StandardAPITime) MarshalJSON ¶
func (dt StandardAPITime) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface. This compliments the custom Unmarshaler implementation to handle conversion of a native Go time.Time format to the JSON API expectations of a time value in the StandardAPITimeLayout format.
func (StandardAPITime) String ¶
func (dt StandardAPITime) String() string
String implements the fmt.Stringer interface as a convenience method.
func (*StandardAPITime) UnmarshalJSON ¶
func (dt *StandardAPITime) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface to handle converting a time string from the JSON API (most time properties) to a native Go time.Time value using the StandardAPITimeLayout format.
type Subscription ¶
type Subscription struct { Hypervisor Hypervisor `json:"hypervisor,omitempty"` StartDate StandardAPITime `json:"start_date"` EndDate StandardAPITime `json:"end_date"` Cores interface{} `json:"cores"` // null is the only value I've encountered MultiEntitlement *bool `json:"multi_entitlement"` // null or true/false AccountNumber *int `json:"account_number"` // null or integer Available int `json:"available"` Consumed int `json:"consumed"` Quantity int `json:"quantity"` SubscriptionID int `json:"subscription_id"` ID int `json:"id"` InstanceMultiplier int `json:"instance_multiplier"` RAM NullString `json:"ram"` Sockets NullString `json:"sockets"` StackingID NullString `json:"stacking_id"` SupportLevel NullString `json:"support_level"` UpstreamPoolID NullString `json:"upstream_pool_id"` CpID string `json:"cp_id"` Name string `json:"name"` ProductID string `json:"product_id"` ProductName string `json:"product_name"` Type string `json:"type"` UnmappedGuest bool `json:"unmapped_guest"` Upstream bool `json:"upstream"` VirtOnly bool `json:"virt_only"` VirtWho bool `json:"virt_who"` }
Subscription represents an entitlement for receiving content and service from Red Hat. Subscription allocations are applied/managed separately within each Red Hat Satellite organization.
type SubscriptionsResponse ¶
type SubscriptionsResponse struct { Error NullString `json:"error"` Organization struct{} `json:"organization"` // I have only encountered: "organization": {}, Page int `json:"page"` PerPage int `json:"per_page"` Subscriptions []Subscription `json:"results"` Search NullString `json:"search"` Sort SortOptions `json:"sort"` Subtotal int `json:"subtotal"` Total int `json:"total"` }
SubscriptionsResponse represents the API response from a request of all subscriptions for a specific organization.
type SyncPlan ¶
type SyncPlan struct { OriginalSyncDate SyncTime `json:"sync_date"` NextSync SyncTime `json:"next_sync"` UpdatedAt StandardAPITime `json:"updated_at"` CreatedAt StandardAPITime `json:"created_at"` Products Products `json:"products"` CronExpression NullString `json:"cron_expression"` Description NullString `json:"description"` Interval string `json:"interval"` Name string `json:"name"` OrganizationName string `json:"-"` OrganizationLabel string `json:"-"` OrganizationTitle string `json:"-"` RecurringLogicID int `json:"foreman_tasks_recurring_logic_id"` ID int `json:"id"` OrganizationID int `json:"organization_id"` Permissions SyncPlanPermissions `json:"permissions"` Enabled bool `json:"enabled"` }
SyncPlan represents a Red Hat Satellite sync plan. Sync plans are used to schedule execution of content synchronization.
func (SyncPlan) DaysStuck ¶
DaysStuck indicates how many days the sync plan has been in a "stuck" state.
func (SyncPlan) DaysStuckHR ¶
DaysStuckHR provides a human readable indication of how many days in the past the sync plan has been in a "stuck" state.
func (SyncPlan) IsOKState ¶
IsOKState indicates whether any problems have been identified with this sync plan.
func (SyncPlan) IsStuck ¶
IsStuck indicates whether (after any applied grace time) the sync plan is considered to be in a "stuck" state (Next Sync state set to past date/time).
Grace time is applied to help prevent flagging a sync plan that is "spinning up" or in a temporary pending status (e.g., on a busy system) as problematic.
NOTE: Very busy systems keeping sync plans in a pending state for an extended duration are still likely to be flagged as non-OK by current logic.
func (SyncPlan) NextSyncTime ¶
NextSyncTime provides a display friendly version of the next scheduled sync time for the sync plan.
type SyncPlanPermissions ¶
type SyncPlanPermissions struct { DestroySyncPlans bool `json:"destroy_sync_plans"` EditSyncPlans bool `json:"edit_sync_plans"` ViewSyncPlans bool `json:"view_sync_plans"` }
SyncPlanPermissions is the collection of permissions that a user querying the Red Hat Satellite API has for interacting with sync plans.
type SyncPlans ¶
type SyncPlans []SyncPlan
SyncPlans is a collection of Red Hat Satellite sync plans.
func GetSyncPlans ¶
GetSyncPlans uses the provided APIClient to retrieve all sync plans for each specified Red Hat Satellite organization. If no organizations are specified then an attempt will be made to retrieve sync plans from all RSAT organizations.
func (SyncPlans) Disabled ¶
Disabled returns a new collection containing all sync plans from the original collection which are not in an enabled state.
func (SyncPlans) Enabled ¶
Enabled returns a new collection containing all sync plans from the original collection which are in an enabled state.
func (SyncPlans) IsOKState ¶
IsOKState indicates whether any problems have been identified with the sync plans in this collection.
func (SyncPlans) NumDisabled ¶
NumDisabled provides the number of sync plans in the collection in a disabled state.
func (SyncPlans) NumEnabled ¶
NumEnabled provides the number of sync plans in the collection in an enabled state.
func (SyncPlans) NumProblemPlans ¶
NumProblemPlans returns the total number of sync plans with a non-OK state.
func (SyncPlans) NumStuck ¶
NumStuck indicates the number of sync plans in the collection are in a "stuck" state.
type SyncPlansResponse ¶
type SyncPlansResponse struct { Error NullString `json:"error"` Search NullString `json:"search"` SyncPlans SyncPlans `json:"results"` Sort SortOptions `json:"sort"` Subtotal int `json:"subtotal"` Total int `json:"total"` Page int `json:"page"` PerPage int `json:"per_page"` }
SyncPlansResponse represents the API response from a request of all sync plans for a specific organization.
type SyncTime ¶
SyncTime is time value as represented in the Red Hat Satellite Sync Plans API for the next_sync and sync_date properties. It uses the SyncTimeLayout format.
func (SyncTime) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. This compliments the custom Unmarshaler implementation to handle conversion of a native Go time.Time format to the JSON API expectations of a time value in the SyncTimeLayout format.
func (*SyncTime) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface to handle converting a time string from the next_sync property in the JSON API to a native Go time.Time value using the SyncTimeLayout format.