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

RHINENG-9505: candlepin improvements #1476

Merged
merged 4 commits into from
Sep 13, 2024
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
4 changes: 2 additions & 2 deletions base/candlepin/candlepin.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package candlepin

type ConsumersUpdateRequest struct {
Environments []ConsumersUpdateEnvironment
Environments []ConsumersUpdateEnvironment `json:"environments"`
}

type ConsumersUpdateEnvironment struct {
ID string
ID string `json:"id"`
}

type ConsumersUpdateResponse struct {
Expand Down
2 changes: 2 additions & 0 deletions base/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type coreConfig struct {
CandlepinAddress string
CandlepinCert string
CandlepinKey string
CandlepinCA string
ManagerPrivateAddress string
ListenerPrivateAddress string
EvaluatorUploadPrivateAddress string
Expand Down Expand Up @@ -160,6 +161,7 @@ func initServicesFromEnv() {
CoreCfg.CandlepinAddress = Getenv("CANDLEPIN_ADDRESS", CoreCfg.CandlepinAddress)
CoreCfg.CandlepinCert = Getenv("CANDLEPIN_CERT", CoreCfg.CandlepinCert)
CoreCfg.CandlepinKey = Getenv("CANDLEPIN_KEY", CoreCfg.CandlepinKey)
CoreCfg.CandlepinCA = Getenv("CANDLEPIN_CA", CoreCfg.CandlepinCA)
}

func initDBFromClowder() {
Expand Down
7 changes: 7 additions & 0 deletions manager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"app/base/utils"
"crypto/tls"
"crypto/x509"
"fmt"
"net/http"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -61,6 +62,12 @@ func CreateCandlepinClient() api.Client {
if err != nil {
return nil, err
}
if utils.CoreCfg.CandlepinCA != "" {
ok := certPool.AppendCertsFromPEM([]byte(utils.CoreCfg.CandlepinCA))
if !ok {
return nil, fmt.Errorf("could not parse candlepin ca cert")
}
}
tlsConfig = &tls.Config{
Certificates: []tls.Certificate{clientCert},
RootCAs: certPool,
Expand Down
2 changes: 1 addition & 1 deletion manager/controllers/template_systems_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TemplateSystemsDeleteHandler(c *gin.Context) {
return
}

err = assignCandlepinEnvironment(c, db, account, nil, req.Systems, groups)
err = assignCandlepinEnvironment(db, account, nil, req.Systems, groups)
if err != nil {
return
}
Expand Down
11 changes: 5 additions & 6 deletions manager/controllers/template_systems_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TemplateSystemsUpdateHandler(c *gin.Context) {
return
}

err = assignCandlepinEnvironment(c, db, account, &template.EnvironmentID, req.Systems, groups)
err = assignCandlepinEnvironment(db, account, &template.EnvironmentID, req.Systems, groups)
if err != nil {
return
}
Expand Down Expand Up @@ -173,12 +173,11 @@ func callCandlepin(ctx context.Context, consumer string, request *candlepin.Cons
*candlepin.ConsumersUpdateResponse, error) {
candlepinEnvConsumersURL := utils.CoreCfg.CandlepinAddress + "/consumers/" + consumer
candlepinFunc := func() (interface{}, *http.Response, error) {
utils.LogTrace("request", *request, "candlepin /consumers request")
candlepinResp := candlepin.ConsumersUpdateResponse{}
resp, err := candlepinClient.Request(&ctx, http.MethodPut, candlepinEnvConsumersURL, request, &candlepinResp)
statusCode := utils.TryGetStatusCode(resp)
utils.LogDebug("status_code", statusCode, "candlepin /consumers call")
utils.LogTrace("response", resp, "candlepin /consumers response")
utils.LogDebug("request", *request, "candlepin_url", candlepinEnvConsumersURL,
"status_code", statusCode, "err", err)
if err != nil && statusCode == 400 {
err = errors.Wrap(errCandlepin, err.Error())
}
Expand All @@ -193,7 +192,7 @@ func callCandlepin(ctx context.Context, consumer string, request *candlepin.Cons
return candlepinRespPtr.(*candlepin.ConsumersUpdateResponse), nil
}

func assignCandlepinEnvironment(c context.Context, db *gorm.DB, accountID int, env *string, inventoryIDs []string,
func assignCandlepinEnvironment(db *gorm.DB, accountID int, env *string, inventoryIDs []string,
groups map[string]string) error {
var consumers = []struct {
InventoryID string
Expand All @@ -219,7 +218,7 @@ func assignCandlepinEnvironment(c context.Context, db *gorm.DB, accountID int, e
err = errors2.Join(err, errors.Errorf("Missing owner_id for '%s'", consumer.InventoryID))
continue
}
resp, apiErr := callCandlepin(c, *consumer.Consumer, &updateReq)
resp, apiErr := callCandlepin(base.Context, *consumer.Consumer, &updateReq)
// check response
if apiErr != nil {
err = errors2.Join(err, apiErr, errors.New(resp.Message))
Expand Down
Loading