Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add kusion config item registry #879

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions pkg/config/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package config

import (
v1 "kusionstack.io/kusion/pkg/apis/core/v1"
"kusionstack.io/kusion/pkg/config/validation"
)

const (
backendCurrent = v1.ConfigBackends + "." + v1.BackendCurrent

Check failure on line 9 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendCurrent` is unused (unused)
backendConfig = v1.ConfigBackends + "." + "*"

Check failure on line 10 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendConfig` is unused (unused)
backendConfigType = backendConfig + "." + v1.BackendType

Check failure on line 11 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendConfigType` is unused (unused)
backendConfigItems = backendConfig + "." + v1.BackendConfigItems

Check failure on line 12 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendConfigItems` is unused (unused)
backendLocalPath = backendConfigItems + "." + v1.BackendLocalPath

Check failure on line 13 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendLocalPath` is unused (unused)
backendMysqlDBName = backendConfigItems + "." + v1.BackendMysqlDBName

Check failure on line 14 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendMysqlDBName` is unused (unused)
backendMysqlUser = backendConfigItems + "." + v1.BackendMysqlUser

Check failure on line 15 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendMysqlUser` is unused (unused)
backendMysqlPassword = backendConfigItems + "." + v1.BackendMysqlPassword

Check failure on line 16 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendMysqlPassword` is unused (unused)
backendMysqlHost = backendConfigItems + "." + v1.BackendMysqlHost

Check failure on line 17 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendMysqlHost` is unused (unused)
backendMysqlPort = backendConfigItems + "." + v1.BackendMysqlPort

Check failure on line 18 in pkg/config/registry.go

View workflow job for this annotation

GitHub Actions / Golang Lint

const `backendMysqlPort` is unused (unused)
backendGenericOssEndpoint = backendConfigItems + "." + v1.BackendGenericOssEndpoint
backendGenericOssAK = backendConfigItems + "." + v1.BackendGenericOssAK
backendGenericOssSK = backendConfigItems + "." + v1.BackendGenericOssSK
backendGenericOssBucket = backendConfigItems + "." + v1.BackendGenericOssBucket
backendGenericOssPrefix = backendConfigItems + "." + v1.BackendGenericOssPrefix
backendS3Region = backendConfigItems + "." + v1.BackendS3Region
)

func newRegisteredItems() map[string]*itemInfo {
return map[string]*itemInfo{
backendCurrent: {"", validation.ValidateCurrentBackend, nil},
backendConfig: {&v1.BackendConfig{}, validation.ValidateBackendConfig, validation.ValidateUnsetBackendConfig},
backendConfigType: {"", validation.ValidateBackendType, validation.ValidateUnsetBackendType},
backendConfigItems: {map[string]any{}, validation.ValidateBackendConfigItems, nil},
backendLocalPath: {"", validation.ValidateLocalBackendItem, nil},
backendMysqlDBName: {"", validation.ValidateMysqlBackendItem, nil},
backendMysqlUser: {"", validation.ValidateMysqlBackendItem, nil},
backendMysqlPassword: {"", validation.ValidateMysqlBackendItem, nil},
backendMysqlHost: {"", validation.ValidateMysqlBackendItem, nil},
backendMysqlPort: {0, validation.ValidateMysqlBackendPort, nil},
backendGenericOssEndpoint: {"", validation.ValidateGenericOssBackendItem, nil},
backendGenericOssAK: {"", validation.ValidateGenericOssBackendItem, nil},
backendGenericOssSK: {"", validation.ValidateGenericOssBackendItem, nil},
backendGenericOssBucket: {"", validation.ValidateGenericOssBackendItem, nil},
backendGenericOssPrefix: {"", validation.ValidateGenericOssBackendItem, nil},
backendS3Region: {"", validation.ValidateS3BackendItem, nil},
}
}

// itemInfo includes necessary information of the config item, which is used when getting, setting and unsetting
// the config item.
type itemInfo struct {
// zeroValue is the zero value of the type that the config item will be parsed from string to. Support string,
// int, bool, map, slice, struct and pointer of struct, the parser rule is shown as below:
// - string: keep the same
// - int: calling strconv.Atoi, e.g. "45" is valid, parsed to 45
// - bool: calling strconv.ParseBool, e.g. "true" is valid, parsed to true
// - slice, map, struct(pointer of struct): calling json.Unmarshal, zeroValue of these types must be
// initialized, e.g. map[string]any{}, nil is invalid
// For other unsupported types, calling json.Unmarshal to do the parse job, unexpected error or panic may
// happen. Please do not use them.
zeroValue any

// validateFunc is used to check the config item is valid or not to set, calling before executing real
// config setting. The unregistered config item, empty item value and invalid item value type is forbidden
// by config operator by default, which are unnecessary to check in the validateFunc.
// Please do not do any real setting job in the validateFunc.
validateFunc validation.ValidateFunc

// validateUnsetFunc is used to check the config item is valid or not to unset, calling before executing
// real config unsetting.
// Please do not do any real unsetting job in the validateUnsetFunc.
validateUnsetFunc validation.ValidateUnsetFunc
}
Loading