generated from keboola/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_row.go
112 lines (99 loc) · 4.22 KB
/
storage_row.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package keboola
import (
"context"
"github.com/keboola/go-utils/pkg/orderedmap"
"github.com/keboola/go-client/pkg/request"
)
// RowID is id of configuration row.
type RowID string
func (v RowID) String() string {
return string(v)
}
// ConfigRowKey is a unique identifier of ConfigRow.
type ConfigRowKey struct {
BranchID BranchID `json:"-"`
ComponentID ComponentID `json:"-"`
ConfigID ConfigID `json:"-"`
ID RowID `json:"id" writeas:"rowId" writeoptional:"true"`
}
func (k ConfigRowKey) ObjectID() any {
return k.ID
}
// ConfigRow https://keboola.docs.apiary.io/#reference/components-and-configurations/component-configurations/list-configurations
type ConfigRow struct {
ConfigRowKey
Name string `json:"name"`
Description string `json:"description"`
ChangeDescription string `json:"changeDescription"`
IsDisabled bool `json:"isDisabled"`
Version int `json:"version" readonly:"true"`
State *orderedmap.OrderedMap `json:"state" readonly:"true"`
Content *orderedmap.OrderedMap `json:"configuration"`
}
// GetConfigRowRequest https://kebooldocs.apiary.io/#reference/components-and-configurations/manage-configuration-rows/row-detail
func (a *AuthorizedAPI) GetConfigRowRequest(key ConfigRowKey) request.APIRequest[*ConfigRow] {
row := &ConfigRow{}
row.BranchID = key.BranchID
row.ComponentID = key.ComponentID
row.ConfigID = key.ConfigID
req := a.
newRequest(StorageAPI).
WithResult(row).
WithGet("branch/{branchId}/components/{componentId}/configs/{configId}/rows/{rowId}").
AndPathParam("branchId", key.BranchID.String()).
AndPathParam("componentId", key.ComponentID.String()).
AndPathParam("configId", key.ConfigID.String()).
AndPathParam("rowId", key.ID.String())
return request.NewAPIRequest(row, req)
}
// CreateConfigRowRequest https://kebooldocs.apiary.io/#reference/components-and-configurations/create-or-list-configuration-rows/create-development-branch-configuration-row
func (a *AuthorizedAPI) CreateConfigRowRequest(row *ConfigRow) request.APIRequest[*ConfigRow] {
// Create request
req := a.
newRequest(StorageAPI).
WithResult(row).
WithPost("branch/{branchId}/components/{componentId}/configs/{configId}/rows").
AndPathParam("branchId", row.BranchID.String()).
AndPathParam("componentId", string(row.ComponentID)).
AndPathParam("configId", string(row.ConfigID)).
WithJSONBody(request.StructToMap(row, nil)).
WithOnError(ignoreResourceAlreadyExistsError(func(ctx context.Context) error {
if result, err := a.GetConfigRowRequest(row.ConfigRowKey).Send(ctx); err == nil {
*row = *result
return nil
} else {
return err
}
}))
return request.NewAPIRequest(row, req)
}
// UpdateConfigRowRequest https://kebooldocs.apiary.io/#reference/components-and-configurations/manage-configuration-rows/update-row-for-development-branch
func (a *AuthorizedAPI) UpdateConfigRowRequest(row *ConfigRow, changedFields []string) request.APIRequest[*ConfigRow] {
// ID is required
if row.ID == "" {
panic("config row id must be set")
}
// Create request
req := a.
newRequest(StorageAPI).
WithResult(row).
WithPut("branch/{branchId}/components/{componentId}/configs/{configId}/rows/{rowId}").
AndPathParam("branchId", row.BranchID.String()).
AndPathParam("componentId", string(row.ComponentID)).
AndPathParam("configId", string(row.ConfigID)).
AndPathParam("rowId", string(row.ID)).
WithJSONBody(request.StructToMap(row, changedFields))
return request.NewAPIRequest(row, req)
}
// DeleteConfigRowRequest https://kebooldocs.apiary.io/#reference/components-and-configurations/manage-configuration-rows/update-row
func (a *AuthorizedAPI) DeleteConfigRowRequest(key ConfigRowKey) request.APIRequest[request.NoResult] {
req := a.
newRequest(StorageAPI).
WithDelete("branch/{branchId}/components/{componentId}/configs/{configId}/rows/{rowId}").
AndPathParam("branchId", key.BranchID.String()).
AndPathParam("componentId", string(key.ComponentID)).
AndPathParam("configId", string(key.ConfigID)).
AndPathParam("rowId", string(key.ID)).
WithOnError(ignoreResourceNotFoundError())
return request.NewAPIRequest(request.NoResult{}, req)
}