(ctx context.Context, enterpriseID string, param params.UpdateEntityParams)
| 168 | } |
| 169 | |
| 170 | func (s *sqlDatabase) UpdateEnterprise(ctx context.Context, enterpriseID string, param params.UpdateEntityParams) (newParams params.Enterprise, err error) { |
| 171 | var rowsAffected int64 |
| 172 | defer func() { |
| 173 | if err == nil && rowsAffected > 0 { |
| 174 | s.sendNotify(common.EnterpriseEntityType, common.UpdateOperation, newParams) |
| 175 | } |
| 176 | }() |
| 177 | var enterprise Enterprise |
| 178 | err = s.conn.Transaction(func(tx *gorm.DB) error { |
| 179 | var err error |
| 180 | enterprise, err = s.getEnterpriseByID(ctx, tx, enterpriseID, "Endpoint") |
| 181 | if err != nil { |
| 182 | return fmt.Errorf("error fetching enterprise: %w", err) |
| 183 | } |
| 184 | |
| 185 | if enterprise.EndpointName == nil { |
| 186 | return fmt.Errorf("error enterprise has no endpoint: %w", runnerErrors.ErrUnprocessable) |
| 187 | } |
| 188 | |
| 189 | updates := make(map[string]interface{}) |
| 190 | |
| 191 | if err := s.updateEntityCredentials(ctx, tx, &enterprise, param.CredentialsName, updates); err != nil { |
| 192 | return err |
| 193 | } |
| 194 | |
| 195 | if param.WebhookSecret != "" { |
| 196 | // Decrypt existing secret to compare |
| 197 | existingSecret, err := util.Unseal(enterprise.WebhookSecret, []byte(s.cfg.Passphrase)) |
| 198 | if err != nil { |
| 199 | return fmt.Errorf("failed to decrypt existing webhook secret: %w", err) |
| 200 | } |
| 201 | // Only update if the webhook secret has changed |
| 202 | if string(existingSecret) != param.WebhookSecret { |
| 203 | secret, err := util.Seal([]byte(param.WebhookSecret), []byte(s.cfg.Passphrase)) |
| 204 | if err != nil { |
| 205 | return fmt.Errorf("error encoding secret: %w", err) |
| 206 | } |
| 207 | updates["webhook_secret"] = secret |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | if param.PoolManagerStatus != nil { |
| 212 | if param.PoolManagerStatus.IsRunning != enterprise.PoolManagerRunning { |
| 213 | updates["pool_manager_running"] = param.PoolManagerStatus.IsRunning |
| 214 | } |
| 215 | if param.PoolManagerStatus.FailureReason != enterprise.PoolManagerFailureReason { |
| 216 | updates["pool_manager_failure_reason"] = param.PoolManagerStatus.FailureReason |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | if param.PoolBalancerType != "" && param.PoolBalancerType != enterprise.PoolBalancerType { |
| 221 | updates["pool_balancer_type"] = param.PoolBalancerType |
| 222 | } |
| 223 | |
| 224 | if param.AgentMode != nil && *param.AgentMode != enterprise.AgentMode { |
| 225 | updates["agent_mode"] = *param.AgentMode |
| 226 | } |
| 227 |
no test coverage detected