rhsm2

package module
v0.0.0-...-1f424de Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: GPL-3.0 Imports: 28 Imported by: 0

README

RHSM2

This project contains Go package allowing to write RHSM2 clients.

Ho to build the package

Just type:

go build

Documentation

Index

Constants

View Source
const DefaultDnfVarsDirPath = "/etc/dnf/vars/"
View Source
const DefaultDnfVarsReleaseFilePath = DefaultDnfVarsDirPath + "releasever"
View Source
const DefaultOsReleaseFilePath = "/etc/os-release"
View Source
const DefaultRHSMConfFilePath = "/etc/rhsm/rhsm.conf"
View Source
const DefaultRepoFilePath = "/etc/yum.repos.d/redhat.repo"
View Source
const DefaultSystemPurposeFilePath = "/etc/rhsm/syspurpose/syspurpose.json"
View Source
const DirectoryDefaultProductCertificate = "/etc/pki/product-default"

DirectoryDefaultProductCertificate is directory containing default product certificate. This certificate is pre-installed on the system. The path cannot be altered in configuration file rhsm.conf

View Source
const RedhatOidNamespace = "1.3.6.1.4.1.2312.9"

Variables

This section is empty.

Functions

func IsDefaultValue

func IsDefaultValue(value *reflect.Value, defaultValue *string) (bool, error)

IsDefaultValue tries to say if given value is default value or not

func IsValueAllowed

func IsValueAllowed(value *reflect.Value, allowedValues *string) (bool, error)

IsValueAllowed tries to say if given value is allowed or not. The allowedValues is string with comma separated values

Types

type AuthType

type AuthType int

AuthType is type used for specifying authentication type of connection

const (
	// NoAuth does not require any authentication. It can use base64 encoded
	// username:password in HTTP header for authentication of client
	NoAuth AuthType = iota

	// ConsumerCertAuth uses consumer certificate for client authentication
	ConsumerCertAuth

	// EntitlementCertAuth uses entitlement certificate for client authentication
	EntitlementCertAuth
)

Constants of authentication types

type ConsumerData

type ConsumerData struct {
	Created             string        `json:"created"`
	Updated             string        `json:"updated"`
	Id                  string        `json:"id"`
	Uuid                string        `json:"uuid"`
	Name                string        `json:"name"`
	Username            string        `json:"username"`
	EntitlementStatus   string        `json:"entitlementStatus"`
	ServiceLevel        string        `json:"serviceLevel"`
	Role                string        `json:"role"`
	Usage               string        `json:"usage"`
	AddOns              []interface{} `json:"addOns"`
	SystemPurposeStatus string        `json:"systemPurposeStatus"`
	ReleaseVer          struct {
		ReleaseVer interface{} `json:"releaseVer"`
	} `json:"releaseVer"`
	Owner struct {
		Id                string `json:"id"`
		Key               string `json:"key"`
		DisplayName       string `json:"displayName"`
		Href              string `json:"href"`
		ContentAccessMode string `json:"contentAccessMode"`
	} `json:"owner"`
	Environment struct {
		Created            interface{} `json:"created"`
		Updated            interface{} `json:"updated"`
		Id                 interface{} `json:"id"`
		Name               string      `json:"name"`
		Type               interface{} `json:"type"`
		Description        interface{} `json:"description"`
		ContentPrefix      interface{} `json:"contentPrefix"`
		Owner              interface{} `json:"owner"`
		EnvironmentContent interface{} `json:"environmentContent"`
	} `json:"environment"`
	EntitlementCount int `json:"entitlementCount"`
	Facts            struct {
	} `json:"facts"`
	LastCheckin       interface{} `json:"lastCheckin"`
	InstalledProducts interface{} `json:"installedProducts"`
	CanActivate       bool        `json:"canActivate"`
	Capabilities      interface{} `json:"capabilities"`
	HypervisorId      interface{} `json:"hypervisorId"`
	ContentTags       interface{} `json:"contentTags"`
	Autoheal          bool        `json:"autoheal"`
	Annotations       interface{} `json:"annotations"`
	ContentAccessMode interface{} `json:"contentAccessMode"`
	Type              struct {
		Created  interface{} `json:"created"`
		Updated  interface{} `json:"updated"`
		Id       string      `json:"id"`
		Label    string      `json:"label"`
		Manifest bool        `json:"manifest"`
	} `json:"type"`
	IdCert struct {
		Created string `json:"created"`
		Updated string `json:"updated"`
		Id      string `json:"id"`
		Key     string `json:"key"`
		Cert    string `json:"cert"`
		Serial  struct {
			Created    string `json:"created"`
			Updated    string `json:"updated"`
			Id         int64  `json:"id"`
			Serial     int64  `json:"serial"`
			Expiration string `json:"expiration"`
			Revoked    bool   `json:"revoked"`
		} `json:"serial"`
	} `json:"idCert"`
	GuestIds       []interface{} `json:"guestIds"`
	Href           string        `json:"href"`
	ActivationKeys []interface{} `json:"activationKeys"`
	ServiceType    interface{}   `json:"serviceType"`
	Environments   []struct {
		Created       string      `json:"created"`
		Updated       string      `json:"updated"`
		Id            string      `json:"id"`
		Name          string      `json:"name"`
		Type          interface{} `json:"type"`
		Description   string      `json:"description"`
		ContentPrefix interface{} `json:"contentPrefix"`
		Owner         struct {
			Id                string `json:"id"`
			Key               string `json:"key"`
			DisplayName       string `json:"displayName"`
			Href              string `json:"href"`
			ContentAccessMode string `json:"contentAccessMode"`
		} `json:"owner"`
		EnvironmentContent []interface{} `json:"environmentContent"`
	} `json:"environments"`
}

