Skip to content

Commit

Permalink
feat: address the PR comments and refactoring the flow for the config…
Browse files Browse the repository at this point in the history
…uration for the new image

Signed-off-by: Adelia Ferreira <[email protected]>
  • Loading branch information
adeliaferreira committed Jan 9, 2024
1 parent 8265319 commit 23f948a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 73 deletions.
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
27 changes: 22 additions & 5 deletions pkg/clients/imagebuilder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ type OSTree struct {

// Customizations is made of the packages that are baked into an image
type Customizations struct {
Packages *[]string `json:"packages"`
PayloadRepositories *[]Repository `json:"payload_repositories,omitempty"`
Users *[]User `json:"users,omitempty"`
Subscription *models.ImageSubscription `json:"subscription"`
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 @@ -89,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 @@ -237,7 +245,6 @@ func (c *Client) ComposeCommit(image *models.Image) (*models.Image, error) {
Customizations: &Customizations{
Packages: image.GetALLPackagesList(),
PayloadRepositories: &payloadRepos,
Subscription: image.Subscription,
},
Distribution: image.Distribution,
ImageRequests: []ImageRequest{
Expand All @@ -250,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
48 changes: 19 additions & 29 deletions pkg/models/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,28 @@ type ImageSet struct {
Images []Image `json:"Images"`
}

type ImageSubscription struct {
Model
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"`
}

// Image is what generates a OSTree Commit.
type Image struct {
Model
Name string `json:"Name"`
Account string `json:"Account"`
OrgID string `json:"org_id" gorm:"index;<-:create"`
Distribution string `json:"Distribution"`
Description string `json:"Description"`
Status string `json:"Status"`
Version int `json:"Version" gorm:"default:1"`
ImageType string `json:"ImageType"` // TODO: Remove as soon as the frontend stops using
OutputTypes pq.StringArray `gorm:"type:text[]" json:"OutputTypes"`
CommitID uint `json:"CommitID"`
Commit *Commit `json:"Commit"`
InstallerID *uint `json:"InstallerID"`
Installer *Installer `json:"Installer"`
ImageSetID *uint `json:"ImageSetID" gorm:"index"` // TODO: Wipe staging database and set to not nullable
Packages []Package `json:"Packages,omitempty" gorm:"many2many:images_packages;"`
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
Subscription ImageSubscription `json:"subscription,omitempty" gorm:"foreignKey:ActivationKey"`
Name string `json:"Name"`
Account string `json:"Account"`
OrgID string `json:"org_id" gorm:"index;<-:create"`
Distribution string `json:"Distribution"`
Description string `json:"Description"`
Status string `json:"Status"`
Version int `json:"Version" gorm:"default:1"`
ImageType string `json:"ImageType"` // TODO: Remove as soon as the frontend stops using
OutputTypes pq.StringArray `gorm:"type:text[]" json:"OutputTypes"`
CommitID uint `json:"CommitID"`
Commit *Commit `json:"Commit"`
InstallerID *uint `json:"InstallerID"`
Installer *Installer `json:"Installer"`
ImageSetID *uint `json:"ImageSetID" gorm:"index"` // TODO: Wipe staging database and set to not nullable
Packages []Package `json:"Packages,omitempty" gorm:"many2many:images_packages;"`
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

0 comments on commit 23f948a

Please sign in to comment.