continuous-integration/drone Build is failing
Migrate the workspace to React and Ant Design, improve account forms and responsive layouts, support outbound diagnostics and SSH fingerprint confirmation, and persist the management startup port. Preserve database migrations, remove S3 settings storage, and improve gateway audit handling.
33 lines
1.4 KiB
Go
33 lines
1.4 KiB
Go
package model
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
const DefaultProject = "默认项目"
|
|
const DefaultEnvironment = "test"
|
|
|
|
// ResourceScope is metadata shared by independently stored configurations.
|
|
type ResourceScope struct {
|
|
Project string `json:"project,omitempty"`
|
|
Environment string `json:"environment,omitempty"`
|
|
}
|
|
|
|
func ValidateScope(project, environment string) error {
|
|
if len(project) > 100 || !utf8.ValidString(project) || strings.ContainsAny(project, "\r\n\x00") || project != strings.TrimSpace(project) || project == "__unassigned__" {
|
|
return errors.New("project must contain at most 100 UTF-8 bytes without surrounding whitespace or control characters")
|
|
}
|
|
if len(environment) > 100 || !utf8.ValidString(environment) || strings.ContainsAny(environment, "\r\n\x00") || environment != strings.TrimSpace(environment) || environment == "__unassigned__" {
|
|
return errors.New("environment must contain at most 100 UTF-8 bytes without surrounding whitespace or control characters")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Empty filters mean all; the explicit sentinel selects legacy/unassigned data.
|
|
func (f ResourceScope) Matches(project, environment string) bool {
|
|
return (f.Project == "" || f.Project == project || f.Project == "__unassigned__" && project == "") &&
|
|
(f.Environment == "" || f.Environment == environment || f.Environment == "__unassigned__" && environment == "")
|
|
}
|