Skip to content

Commit

Permalink
add dummy values to Principal and Name fields
Browse files Browse the repository at this point in the history
  • Loading branch information
r14chandra committed Mar 7, 2024
1 parent ef41a1d commit 59cc473
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 37 deletions.
11 changes: 3 additions & 8 deletions internal/cmd/inventoryconsumer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ type identityKey string
// InventoryEvent represents a message read off the inventory.events
// topic.
type InventoryEvent struct {
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Host internal.Host `json:"host"`
PlatformMetadata struct {
B64Identity string `json:"b64_identity"`
} `json:"platform_metadata"`
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Host internal.Host `json:"host"`
}

func handler(ctx context.Context, msg kafka.Message) {
Expand All @@ -76,8 +73,6 @@ func handler(ctx context.Context, msg kafka.Message) {
return
}

ctx = context.WithValue(ctx, identityKey("identity"), event.PlatformMetadata.B64Identity)

switch eventType {
case "created":
logger.Info().Msg("setting up new host for remote host configuration")
Expand Down
36 changes: 7 additions & 29 deletions internal/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"config-manager/internal/db"
"config-manager/internal/util"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"time"
Expand All @@ -31,14 +30,6 @@ type Host struct {
} `json:"system_profile"`
}

type IdentityData struct {
Identity struct {
User struct {
Username string `json:"username"`
} `json:"user"`
} `json:"identity"`
}

// ApplyProfile applies the current profile to the specified hosts.
func ApplyProfile(ctx context.Context, profile *db.Profile, hosts []Host, fn func(resp []dispatcher.RunCreated)) {
logger := log.With().Logger()
Expand All @@ -52,24 +43,6 @@ func ApplyProfile(ctx context.Context, profile *db.Profile, hosts []Host, fn fun
return
}

identity, ok := ctx.Value("identity").(string)
username := ""
if ok {
rawIdentity, err := base64.StdEncoding.DecodeString(identity)

if err != nil {
fmt.Println("Error decoding identity:", err)
return
}
identityData := &IdentityData{}

if err := json.Unmarshal(rawIdentity, &identityData); err != nil {
fmt.Println("Error parsing JSON:", err)
return
}
username = identityData.Identity.User.Username
}

logger.Debug().Int("num_hosts", len(hosts)).Msg("applying profile for hosts")

runs := make([]dispatcher.RunInputV2, 0, len(hosts))
Expand All @@ -79,12 +52,17 @@ func ApplyProfile(ctx context.Context, profile *db.Profile, hosts []Host, fn fun
continue
}
logger.Debug().Str("client_id", host.SystemProfile.RHCID).Msg("creating run for host")

// Sending dummy values to `Principal` and `Name` fields as config-manager doesn't store/get playbook name

Check failure on line 56 in internal/host.go

View workflow job for this annotation

GitHub Actions / Lint language

`dummy` may be insensitive, use `placeholder`, `sample` instead
// and moreover, ApplyProfile is also used in internal/dispatch/dispatch.go, it is not possible to pass identity from there
// and populate `Principal` field i.e username.
// These two fields are important for apps like Remediations.
run := dispatcher.RunInputV2{
Recipient: uuid.MustParse(host.SystemProfile.RHCID),
OrgId: host.OrgID,
Principal: username,
Principal: "r14chandra",
Url: config.DefaultConfig.PlaybookHost.String() + fmt.Sprintf(config.DefaultConfig.PlaybookPath, profile.ID),
Name: profile.Name.String,
Name: "Apply fix",
Labels: &dispatcher.Labels{
"state_id": profile.ID.String(),
"id": host.ID,
Expand Down

0 comments on commit 59cc473

Please sign in to comment.