Skip to content

Commit

Permalink
Revert "PMM-13129 Dereference all DB options on encrypt/decrypt."
Browse files Browse the repository at this point in the history
This reverts commit fe3be31.
  • Loading branch information
JiriCtvrtka committed Jul 9, 2024
1 parent 9fd8982 commit f955040
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
12 changes: 9 additions & 3 deletions managed/models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,9 @@ func CreateNodeExporter(q *reform.Querier,
return nil, errors.WithStack(err)
}

return row, nil
decryptedAgent := DecryptAgent(encryptedAgent)

return &decryptedAgent, nil
}

// CreateExternalExporterParams params for add external exporter.
Expand Down Expand Up @@ -738,7 +740,9 @@ func CreateExternalExporter(q *reform.Querier, params *CreateExternalExporterPar
return nil, errors.WithStack(err)
}

return row, nil
decryptedAgent := DecryptAgent(encryptedAgent)

return &decryptedAgent, nil
}

// CreateAgentParams params for add common exporter.
Expand Down Expand Up @@ -930,7 +934,9 @@ func CreateAgent(q *reform.Querier, agentType AgentType, params *CreateAgentPara
return nil, errors.WithStack(err)
}

return row, nil
decryptedAgent := DecryptAgent(encryptedAgent)

return &decryptedAgent, nil
}

// ChangeCommonAgentParams contains parameters that can be changed for all Agents.
Expand Down
32 changes: 10 additions & 22 deletions managed/models/encryption_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,67 +77,55 @@ func agentEncryption(agent Agent, handler func(string) (string, error)) Agent {

var err error
if agent.MySQLOptions != nil {
options := &MySQLOptions{}
*options = *agent.MySQLOptions
options.TLSCert, err = handler(agent.MySQLOptions.TLSCert)
agent.MySQLOptions.TLSCert, err = handler(agent.MySQLOptions.TLSCert)
if err != nil {
logrus.Warning(err)
}
options.TLSKey, err = handler(agent.MySQLOptions.TLSKey)
agent.MySQLOptions.TLSKey, err = handler(agent.MySQLOptions.TLSKey)
if err != nil {
logrus.Warning(err)
}
agent.MySQLOptions = options
}

if agent.PostgreSQLOptions != nil {
options := &PostgreSQLOptions{}
*options = *agent.PostgreSQLOptions
options.SSLCert, err = handler(agent.PostgreSQLOptions.SSLCert)
agent.PostgreSQLOptions.SSLCert, err = handler(agent.PostgreSQLOptions.SSLCert)
if err != nil {
logrus.Warning(err)
}
options.SSLKey, err = handler(agent.PostgreSQLOptions.SSLKey)
agent.PostgreSQLOptions.SSLKey, err = handler(agent.PostgreSQLOptions.SSLKey)
if err != nil {
logrus.Warning(err)
}
agent.PostgreSQLOptions = options
}

if agent.MongoDBOptions != nil {
options := &MongoDBOptions{}
*options = *agent.MongoDBOptions
options.TLSCertificateKey, err = handler(agent.MongoDBOptions.TLSCertificateKey)
agent.MongoDBOptions.TLSCertificateKey, err = handler(agent.MongoDBOptions.TLSCertificateKey)
if err != nil {
logrus.Warning(err)
}
options.TLSCertificateKeyFilePassword, err = handler(agent.MongoDBOptions.TLSCertificateKeyFilePassword)
agent.MongoDBOptions.TLSCertificateKeyFilePassword, err = handler(agent.MongoDBOptions.TLSCertificateKeyFilePassword)
if err != nil {
logrus.Warning(err)
}
agent.MongoDBOptions = options
}

if agent.AzureOptions != nil {
options := &AzureOptions{}
*options = *agent.AzureOptions
options.ClientID, err = handler(agent.AzureOptions.ClientID)
agent.AzureOptions.ClientID, err = handler(agent.AzureOptions.ClientID)
if err != nil {
logrus.Warning(err)
}
options.ClientSecret, err = handler(agent.AzureOptions.ClientSecret)
agent.AzureOptions.ClientSecret, err = handler(agent.AzureOptions.ClientSecret)
if err != nil {
logrus.Warning(err)
}
options.SubscriptionID, err = handler(agent.AzureOptions.SubscriptionID)
agent.AzureOptions.SubscriptionID, err = handler(agent.AzureOptions.SubscriptionID)
if err != nil {
logrus.Warning(err)
}
options.TenantID, err = handler(agent.AzureOptions.TenantID)
agent.AzureOptions.TenantID, err = handler(agent.AzureOptions.TenantID)
if err != nil {
logrus.Warning(err)
}
agent.AzureOptions = options
}

return agent
Expand Down

0 comments on commit f955040

Please sign in to comment.