Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theedge 3710: Add activation key to image model and add it on image builder request #2360

Merged
merged 9 commits into from
Jan 18, 2024
83 changes: 44 additions & 39 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type EdgeConfig struct {
DeleteFilesRetryDelay uint `json:"delete_files_retry_delay"`
RbacBaseURL string `json:"rbac_base_url"`
RbacTimeout uint `mapstructure:"rbac_timeout,omitempty"`
ActivationKeyServerURL string `json:"activation_key_server_url"`
ActivationKeyBaseUrl string `json:"activation_key_base_url"`
}

type dbConfig struct {
Expand Down Expand Up @@ -217,64 +219,67 @@ func CreateEdgeAPIConfig() (*EdgeConfig, error) {
options.SetDefault("TenantTranslatorPort", os.Getenv("TENANT_TRANSLATOR_PORT"))

edgeConfig := &EdgeConfig{
Hostname: options.GetString("Hostname"),
Auth: options.GetBool("Auth"),
WebPort: options.GetInt("WebPort"),
MetricsPort: options.GetInt("MetricsPort"),
MetricsBaseURL: options.GetString("MetricsBaseURL"),
Debug: options.GetBool("Debug"),
LogLevel: options.GetString("LOG_LEVEL"),
BucketName: options.GetString("EdgeTarballsBucket"),
BucketRegion: options.GetString("BucketRegion"),
RepoTempPath: options.GetString("RepoTempPath"),
OpenAPIFilePath: options.GetString("OpenAPIFilePath"),
HTTPClientTimeout: options.GetInt("HTTPClientTimeout"),
ImageBuilderConfig: &imageBuilderConfig{
URL: options.GetString("ImageBuilderUrl"),
},
InventoryConfig: &inventoryConfig{
URL: options.GetString("InventoryUrl"),
},
PlaybookDispatcherConfig: &playbookDispatcherConfig{
URL: options.GetString("PlaybookDispatcherURL"),
PSK: options.GetString("PlaybookDispatcherPSK"),
Status: options.GetString("PlaybookDispatcherStatusURL"),
},
TemplatesPath: options.GetString("TemplatesPath"),
EdgeAPIBaseURL: options.GetString("EdgeAPIBaseURL"),
EdgeCertAPIBaseURL: options.GetString("EdgeCertAPIBaseURL"),
EdgeAPIServiceHost: options.GetString("EDGE_API_SERVICE_SERVICE_HOST"),
EdgeAPIServicePort: options.GetInt("EDGE_API_SERVICE_SERVICE_PORT"),
UploadWorkers: options.GetInt("UploadWorkers"),
FDO: &fdoConfig{
URL: options.GetString("FDOHostURL"),
APIVersion: options.GetString("FDOApiVersion"),
AuthorizationBearer: options.GetString("FDOAuthorizationBearer"),
},
Hostname: options.GetString("Hostname"),
Auth: options.GetBool("Auth"),
WebPort: options.GetInt("WebPort"),
MetricsPort: options.GetInt("MetricsPort"),
MetricsBaseURL: options.GetString("MetricsBaseURL"),
Logging: &loggingConfig{},
LogLevel: options.GetString("LOG_LEVEL"),
Debug: options.GetBool("Debug"),
Database: &dbConfig{},
BucketName: options.GetString("EdgeTarballsBucket"),
BucketRegion: options.GetString("BucketRegion"),
AccessKey: "",
SecretKey: "",
AWSToken: "",
RepoTempPath: options.GetString("RepoTempPath"),
OpenAPIFilePath: options.GetString("OpenAPIFilePath"),
ImageBuilderConfig: &imageBuilderConfig{URL: options.GetString("ImageBuilderUrl")},
InventoryConfig: &inventoryConfig{URL: options.GetString("InventoryUrl")},
PlaybookDispatcherConfig: &playbookDispatcherConfig{URL: options.GetString("PlaybookDispatcherURL"), PSK: options.GetString("PlaybookDispatcherPSK"), Status: options.GetString("PlaybookDispatcherStatusURL")},
TemplatesPath: options.GetString("TemplatesPath"),
EdgeAPIBaseURL: options.GetString("EdgeAPIBaseURL"),
EdgeCertAPIBaseURL: options.GetString("EdgeCertAPIBaseURL"),
EdgeAPIServiceHost: options.GetString("EDGE_API_SERVICE_SERVICE_HOST"),
EdgeAPIServicePort: options.GetInt("EDGE_API_SERVICE_SERVICE_PORT"),
UploadWorkers: options.GetInt("UploadWorkers"),
KafkaConfig: &clowder.KafkaConfig{},
KafkaBrokers: []clowder.BrokerConfig{},
KafkaServers: "",
KafkaBroker: &clowder.BrokerConfig{},
KafkaBrokerCaCertPath: "",
KafkaRequestRequiredAcks: options.GetInt("KafkaRequestRequiredAcks"),
KafkaMessageSendMaxRetries: options.GetInt("KafkaMessageSendMaxRetries"),
KafkaRetryBackoffMs: options.GetInt("KafkaRetryBackoffMs"),
KafkaTopics: map[string]string{},
FDO: &fdoConfig{URL: options.GetString("FDOHostURL"), APIVersion: options.GetString("FDOApiVersion"), AuthorizationBearer: options.GetString("FDOAuthorizationBearer")},
Local: options.GetBool("Local"),
Dev: options.GetBool("Dev"),
UnleashURL: options.GetString("FeatureFlagsUrl"),
UnleashSecretName: options.GetString("FeatureFlagsBearerToken"),
FeatureFlagsEnvironment: options.GetString("FeatureFlagsEnvironment"),
FeatureFlagsURL: options.GetString("FeatureFlagsUrl"),
FeatureFlagsAPIToken: options.GetString("FeatureFlagsAPIToken"),
FeatureFlagsBearerToken: options.GetString("FeatureFlagsBearerToken"),
FeatureFlagsService: options.GetString("FeatureFlagsService"),
TenantTranslatorHost: options.GetString("TenantTranslatorHost"),
FeatureFlagsBearerToken: options.GetString("FeatureFlagsBearerToken"),
ContentSourcesURL: options.GetString("CONTENT_SOURCES_URL"),
TenantTranslatorHost: options.GetString("TenantTranslatorHost"),
TenantTranslatorPort: options.GetString("TenantTranslatorPort"),
TenantTranslatorURL: "",
ImageBuilderOrgID: options.GetString("ImageBuilderOrgID"),
KafkaRequestRequiredAcks: options.GetInt("KafkaRequestRequiredAcks"),
KafkaMessageSendMaxRetries: options.GetInt("KafkaMessageSendMaxRetries"),
KafkaRetryBackoffMs: options.GetInt("KafkaRetryBackoffMs"),
GpgVerify: options.GetString("GpgVerify"),
GlitchtipDsn: options.GetString("GlitchtipDsn"),
HTTPClientTimeout: options.GetInt("HTTPClientTimeout"),
TlsCAPath: options.GetString("/tmp/tls_path.txt"),
RepoFileUploadAttempts: options.GetUint("RepoFileUploadAttempts"),
RepoFileUploadDelay: 0,
DeleteFilesAttempts: options.GetUint("DeleteFilesAttempts"),
DeleteFilesRetryDelay: options.GetUint("DeleteFilesRetryDelay"),
RbacBaseURL: options.GetString("RBAC_BASE_URL"),
RbacTimeout: options.GetUint("RbacTimeout"),
ActivationKeyServerURL: options.GetString("ACTIVATION_KEY_SERVER_URL"),
ActivationKeyBaseUrl: options.GetString("ACTIVATION_KEY_BASE_URL"),
}
if edgeConfig.TenantTranslatorHost != "" && edgeConfig.TenantTranslatorPort != "" {
edgeConfig.TenantTranslatorURL = fmt.Sprintf("http://%s:%s", edgeConfig.TenantTranslatorHost, edgeConfig.TenantTranslatorPort)
Expand Down
19 changes: 19 additions & 0 deletions pkg/clients/imagebuilder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Customizations struct {
Packages *[]string `json:"packages"`
PayloadRepositories *[]Repository `json:"payload_repositories,omitempty"`
Users *[]User `json:"users,omitempty"`
Subscription *Subscription `json:"subscription,omitempty"`
}

// Repository is the record of Third Party Repository
Expand All @@ -88,6 +89,14 @@ type User struct {
Name string `json:"name"`
SSHKey string `json:"ssh_key"`
}
type Subscription struct {
Organization string `json:"organization"`
ActivationKey string `json:"activation-key"`
BaseUrl string `json:"base-url"`
ServerUrl string `json:"server-url"`
Insights bool `json:"insights"`
RHC bool `json:"rhc"`
}

// UploadRequest is the upload options accepted by Image Builder API
type UploadRequest struct {
Expand Down Expand Up @@ -248,6 +257,16 @@ func (c *Client) ComposeCommit(image *models.Image) (*models.Image, error) {
},
}},
}
if image.ActivationKey != "" {
req.Customizations.Subscription = &Subscription{
ActivationKey: image.ActivationKey,
Organization: image.OrgID,
BaseUrl: config.Get().ActivationKeyBaseUrl,
ServerUrl: config.Get().ActivationKeyServerURL,
Insights: true,
RHC: true,
}
}
if image.Commit.OSTreeRef != "" {
if req.ImageRequests[0].Ostree == nil {
req.ImageRequests[0].Ostree = &OSTree{}
Expand Down
1 change: 1 addition & 0 deletions pkg/models/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Image struct {
ThirdPartyRepositories []ThirdPartyRepo `json:"ThirdPartyRepositories,omitempty" gorm:"many2many:images_repos;"`
CustomPackages []Package `json:"CustomPackages,omitempty" gorm:"many2many:images_custom_packages"`
RequestID string `json:"request_id"` // storing for logging reference on resume
ActivationKey string `json:"activationKey,omitempty"`

TotalDevicesWithImage int64 `json:"SystemsRunning" gorm:"-"` // only for forms
TotalPackages int `json:"TotalPackages" gorm:"-"` // only for forms
Expand Down