ConsumerData is structure used for parsing JSON data returned during registration when system was successfully registered and consumer was created

type Content

type Content struct {
	Id             string   `json:"id"`
	Type           string   `json:"type"`
	Name           string   `json:"name" ini:"name"`
	Label          string   `json:"label"`
	Vendor         string   `json:"vendor"`
	Path           string   `json:"path"`
	Enabled        *bool    `json:"enabled"` // nil means that enabled was not set in JSON
	Arches         []string `json:"arches"`
	GpgUrl         string   `json:"gpg_url,omitempty"`
	MetadataExpire int      `json:"metadata_expire,omitempty" ini:"metadata_expire,omitempty"`
	RequiredTags   []string `json:"required_tags,omitempty"`
}

Content is a structure containing information about one content. This structure is unmarshalled from the entitlement certificate

type ContentOverride

type ContentOverride struct {
	Created      string `json:"created"`
	Updated      string `json:"updated"`
	Name         string `json:"name"`
	ContentLabel string `json:"contentLabel"`
	Value        string `json:"value"`
}

ContentOverride is a structure containing information about content override for a given repository

type ContentOverridesResult

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

ContentOverridesResult is structure used in enableContent function

type EngineeringProduct

type EngineeringProduct struct {
	Id            string        `json:"id"`
	Name          string        `json:"name"`
	Version       string        `json:"version"`
	Architectures []interface{} `json:"architectures"`
	Content       []Content     `json:"content"`
}

EngineeringProduct is structure containing information about one engineering product. This structure is unmarshalled from entitlement certificate

type EntCertKeysResult

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

EntCertKeysResult is structure used in enableContent function

type EntitlementCertificateKey

type EntitlementCertificateKey struct {
	KeyPath  *string
	CertPath *string
}

type EntitlementCertificateKeyJSON

type EntitlementCertificateKeyJSON struct {
	Created string `json:"created"`
	Updated string `json:"updated"`
	Id      string `json:"id"`
	Key     string `json:"key"`
	Cert    string `json:"cert"`
	Serial  struct {
		Created    string `json:"created"`
		Updated    string `json:"updated"`
		Id         int64  `json:"id"`
		Serial     int64  `json:"serial"`
		Expiration string `json:"expiration"`
		Revoked    bool   `json:"revoked"`
	} `json:"serial"`
}

