Skip to content

Commit e717aae

Browse files
authored
feat: implement variable set (#1344)
1 parent d8a9ecf commit e717aae

34 files changed

+4403
-22
lines changed

api/openapispec/docs.go

Lines changed: 979 additions & 0 deletions
Large diffs are not rendered by default.

api/openapispec/swagger.json

Lines changed: 979 additions & 0 deletions
Large diffs are not rendered by default.

api/openapispec/swagger.yaml

Lines changed: 643 additions & 0 deletions
Large diffs are not rendered by default.

pkg/domain/constant/global.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
ResourcePageSizeLarge = 1000
2828
CommonPageDefault = 1
2929
CommonPageSizeDefault = 10
30+
CommonMaxResultLimit = 10000
3031
SortByCreateTimestamp = "createTimestamp"
3132
SortByModifiedTimestamp = "modifiedTimestamp"
3233
SortByName = "name"

pkg/domain/constant/variable.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package constant
2+
3+
import "errors"
4+
5+
var (
6+
ErrInvalidVariableName = errors.New("variable name can only have alphanumeric characters and underscores with [a-zA-Z0-9_]")
7+
ErrInvalidVariableType = errors.New("invalid variable type, only PlainText and CipherText supported")
8+
ErrEmptyVariableSet = errors.New("variable set should not be empty")
9+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package constant
2+
3+
import "errors"
4+
5+
var (
6+
ErrInvalidVariableSetName = errors.New("variable set name can only have alphanumeric characters and underscores with [a-zA-Z0-9_]")
7+
ErrEmptyVariableSetLabels = errors.New("variable set labels should not be empty")
8+
)

pkg/domain/entity/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type Pagination struct {
66
}
77

88
type SortOptions struct {
9-
Field string
10-
Ascending bool
9+
Field string
10+
Ascending bool
11+
Descending bool
1112
}

pkg/domain/entity/variable.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package entity
2+
3+
import "errors"
4+
5+
type VariableType string
6+
7+
const (
8+
PlainTextType VariableType = "PlainText"
9+
CipherTextType VariableType = "CipherText"
10+
)
11+
12+
// Variable represents a specific configuration code variable,
13+
// which usually includes the global configuration for Terraform providers like
14+
// api host, access key and secret key.
15+
type Variable struct {
16+
// Name is the name of the variable.
17+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
18+
// Value is the value of the variable.
19+
Value string `yaml:"value,omitempty" json:"value,omitempty"`
20+
// Type is the text type of the variable.
21+
Type VariableType `yaml:"type,omitempty" json:"type,omitempty"`
22+
// VariableSet is the variable set to which the variable belongs.
23+
VariableSet string `yaml:"variableSet,omitempty" json:"variableSet,omitempty"`
24+
}
25+
26+
// VariableFilter represents the filter conditions to list variables.
27+
type VariableFilter struct {
28+
Name string
29+
VariableSet string
30+
Pagination *Pagination
31+
FetchAll bool
32+
}
33+
34+
// VariableListResult represents the result of listing variables.
35+
type VariableListResult struct {
36+
Variables []*Variable
37+
Total int
38+
}
39+
40+
// Validate checks if the variable is valid.
41+
func (v *Variable) Validate() error {
42+
if v == nil {
43+
return errors.New("variable is nil")
44+
}
45+
46+
if v.Name == "" {
47+
return errors.New("empty variable name")
48+
}
49+
50+
if v.Type != PlainTextType && v.Type != CipherTextType {
51+
return errors.New("invalid variable type")
52+
}
53+
54+
if v.VariableSet == "" {
55+
return errors.New("empty variable set name")
56+
}
57+
58+
return nil
59+
}

pkg/domain/entity/variable_set.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package entity
2+
3+
import "errors"
4+
5+
// VariableSet represents a set of the global configuration variables.
6+
type VariableSet struct {
7+
// Name is the name of the variable set.
8+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
9+
// Labels clarifies the scope of the variable set.
10+
Labels map[string]string `yaml:"labels,omitempty" json:"labels,omitempty"`
11+
}
12+
13+
// VariableSetFilter represents the filter conditions to list variable sets.
14+
type VariableSetFilter struct {
15+
Name string
16+
Pagination *Pagination
17+
FetchAll bool
18+
}
19+
20+
// VariableSetListResult represents the result of listing variable sets.
21+
type VariableSetListResult struct {
22+
VariableSets []*VariableSet
23+
Total int
24+
}
25+
26+
// Validate checks if the variable set is valid.
27+
func (vs *VariableSet) Validate() error {
28+
if vs == nil {
29+
return errors.New("variable set is nil")
30+
}
31+
32+
if vs.Name == "" {
33+
return errors.New("empty variable set name")
34+
}
35+
36+
if len(vs.Labels) == 0 {
37+
return errors.New("empty variable set labels")
38+
}
39+
40+
return nil
41+
}

pkg/domain/repository/repository.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,33 @@ type RunRepository interface {
152152
// List retrieves all existing run.
153153
List(ctx context.Context, filter *entity.RunFilter, sortOptions *entity.SortOptions) (*entity.RunListResult, error)
154154
}
155+
156+
// VariableSetRepository is an interface that defines the repository operations
157+
// for variable sets. It follows the principles of domain-driven design (DDD).
158+
type VariableSetRepository interface {
159+
// Create creates a new variable set.
160+
Create(ctx context.Context, vs *entity.VariableSet) error
161+
// Delete deletes a variable set by its name.
162+
Delete(ctx context.Context, name string) error
163+
// Update updates an existing variable set.
164+
Update(ctx context.Context, vs *entity.VariableSet) error
165+
// Get retrieves a variable set by its name.
166+
Get(ctx context.Context, name string) (*entity.VariableSet, error)
167+
// List retrieves existing variable sets with filter and sort options.
168+
List(ctx context.Context, filter *entity.VariableSetFilter, sortOptions *entity.SortOptions) (*entity.VariableSetListResult, error)
169+
}
170+
171+
// VariableRepository is an interface that defines the repository operations
172+
// for variables. It follows the principles of domain-driven design (DDD).
173+
type VariableRepository interface {
174+
// Create creates a new variable.
175+
Create(ctx context.Context, v *entity.Variable) error
176+
// Delete deletes a variable by its name and the variable set it belongs to.
177+
Delete(ctx context.Context, name, variableSet string) error
178+
// Update updates an existing variable.
179+
Update(ctx context.Context, v *entity.Variable) error
180+
// Get retrieves a variable by its name and the variable set it belogs to.
181+
Get(ctx context.Context, name, variableSet string) (*entity.Variable, error)
182+
// List retrieves existing variable with filter and sort options.
183+
List(ctx context.Context, filter *entity.VariableFilter, sortOptions *entity.SortOptions) (*entity.VariableListResult, error)
184+
}

0 commit comments

Comments
 (0)