Skip to content

Commit

Permalink
MGMT-16501: Add request headers to api_vip_connectivity check request
Browse files Browse the repository at this point in the history
https://issues.redhat.com/browse/MGMT-16501
API change to include additional request headers when making a call
to the ignition endpoint. Allows for more flexibility to pass headers
to different ignition servers.
  • Loading branch information
CrystalChun committed Jan 17, 2024
1 parent 77bd860 commit c28b45a
Show file tree
Hide file tree
Showing 12 changed files with 547 additions and 18 deletions.

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

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

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

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

4 changes: 4 additions & 0 deletions internal/host/hostcommands/api_vip_connectivity_check_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hostcommands
import (
"context"
"encoding/json"
"fmt"

"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/host/hostutil"
Expand Down Expand Up @@ -50,9 +51,12 @@ func (c *apivipConnectivityCheckCmd) GetSteps(ctx context.Context, host *models.
request.CaCertificate = cluster.IgnitionEndpoint.CaCertificate
}

var requestHeaders []*models.APIVipConnectivityAdditionalRequestHeader
if commonHost.IgnitionEndpointToken != "" {
requestHeaders = append(requestHeaders, &models.APIVipConnectivityAdditionalRequestHeader{Key: "Authorization", Value: fmt.Sprintf("Bearer %s", commonHost.IgnitionEndpointToken)})
request.IgnitionEndpointToken = &commonHost.IgnitionEndpointToken
}
request.RequestHeaders = requestHeaders

requestBytes, err := json.Marshal(request)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ var _ = Describe("apivipconnectivitycheckcmd", func() {

It("get_step custom ignition endpoint", func() {
customEndpoint := "https://foo.bar:33735/acme"
expectedURL := fmt.Sprintf("{\"url\":\"%s/worker\"}", customEndpoint)
expectedUrl := fmt.Sprintf("{\"url\":\"%s/worker\"}", customEndpoint)
Expect(db.Model(&cluster).Update("ignition_endpoint_url", customEndpoint).Error).ShouldNot(HaveOccurred())
stepReply, stepErr = apivipConnectivityCheckCmd.GetSteps(ctx, &host)
Expect(stepReply[0]).ShouldNot(BeNil())
Expect(stepReply[0].Args[len(stepReply[0].Args)-1]).Should(Equal(expectedURL))
Expect(stepReply[0].Args[len(stepReply[0].Args)-1]).Should(Equal(expectedUrl))
Expect(stepErr).ShouldNot(HaveOccurred())
})

Expand All @@ -87,18 +87,18 @@ var _ = Describe("apivipconnectivitycheckcmd", func() {
It("get_step custom ignition endpoint and pool name", func() {
customEndpoint := "https://foo.bar:33735/acme"
poolName := "testpool"
expectedURL := fmt.Sprintf("{\"url\":\"%s/%s\"}", customEndpoint, poolName)
expectedUrl := fmt.Sprintf("{\"url\":\"%s/%s\"}", customEndpoint, poolName)
Expect(db.Model(&host).Update("MachineConfigPoolName", poolName).Error).ShouldNot(HaveOccurred())
Expect(db.Model(&cluster).Update("ignition_endpoint_url", customEndpoint).Error).ShouldNot(HaveOccurred())
stepReply, stepErr = apivipConnectivityCheckCmd.GetSteps(ctx, &host)
Expect(stepReply[0]).ShouldNot(BeNil())
Expect(stepReply[0].Args[len(stepReply[0].Args)-1]).Should(Equal(expectedURL))
Expect(stepReply[0].Args[len(stepReply[0].Args)-1]).Should(Equal(expectedUrl))
Expect(stepErr).ShouldNot(HaveOccurred())
})

It("get_step custom token", func() {
token := "verysecrettoken"
expectedArgs := fmt.Sprintf("{\"ignition_endpoint_token\":\"%s\",\"url\":\"http://test.com:22624/config/worker\"}", token)
expectedArgs := fmt.Sprintf("{\"ignition_endpoint_token\":\"%s\",\"request_headers\":[{\"key\":\"Authorization\",\"value\":\"Bearer %s\"}],\"url\":\"http://test.com:22624/config/worker\"}", token, token)
Expect(db.Model(&host).Update("ignition_endpoint_token", token).Error).ShouldNot(HaveOccurred())
stepReply, stepErr = apivipConnectivityCheckCmd.GetSteps(ctx, &host)
Expect(stepReply[0]).ShouldNot(BeNil())
Expand All @@ -111,8 +111,8 @@ var _ = Describe("apivipconnectivitycheckcmd", func() {
poolName := "testpool"
customEndpoint := "https://foo.bar:33735/acme"
customCACert := "somecertificatestring"
expectedArgs := fmt.Sprintf("{\"ca_certificate\":\"%s\",\"ignition_endpoint_token\":\"%s\",\"url\":\"%s/%s\"}",
customCACert, token, customEndpoint, poolName)
expectedArgs := fmt.Sprintf("{\"ca_certificate\":\"%s\",\"ignition_endpoint_token\":\"%s\",\"request_headers\":[{\"key\":\"Authorization\",\"value\":\"Bearer %s\"}],\"url\":\"%s/%s\"}",
customCACert, token, token, customEndpoint, poolName)
Expect(db.Model(&host).Update("MachineConfigPoolName", poolName).Error).ShouldNot(HaveOccurred())
Expect(db.Model(&host).Update("ignition_endpoint_token", token).Error).ShouldNot(HaveOccurred())
Expect(db.Model(&cluster).Update("ignition_endpoint_url", customEndpoint).Error).ShouldNot(HaveOccurred())
Expand Down

0 comments on commit c28b45a

Please sign in to comment.