EntitlementCertificateKeyJSON is structure used for un-marshaling of JSON returned from candlepin server. JSON document includes list of this objects

type EntitlementContentJSON

type EntitlementContentJSON struct {
	Consumer     string `json:"consumer"`
	Subscription struct {
		Sku  string `json:"sku"`
		Name string `json:"name"`
	} `json:"subscription"`
	Order struct {
		Start time.Time `json:"start"`
		End   time.Time `json:"end"`
	} `json:"order"`
	Products []EngineeringProduct `json:"products"`
	Pool     struct {
	} `json:"pool"`
}

EntitlementContentJSON is structure containing information about content (decoded from entitlement certificate)

type Environment

type Environment struct {
	Created       string      `json:"created,omitempty"`
	Updated       string      `json:"updated,omitempty"`
	Id            string      `json:"id"`
	Name          string      `json:"name,omitempty"`
	Type          interface{} `json:"type,omitempty"`
	Description   string      `json:"description,omitempty"`
	ContentPrefix interface{} `json:"contentPrefix,omitempty"`
	Owner         *struct {
		Id                string `json:"id"`
		Key               string `json:"key,omitempty"`
		DisplayName       string `json:"displayName,omitempty"`
		Href              string `json:"href,omitempty"`
		ContentAccessMode string `json:"contentAccessMode,omitempty"`
	} `json:"owner,omitempty"`
	EnvironmentContent []interface{} `json:"environmentContent,omitempty"`
}

Environment contains information about environment returned form candlepin server. The Owner is pointer on structure, because this structure is also used during registration and only ID of environment is really necessary

type InstalledProduct

type InstalledProduct struct {
	// Following attributes are sent in the report.
	Id           string `json:"productId"`
	Name         string `json:"productName"`
	Version      string `json:"version"`
	Architecture string `json:"arch"`
	// contains filtered or unexported fields
}

InstalledProduct is product certificate installed to /etc/pki/product or /etc/pki/product-default. DNF plugin installs product certificates to /etc/pki/product and there is typically one pre-installed product certificate in /etc/pki/product-default, when pre-installed operating system is part of some product (Red Hat Enterprise Linux)

type OSRelease

type OSRelease struct {
	ID           string
	VersionID    string
	VersionMajor string
	VersionMinor string
}

type OrganizationData

type OrganizationData struct {
	Created                    string      `json:"created"`
	Updated                    string      `json:"updated"`
	Id                         string      `json:"id"`
	DisplayName                string      `json:"displayName"`
	Key                        string      `json:"key"`
	ContentPrefix              interface{} `json:"contentPrefix"`
	DefaultServiceLevel        interface{} `json:"defaultServiceLevel"`
	LogLevel                   interface{} `json:"logLevel"`
	ContentAccessMode          string      `json:"contentAccessMode"`
	ContentAccessModeList      string      `json:"contentAccessModeList"`
	AutobindHypervisorDisabled bool        `json:"autobindHypervisorDisabled"`
	AutobindDisabled           bool        `json:"autobindDisabled"`
	LastRefreshed              string      `json:"lastRefreshed"`
	ParentOwner                interface{} `json:"parentOwner"`
	UpstreamConsumer           interface{} `json:"upstreamConsumer"`
	Anonymous                  interface{} `json:"anonymous"`
	Claimed                    interface{} `json:"claimed"`
}

OrganizationData is structure used for parsing JSON document returned by candlepin. This structure represents one organization

type RHSMClient

type RHSMClient struct {
	UserAgent *UserAgentInfo
	RHSMConf  *RHSMConf
	// contains filtered or unexported fields
}

RHSMClient contains information about client. It can hold up to 3 different type of connections, but usually it is necessary to use only consumerCertAuthConnection. The noAuthConnection is used only during registration process, when no consumer certificate/key is installed. Note: we do not create special connection for "Base Auth", because it is actually noAuthConnection with special HTTP header. entitlementCertAuthConnection could be used for communication with CDN.

func GetRHSMClient

func GetRHSMClient(appName *string, confFilePath *string) (*RHSMClient, error)

