Skip to content

Commit

Permalink
PMM-13129 Changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriCtvrtka committed Jun 26, 2024
1 parent 8c9d21a commit f35ad67
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 51 deletions.
33 changes: 0 additions & 33 deletions managed/models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,21 +593,10 @@ func createPMMAgentWithID(q *reform.Querier, id, runsOnNodeID string, customLabe
// TODO https://jira.percona.com/browse/PMM-4496
// Check that Node is not remote.

encryptedUsername, err := encryption.Encrypt("")
if err != nil {
logrus.Warningf("Encryption: %v", err)
}
encryptedPassword, err := encryption.Encrypt("")
if err != nil {
logrus.Warningf("Encryption: %v", err)
}

agent := &Agent{
AgentID: id,
AgentType: PMMAgentType,
RunsOnNodeID: &runsOnNodeID,
Username: &encryptedUsername,
Password: &encryptedPassword,
}
if err := agent.SetCustomLabels(customLabels); err != nil {
return nil, err
Expand Down Expand Up @@ -654,22 +643,11 @@ func CreateNodeExporter(q *reform.Querier,
" it doesn't support it, minimum supported version=%q", pointer.GetString(pmmAgent.Version), PMMAgentWithPushMetricsSupport.String())
}

encryptedUsername, err := encryption.Encrypt("")
if err != nil {
logrus.Warningf("Encryption: %v", err)
}
encryptedPassword, err := encryption.Encrypt("")
if err != nil {
logrus.Warningf("Encryption: %v", err)
}

row := &Agent{
AgentID: id,
AgentType: NodeExporterType,
PMMAgentID: &pmmAgentID,
NodeID: pmmAgent.RunsOnNodeID,
Username: &encryptedUsername,
Password: &encryptedPassword,
PushMetrics: pushMetrics,
DisabledCollectors: disableCollectors,
AgentPassword: agentPassword,
Expand Down Expand Up @@ -750,23 +728,12 @@ func CreateExternalExporter(q *reform.Querier, params *CreateExternalExporterPar
metricsPath = "/metrics"
}

encryptedUsername, err := encryption.Encrypt(params.Username)
if err != nil {
logrus.Warningf("Encryption: %v", err)
}
encryptedPassword, err := encryption.Encrypt(params.Password)
if err != nil {
logrus.Warningf("Encryption: %v", err)
}

row := &Agent{
PMMAgentID: pmmAgentID,
AgentID: id,
AgentType: ExternalExporterType,
RunsOnNodeID: runsOnNodeID,
ServiceID: pointer.ToStringOrNil(params.ServiceID),
Username: &encryptedUsername,
Password: &encryptedPassword,
MetricsScheme: &scheme,
MetricsPath: &metricsPath,
ListenPort: pointer.ToUint16(uint16(params.ListenPort)),
Expand Down
2 changes: 0 additions & 2 deletions managed/models/agent_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,6 @@ func TestAgentHelpers(t *testing.T) {
RunsOnNodeID: pointer.ToString("N1"),
ServiceID: pointer.ToString("S1"),
ListenPort: pointer.ToUint16(9104),
Username: agent.Username,
Password: agent.Password,
MetricsPath: pointer.ToString("/metrics"),
MetricsScheme: pointer.ToString("http"),
CreatedAt: now,
Expand Down
21 changes: 5 additions & 16 deletions managed/utils/encryption/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,13 @@ func (e *Encryption) EncryptDB(ctx context.Context, c *DatabaseConnection) error

for k, v := range res.SetValues {
for i, val := range v {
var value string
if v, ok := val.(*sql.NullString); ok {
value = v.String
}

if value != "" {
_, err := base64.StdEncoding.DecodeString(value)
if err == nil {
res.SetValues[k][i] = value
continue
}
value := val.(*sql.NullString)
if !value.Valid {
res.SetValues[k][i] = sql.NullString{}
continue
}

encrypted, err := e.Encrypt(value)
encrypted, err := e.Encrypt(value.String)
if err != nil {
return err
}
Expand Down Expand Up @@ -226,10 +219,6 @@ func (e *Encryption) DecryptDB(ctx context.Context, c *DatabaseConnection) error
if err != nil {
return err
}
if decrypted == "" {
res.SetValues[k][i] = sql.NullString{}
continue
}
res.SetValues[k][i] = decrypted
}
data := slices.Concat([]any{}, v)
Expand Down

0 comments on commit f35ad67

Please sign in to comment.