Skip to content

Commit

Permalink
add api endpoint for commitment merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Varsius committed Feb 20, 2025
1 parent 866ed53 commit a6f38ab
Show file tree
Hide file tree
Showing 13 changed files with 766 additions and 158 deletions.
11 changes: 11 additions & 0 deletions docs/users/api-spec-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,17 @@ Returns 201 (Created) on success. Result is a JSON document like:
The `commitment` object has the same structure as the `commitments[]` objects in `GET /v1/domains/:domain_id/projects/:project_id/commitments`.
If `confirm_by` was given, a successful response will include the `confirmed_at` timestamp.

### POST /v1/domains/:domain\_id/projects/:project\_id/commitments/merge

Merges active commitments on the same resource within the given project. The newly created merged commitment receives the latest expiration date of all given commitments. Requires a project-admin token, and a request body that is a JSON document like:

```json
{
"commitment_ids": [1,2,5]
}
```
Returns 202 (Accepted) on success, and returns the merged commitment as a JSON document.

### POST /v1/domains/:domain\_id/projects/:project\_id/commitments/can-confirm

Checks if a new commitment within the given project could be confirmed immediately.
Expand Down
18 changes: 10 additions & 8 deletions internal/api/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"fmt"
"strconv"

"github.com/sapcc/limes/internal/db"

"github.com/sapcc/go-api-declarations/cadf"
"github.com/sapcc/go-api-declarations/limes"
limesrates "github.com/sapcc/go-api-declarations/limes/rates"
Expand Down Expand Up @@ -101,12 +103,12 @@ func (t rateLimitEventTarget) Render() cadf.Resource {
// commitmentEventTarget contains the structure for rendering a cadf.Event.Target for
// changes regarding commitments.
type commitmentEventTarget struct {
DomainID string
DomainName string
ProjectID string
ProjectName string
SupersededCommitment *limesresources.Commitment
Commitments []limesresources.Commitment // must have at least one entry
DomainID string
DomainName string
ProjectID string
ProjectName string
Commitments []limesresources.Commitment // must have at least one entry
WorkflowContext *db.CommitmentWorkflowContext
}

// Render implements the audittools.Target interface.
Expand All @@ -131,8 +133,8 @@ func (t commitmentEventTarget) Render() cadf.Resource {
attachment := must.Return(cadf.NewJSONAttachment(name, commitment))
res.Attachments = append(res.Attachments, attachment)
}
if t.SupersededCommitment != nil {
attachment := must.Return(cadf.NewJSONAttachment("superseded-payload", *t.SupersededCommitment))
if t.WorkflowContext != nil {
attachment := must.Return(cadf.NewJSONAttachment("context-payload", *t.WorkflowContext))
res.Attachments = append(res.Attachments, attachment)
}
return res
Expand Down
Loading

0 comments on commit a6f38ab

Please sign in to comment.