GetRHSMClient tries to return the instance of RHSMClient. If the instance already exists, then the existing instance is returned. The confFilePath is used only in the first call of the function. It is just ignored in any other next call.

func (*RHSMClient) Clean

func (rhsmClient *RHSMClient) Clean() error

Clean tries to clean all installed files, but do not try to remove consumer object from candlepin server

func (*RHSMClient) GetCdnReleases

func (rhsmClient *RHSMClient) GetCdnReleases(metadata *RequestMetadata) (map[string]struct{}, error)

GetCdnReleases tries to get the list of available releases from CDN. The list of releases should include only unique values of releases. There should not be any duplicates.

func (*RHSMClient) GetConsumerUUID

func (rhsmClient *RHSMClient) GetConsumerUUID() (*string, error)

GetConsumerUUID tries to get consumer UUID from installed consumer certificate

func (*RHSMClient) GetDnfVarsRelease

func (rhsmClient *RHSMClient) GetDnfVarsRelease() (string, error)

GetDnfVarsRelease tries to get the release from the host in the variable file /etc/dnf/vars/releasever. If the file does not exist, it returns an empty string and error.

func (*RHSMClient) GetEnvironments

func (rhsmClient *RHSMClient) GetEnvironments(
	username string,
	password string,
	organization string,
	metadata *RequestMetadata,
) ([]Environment, error)

GetEnvironments tries to get list of environments from candlepin server

func (*RHSMClient) GetOrgs

func (rhsmClient *RHSMClient) GetOrgs(
	username string,
	password string,
	metadata *RequestMetadata,
) ([]OrganizationData, error)

GetOrgs tries to get list of available organizations for given username

func (*RHSMClient) GetOwner

func (rhsmClient *RHSMClient) GetOwner() (*string, error)

GetOwner tries to get owner from installed consumer certificate

func (*RHSMClient) GetReleaseFromServer

func (rhsmClient *RHSMClient) GetReleaseFromServer(metadata *RequestMetadata) (string, error)

GetReleaseFromServer tries to get the latest release from the candlepin server.

func (*RHSMClient) GetServerEndpoints

func (rhsmClient *RHSMClient) GetServerEndpoints(metadata *RequestMetadata) (*[]RHSMEndPoints, error)

GetServerEndpoints tries to get list of supported server endpoints

func (*RHSMClient) GetServerStatus

func (rhsmClient *RHSMClient) GetServerStatus(metadata *RequestMetadata) (*RHSMStatus, error)

GetServerStatus tries to get status from the server. This method is possible to call, when server is connected or not

func (*RHSMClient) RegisterOrgActivationKeys

func (rhsmClient *RHSMClient) RegisterOrgActivationKeys(
	org *string,
	activationKeys []string,
	options *map[string]string,
	metadata *RequestMetadata,
) (*ConsumerData, error)

RegisterOrgActivationKeys tries to register system using organization id and activation keys

func (*RHSMClient) RegisterUsernamePassword

func (rhsmClient *RHSMClient) RegisterUsernamePassword(
	username *string,
	password *string,
	options *map[string]string,
	metadata *RequestMetadata,
) (*ConsumerData, error)

RegisterUsernamePassword tries to register system using username and password

func (*RHSMClient) SetRelease

func (rhsmClient *RHSMClient) SetRelease(release string) error

SetRelease tries to set the release on the host in the variable file /etc/dnf/vars/releasever. It also tries to set the release on the candlepin server. The set release on the server is done asynchronously.

func (*RHSMClient) Unregister

func (rhsmClient *RHSMClient) Unregister(metadata *RequestMetadata) error

Unregister tries to unregister system

func (*RHSMClient) UnsetRelease

func (rhsmClient *RHSMClient) UnsetRelease() error

UnsetRelease tries to unset the release on the host in the variable file /etc/dnf/vars/releasever. It also tries to unset the release on the candlepin server. The unset release on the server is done asynchronously.

type RHSMConf

