-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
6,033 additions
and
2,521 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package entity | ||
|
||
import "errors" | ||
|
||
const ( | ||
PlainTextType string = "PlainText" | ||
CipherTextType string = "CipherText" | ||
) | ||
|
||
// Variable represents the specific configuration code variable, | ||
// which usually includes the global configurations for Terraform providers like | ||
// api host, ak and sk. | ||
type Variable struct { | ||
// VariableKey is the access path for the variable. | ||
VariableKey string `yaml:"variableKey,omitempty" json:"variableKey,omitempty"` | ||
// Value is the value of the variable. | ||
Value string `yaml:"value,omitempty" json:"value,omitempty"` | ||
// Type is the type of the variable. | ||
Type string `yaml:"type,omitempty" json:"type,omitempty"` | ||
// Labels clarifies the scope of the variable. | ||
Labels map[string]string `yaml:"labels,omitempty" json:"labels,omitempty"` | ||
// Fqn is the fully qualified name of the variable. | ||
Fqn string `yaml:"fqn,omitempty" json:"fqn,omitempty"` | ||
} | ||
|
||
// VariableFilter represents the filter conditions to list variables. | ||
type VariableFilter struct { | ||
Key string | ||
Pagination *Pagination | ||
} | ||
|
||
// VariableListResult represents the result of listing variables. | ||
type VariableListResult struct { | ||
Variables []*Variable | ||
Total int | ||
} | ||
|
||
// Validate checks if the variable is valid. | ||
// It returns an error if the variable is not valid. | ||
func (v *Variable) Validate() error { | ||
if v == nil { | ||
return errors.New("variable is nil") | ||
} | ||
|
||
if v.VariableKey == "" { | ||
return errors.New("empty variable key") | ||
} | ||
|
||
if v.Type != PlainTextType && v.Type != CipherTextType { | ||
return errors.New("invalid variable type") | ||
} | ||
|
||
if v.Fqn == "" { | ||
return errors.New("empty fqn") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package entity | ||
|
||
import "errors" | ||
|
||
// VariableLabels records the labels of the specific configuration code variable, | ||
// and the labels are sorted in ascending order of priority. | ||
type VariableLabels struct { | ||
// VariableKey is the access path for the variable. | ||
VariableKey string `yaml:"variableKey,omitempty" json:"variableKey,omitempty"` | ||
// Labels is the list of variable labels, which should be sorted | ||
// in ascending order of priority. | ||
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"` | ||
} | ||
|
||
// VariableLabelsFilter represents the filter conditions to list variable labels. | ||
type VariableLabelsFilter struct { | ||
Labels []string | ||
Pagination *Pagination | ||
} | ||
|
||
// VariableLabelsListResult represents the result of listing variable labels. | ||
type VariableLabelsListResult struct { | ||
VariableLabels []*VariableLabels | ||
Total int | ||
} | ||
|
||
// Validate checks if the variable labels are valid. | ||
// It returns an error if the variable labels are not valid. | ||
func (vl *VariableLabels) Validate() error { | ||
if vl == nil { | ||
return errors.New("nil variable labels") | ||
} | ||
|
||
if vl.VariableKey == "" { | ||
return errors.New("empty key for variable labels") | ||
} | ||
|
||
if len(vl.Labels) == 0 { | ||
return errors.New("empty variable labels") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package request | ||
|
||
import "net/http" | ||
|
||
// CreateVariableLabelsRequest represents the create request structure | ||
// for variable labels. | ||
type CreateVariableLabelsRequest struct { | ||
// VariableKey is the access path for the variable. | ||
VariableKey string `json:"variableKey" binding:"required"` | ||
// Labels is the list of variable labels, which should be sorted | ||
// in ascending order of priority. | ||
Labels []string `json:"labels" binding:"required"` | ||
} | ||
|
||
// UpdateVariableLabelsRequest represents the update request structure | ||
// for variable labels. | ||
type UpdateVariableLabelsRequest struct { | ||
// VariableKey is the access path for the variable. | ||
VariableKey string `json:"variableKey" binding:"required"` | ||
// Labels is the list of variable labels, which should be sorted | ||
// in ascending order of priority. | ||
Labels []string `json:"labels" binding:"required"` | ||
} | ||
|
||
func (payload *CreateVariableLabelsRequest) Decode(r *http.Request) error { | ||
return decode(r, payload) | ||
} | ||
|
||
func (payload *UpdateVariableLabelsRequest) Decode(r *http.Request) error { | ||
return decode(r, payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package request | ||
|
||
import "net/http" | ||
|
||
// CreateVariableSetRequest represents the create request structure | ||
// for a variable in the variable set. | ||
type CreateVariableSetRequest struct { | ||
// VariableKey is the access path for the variable. | ||
VariableKey string `json:"variableKey" binding:"required"` | ||
// Value is the value of the variable. | ||
Value string `json:"value" binding:"required"` | ||
// Type is the type of the variable. | ||
Type string `json:"type" binding:"required"` | ||
// Labels clarifies the scope of the variable. | ||
Labels map[string]string `json:"labels,omitempty"` | ||
} | ||
|
||
// UpdateVariableSetRequest represents the update request structure | ||
// for a variable in the variable set. | ||
type UpdateVariableSetRequest struct { | ||
// VariableKey is the access path for the variable. | ||
VariableKey string `json:"variableKey" binding:"required"` | ||
// Value is the value of the variable. | ||
Value string `json:"value" binding:"required"` | ||
// Type is the type of the variable. | ||
Type string `json:"type" binding:"required"` | ||
// Labels clarifies the scope of the variable. | ||
Labels map[string]string `json:"labels" binding:"required"` | ||
// Fqn is the fully qualified name of the variable. | ||
Fqn string `json:"fqn" binding:"required"` | ||
} | ||
|
||
// ListVariableSetRequest represents the list request structure | ||
// for variables matched to the labels in the variable set. | ||
type ListVariableSetRequest struct { | ||
// Labels clarifies the scope of the variables. | ||
Labels map[string]string `json:"labels" binding:"required"` | ||
} | ||
|
||
func (payload *CreateVariableSetRequest) Decode(r *http.Request) error { | ||
return decode(r, payload) | ||
} | ||
|
||
func (payload *UpdateVariableSetRequest) Decode(r *http.Request) error { | ||
return decode(r, payload) | ||
} | ||
|
||
func (payload *ListVariableSetRequest) Decode(r *http.Request) error { | ||
return decode(r, payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package response | ||
|
||
import "kusionstack.io/kusion/pkg/domain/entity" | ||
|
||
type PaginatedVariableResponse struct { | ||
Variables []*entity.Variable `json:"variables"` | ||
Total int `json:"total"` | ||
CurrentPage int `json:"currentPage"` | ||
PageSize int `json:"pageSize"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package response | ||
|
||
import "kusionstack.io/kusion/pkg/domain/entity" | ||
|
||
type PaginatedVariableLabelsResponse struct { | ||
VariableLabels []*entity.VariableLabels `json:"variableLabels"` | ||
Total int `json:"total"` | ||
CurrentPage int `json:"currentPage"` | ||
PageSize int `json:"pageSize"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.