(connection *models.WebhookConnection, withApiKeyInfo bool)
| 254 | } |
| 255 | |
| 256 | func formatConnection(connection *models.WebhookConnection, withApiKeyInfo bool) (*WebhookConnectionResponse, errors.Error) { |
| 257 | response := &WebhookConnectionResponse{WebhookConnection: *connection} |
| 258 | response.PostIssuesEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/issues`, connection.ID) |
| 259 | response.CloseIssuesEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/issue/:issueKey/close`, connection.ID) |
| 260 | response.PostPullRequestsEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/pull_requests`, connection.ID) |
| 261 | response.PostPipelineTaskEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/cicd_tasks`, connection.ID) |
| 262 | response.PostPipelineDeployTaskEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/deployments`, connection.ID) |
| 263 | response.ClosePipelineEndpoint = fmt.Sprintf(`/rest/plugins/webhook/connections/%d/cicd_pipeline/:pipelineName/finish`, connection.ID) |
| 264 | if withApiKeyInfo { |
| 265 | db := basicRes.GetDal() |
| 266 | apiKeyName := apiKeyHelper.GenApiKeyNameForPlugin(pluginName, connection.ID) |
| 267 | apiKey, err := apiKeyHelper.GetApiKey(db, dal.Where("name = ?", apiKeyName)) |
| 268 | if err != nil { |
| 269 | if db.IsErrorNotFound(err) { |
| 270 | logger.Info("api key with name: %s not found in db", apiKeyName) |
| 271 | } else { |
| 272 | logger.Error(err, "query api key from db, name: %s", apiKeyName) |
| 273 | return nil, err |
| 274 | } |
| 275 | } else { |
| 276 | response.ApiKey = apiKey |
| 277 | response.ApiKey.RemoveHashedApiKey() // delete the hashed api key to reduce the attack surface. |
| 278 | } |
| 279 | } |
| 280 | return response, nil |
| 281 | } |
no test coverage detected