type RHSMConf struct {

	// Server represents section [server]
	Server RHSMConfServer `ini:"server"`

	// RHSM represents section [rhsm]
	RHSM RHSMConfRHSM `ini:"rhsm"`

	// RHSMCertDaemon represents section [rhsmcertd]
	RHSMCertDaemon RHSMConfRHSMCertDaemon `ini:"rhsmcertd"`

	// Logging represents section [logging]
	Logging RHSMConfLogging `ini:"logging"`
	// contains filtered or unexported fields
}

RHSMConf is structure intended for storing configuration that is typically read from /etc/rhsm/rhsm.conf. We try to

func LoadRHSMConf

func LoadRHSMConf(confFilePath string) (*RHSMConf, error)

LoadRHSMConf tries to load given configuration file to RHSMConf structure

type RHSMConfLogging

type RHSMConfLogging struct {
	DefaultLogLevel string `ini:"default_log_level" default:"INFO" allowedValues:"ERROR,WARN,INFO,DEBUG"`
}

type RHSMConfRHSM

type RHSMConfRHSM struct {
	// Directories used for certificates
	CACertDir             string `ini:"ca_cert_dir" default:"/etc/rhsm/ca/"`
	ConsumerCertDir       string `ini:"consumer_cert_dir" default:"/etc/pki/consumer"`       // modified
	EntitlementCertDir    string `ini:"entitlement_cert_dir" default:"/etc/pki/entitlement"` // modified
	ProductCertDir        string `ini:"product_cert_dir" default:"/etc/pki/product"`         // modified
	DefaultProductCertDir string `default:"/etc/pki/product-default"`

	// Configuration options related to RPMs and repositories
	BaseURL              string `ini:"baseurl" default:"https://cdn.redhat.com"`
	ReportPackageProfile bool   `ini:"report_package_profile" default:"true"`
	RepoCACertificate    string `ini:"repo_ca_cert" default:"/etc/rhsm/ca/redhat-uep.pem"`
	ManageRepos          bool   `ini:"manage_repos" default:"true"`

	// Configuration options related to DNF plugins
	AutoEnableYumPlugins  bool `ini:"auto_enable_yum_plugins" default:"true"`
	PackageProfileOnTrans bool `ini:"package_profile_on_trans" default:"false"`
}

RHSMConfRHSM represents section [rhsm] in rhsm.conf

type RHSMConfRHSMCertDaemon

type RHSMConfRHSMCertDaemon struct {
	AutoRegistration         bool  `ini:"auto_registration" default:"false"`
	AutoRegistrationInterval int64 `ini:"auto_registration_interval" default:"60"`
	Splay                    bool  `ini:"splay" default:"true"`
}

RHSMConfRHSMCertDaemon represents section [rhsmcertd] in rhsm.conf

type RHSMConfServer

type RHSMConfServer struct {
	// Basic settings for connection to candlepin server
	Hostname string `ini:"hostname" default:"subscription.rhsm.redhat.com"`
	Prefix   string `ini:"prefix" default:"/subscription"`
	Port     string `ini:"port" default:"443"`
	Insecure bool   `ini:"insecure" default:"false"`
	Timeout  int64  `ini:"server_timeout" default:"180"`

	// Proxy settings
	ProxyHostname string `ini:"proxy_hostname" default:""`
	ProxyScheme   string `ini:"proxy_scheme" default:"http" allowedValues:"http,https"`
	ProxyPort     string `ini:"proxy_port" default:"3128"`
	ProxyUser     string `ini:"proxy_user" default:""`
	ProxyPassword string `ini:"proxy_password" default:""`

	// Comma separated list of hostnames, when connection should not go
	// through proxy server
	NoProxy string `ini:"no_proxy" default:""`
}

RHSMConfServer represents section [server] in rhsm.conf

type RHSMConnection

type RHSMConnection struct {
	AuthType       AuthType
	Client         *http.Client
	ServerHostname *string
	ServerPort     *string
	ServerPrefix   *string
}

RHSMConnection contains information about connection to server This is typically connection to candlepin server, but it can be also connection to CDN, when we try to get information about release

type RHSMEndPoints

type RHSMEndPoints struct {
	Rel  string `json:"rel"`
	Href string `json:"href"`
}

