Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/common/testdata/exported_blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
],
"snapshot_date": "2012-12-20",
"customizations": {
"aap_registration": {
"ansible_callback_url": "https://aap-gw.example.com/api/controller/v2/job_templates/42/callback/",
"host_config_key": "",
"skip_tls_verification": false,
"tls_certificate_authority": "-----BEGIN CERTIFICATE-----\nMIIC0DCCAbigAwIBAgIUI...\n-----END CERTIFICATE-----"
},
"custom_repositories": [
{
"baseurl": [
Expand Down
7 changes: 3 additions & 4 deletions internal/v1/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/v1/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,6 @@ components:
type: string
description: |
Name of the content template. Used when registering the system to Insights.
aap_registration:
$ref: '#/components/schemas/AAPRegistration'
ImageTypes:
type: string
enum:
Expand Down Expand Up @@ -1783,6 +1781,8 @@ components:
$ref: '#/components/schemas/Installer'
cacerts:
$ref: '#/components/schemas/CACertsCustomization'
aap_registration:
$ref: '#/components/schemas/AAPRegistration'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API breaking change, will UI be ready when we merge this? It will go straight into stage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI is done, but will need a review.
It contains playwright test that was waiting for these changes to include import and export. I can tag people for review today, but it will need to be merged after this gets merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? It's just additive, isn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a refactoring, see the hunk above.

Well, if there are no upgrade concerns, I am fine.

Container:
type: object
required:
Expand Down
14 changes: 14 additions & 0 deletions internal/v1/handler_blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (bb *BlueprintBody) RedactCertificates() {
bb.Customizations.Cacerts = nil
}

func (bb *BlueprintBody) RedactAAPRegistration() {
if bb.Customizations.AAPRegistration != nil {
bb.Customizations.AAPRegistration.HostConfigKey = ""
}
}

// Merges Password or SshKey from other User struct to this User struct if it is not set
func (u *User) MergeExisting(other User) {
if u.Password == nil {
Expand Down Expand Up @@ -179,6 +185,12 @@ func WithRedactedCertificates() BlueprintBodyOption {
}
}

func WithRedactedAAPRegistration() BlueprintBodyOption {
return func(bp *BlueprintBody) {
bp.RedactAAPRegistration()
}
}

func WithRedactedFiles(paths []string) BlueprintBodyOption {
return func(bp *BlueprintBody) {
if bp.Customizations.Files != nil {
Expand Down Expand Up @@ -369,9 +381,11 @@ func (h *Handlers) ExportBlueprint(ctx echo.Context, id openapi_types.UUID) erro
blueprintEntry,
WithRedactedPasswords(),
WithRedactedCertificates(),
WithRedactedAAPRegistration(),
WithRedactedFiles([]string{
"/etc/systemd/system/register-satellite.service",
"/usr/local/sbin/register-satellite",
"/usr/local/sbin/aap-first-boot-reg",
}),
)
if err != nil {
Expand Down
31 changes: 28 additions & 3 deletions internal/v1/handler_blueprints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func TestHandlers_CreateBlueprint(t *testing.T) {
{"name": "user", "password": "test"},
{"name": "user2", "ssh_key": "ssh-rsa AAAAB3NzaC1"},
},
"aap_registration": map[string]interface{}{
"ansible_callback_url": "https://aap-gw.example.com/api/controller/v2/job_templates/42/callback/",
"host_config_key": "test-host-config-key-12345",
"tls_certificate_authority": "-----BEGIN CERTIFICATE-----\nMIIC0DCCAbigAwIBAgIUI...\n-----END CERTIFICATE-----",
"skip_tls_verification": false,
},
},
"distribution": "centos-9",
"image_requests": []map[string]interface{}{
Expand All @@ -93,6 +99,15 @@ func TestHandlers_CreateBlueprint(t *testing.T) {
require.NoError(t, err)
require.Nil(t, be.Metadata)

blueprint, err := v1.BlueprintFromEntry(be)
require.NoError(t, err)
require.NotNil(t, blueprint.Customizations.AAPRegistration)
require.Equal(t, "https://aap-gw.example.com/api/controller/v2/job_templates/42/callback/", blueprint.Customizations.AAPRegistration.AnsibleCallbackUrl)
require.Equal(t, "test-host-config-key-12345", blueprint.Customizations.AAPRegistration.HostConfigKey)
require.Equal(t, "-----BEGIN CERTIFICATE-----\nMIIC0DCCAbigAwIBAgIUI...\n-----END CERTIFICATE-----", blueprint.Customizations.AAPRegistration.TlsCertificateAuthority)
require.NotNil(t, blueprint.Customizations.AAPRegistration.SkipTlsVerification)
require.False(t, *blueprint.Customizations.AAPRegistration.SkipTlsVerification)

// Test unique name constraint
statusCode, resp := tutils.PostResponseBody(t, srvURL+"/api/image-builder/v1/blueprints", body)
require.Equal(t, http.StatusUnprocessableEntity, statusCode)
Expand Down Expand Up @@ -877,14 +892,13 @@ func TestHandlers_BlueprintFromEntryRedactedForExport(t *testing.T) {
result, err := v1.BlueprintFromEntry(
be,
v1.WithRedactedPasswords(),
v1.WithRedactedCertificates(),
v1.WithRedactedFiles([]string{
"/etc/systemd/system/register-satellite.service",
"/usr/local/sbin/register-satellite",
}),
)
require.NoError(t, err)
require.Nil(t, result.Customizations.Cacerts)
require.NotNil(t, result.Customizations.Cacerts)
require.Nil(t, result.Customizations.Files)
})

Expand Down Expand Up @@ -916,7 +930,6 @@ func TestHandlers_BlueprintFromEntryRedactedForExport(t *testing.T) {
result, err := v1.BlueprintFromEntry(
be,
v1.WithRedactedPasswords(),
v1.WithRedactedCertificates(),
v1.WithRedactedFiles([]string{
"/etc/systemd/system/register-satellite.service",
"/usr/local/sbin/register-satellite",
Expand Down Expand Up @@ -1127,6 +1140,12 @@ func TestHandlers_ExportBlueprint(t *testing.T) {
Subscription: &v1.Subscription{
ActivationKey: "aaa",
},
AAPRegistration: &v1.AAPRegistration{
AnsibleCallbackUrl: "https://aap-gw.example.com/api/controller/v2/job_templates/42/callback/",
HostConfigKey: "test-host-config-key-12345",
TlsCertificateAuthority: "-----BEGIN CERTIFICATE-----\nMIIC0DCCAbigAwIBAgIUI...\n-----END CERTIFICATE-----",
SkipTlsVerification: common.ToPtr(false),
},
Users: common.ToPtr([]v1.User{
{
Name: "user",
Expand Down Expand Up @@ -1257,6 +1276,12 @@ func TestHandlers_ExportBlueprint(t *testing.T) {
Subscription: &v1.Subscription{
ActivationKey: "aaa",
},
AAPRegistration: &v1.AAPRegistration{
AnsibleCallbackUrl: "https://aap-gw.example.com/api/controller/v2/job_templates/42/callback/",
HostConfigKey: "test-host-config-key-12345",
TlsCertificateAuthority: "-----BEGIN CERTIFICATE-----\nMIIC0DCCAbigAwIBAgIUI...\n-----END CERTIFICATE-----",
SkipTlsVerification: common.ToPtr(false),
},
Users: common.ToPtr([]v1.User{
{
Name: "user",
Expand Down
2 changes: 1 addition & 1 deletion internal/v1/handler_compose_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ func (h *Handlers) buildCustomizations(ctx echo.Context, cr *ComposeRequest, d *
}
}

if aap := cr.ImageRequests[0].AAPRegistration; aap != nil {
if aap := cust.AAPRegistration; aap != nil {
script, err := tmpl.RenderAAPRegistrationScript(ctx.Request().Context(), tmpl.AAPRegistrationParams{
HostConfigKey: aap.HostConfigKey,
AnsibleCallbackUrl: aap.AnsibleCallbackUrl,
Expand Down
15 changes: 8 additions & 7 deletions internal/v1/handler_post_compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2955,8 +2955,14 @@ func TestComposeCustomizations(t *testing.T) {
// aap first boot registration
{
imageBuilderRequest: v1.ComposeRequest{
Customizations: &v1.Customizations{},
Distribution: "rhel-8",
Customizations: &v1.Customizations{
AAPRegistration: &v1.AAPRegistration{
AnsibleCallbackUrl: "http://some-url.org/api/controller/v2/job_templates/38/callback/",
HostConfigKey: "some-key",
TlsCertificateAuthority: "---BEGIN CERTIFICATE---\nMIIC0DCCAbigAwIBAgIUI...\n---END CERTIFICATE---",
},
},
Distribution: "rhel-8",
ImageRequests: []v1.ImageRequest{
{
Architecture: "x86_64",
Expand All @@ -2965,11 +2971,6 @@ func TestComposeCustomizations(t *testing.T) {
Type: v1.UploadTypesAwsS3,
Options: uo,
},
AAPRegistration: &v1.AAPRegistration{
AnsibleCallbackUrl: "http://some-url.org/api/controller/v2/job_templates/38/callback/",
HostConfigKey: "some-key",
TlsCertificateAuthority: "---BEGIN CERTIFICATE---\nMIIC0DCCAbigAwIBAgIUI...\n---END CERTIFICATE---",
},
},
},
},
Expand Down
Loading