RHSMEndPoints is structure used for storing GET response from REST API endpoint "/". This endpoint can be called using no-auth or consumer-cert-auth connection

type RHSMStatus

type RHSMStatus struct {
	Mode           string      `json:"mode"`
	ModeReason     interface{} `json:"modeReason"`
	ModeChangeTime interface{} `json:"modeChangeTime"`
	Result         bool        `json:"result"`
	Version        string      `json:"version"`
	Release        string      `json:"release"`
	Standalone     bool        `json:"standalone"`
	// Note: json module cannot unmarshal timeUTC into time.Time
	// for this reason: https://github.com/golang/go/issues/47353
	// Because we do not need to use timeUTC for anything ATM.
	// It is parsed as normal string.
	TimeUTC             string      `json:"timeUTC"`
	RulesSource         string      `json:"rulesSource"`
	RulesVersion        string      `json:"rulesVersion"`
	ManagerCapabilities []string    `json:"managerCapabilities"`
	KeycloakRealm       interface{} `json:"keycloakRealm"`
	KeycloakAuthUrl     interface{} `json:"keycloakAuthUrl"`
	KeycloakResource    interface{} `json:"keycloakResource"`
	DeviceAuthRealm     interface{} `json:"deviceAuthRealm"`
	DeviceAuthUrl       interface{} `json:"deviceAuthUrl"`
	DeviceAuthClientId  interface{} `json:"deviceAuthClientId"`
	DeviceAuthScope     interface{} `json:"deviceAuthScope"`
}

RHSMStatus is structure used for storing GET response from REST API endpoint "/status". This endpoint can be called using no-auth or consumer-cert-auth connection

type RegisterData

type RegisterData struct {
	Type              string             `json:"type"`
	Name              string             `json:"name"`
	Facts             *SystemFacts       `json:"facts"`
	InstalledProducts []InstalledProduct `json:"installedProducts"`
	ContentTags       []string           `json:"contentTags"`
	Role              string             `json:"role"`
	AddOns            []interface{}      `json:"addOns"`
	Usage             string             `json:"usage"`
	ServiceLevel      string             `json:"serviceLevel"`
	Environments      []Environment      `json:"environments"`
}

RegisterData is structure representing JSON data used for register request

type RegisterError

type RegisterError struct {
	DisplayMessage string `json:"displayMessage"`
	RequestUuid    string `json:"requestUuid"`
}

RegisterError is structure used for parsing JSON document returned by candlepin server, when registration is not successful

type RegisterOptions

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

RegisterOptions is structure containing various registration options

type Release

type Release struct {
	ReleaseVer string `json:"releaseVer"`
}

Release represents the release object returned from candlepin server

type RequestMetadata

type RequestMetadata struct {
	Locale        *string
	IPCSender     *string
	CorrelationId *string
}

RequestMetadata holds information about the current client triggering a given HTTP request. Information in this structure could not be stored in rhsmClient, because RHSM client could be also systemd .service providing e.g., D-Bus API or Varlink API and each D-Bus or Varlink client can have different preferences (e.g., locale).

type SysPurposeJSON

type SysPurposeJSON struct {
	Role                  string `json:"role"`
	ServiceLevelAgreement string `json:"service_level_agreement"`
	Usage                 string `json:"usage"`
}

SysPurposeJSON is structure holding system purpose attributes

type SystemFacts

type SystemFacts struct {
	SystemCertificateVersion string `json:"system.certificate_version"`
}

SystemFacts is collection of system facts necessary during registration

type UnregisterServerError

type UnregisterServerError struct {
	DisplayMessage string `json:"displayMessage"`
	RequestUuid    string `json:"requestUuid"`
	StatusCode     int
	ParsingError   error
}

UnregisterServerError is structure representing error returned from server

func (UnregisterServerError) Error

func (unregisterServerError UnregisterServerError) Error() string

Error interface

type UserAgentInfo

type UserAgentInfo struct {
	AppName      string
	Distribution string
}

UserAgentInfo holds information about the current client connected to the candlepin server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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