mirror of
https://github.com/rancher/types.git
synced 2025-06-23 04:07:03 +00:00
Fix secret types
This commit is contained in:
parent
cdfe5ebb78
commit
ee9dc3fbfa
@ -2,9 +2,9 @@ package schema
|
||||
|
||||
import (
|
||||
"github.com/rancher/norman/types"
|
||||
"github.com/rancher/norman/types/convert"
|
||||
m "github.com/rancher/norman/types/mapper"
|
||||
"github.com/rancher/types/apis/project.cattle.io/v3"
|
||||
"github.com/rancher/types/mapper"
|
||||
"k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
@ -13,48 +13,40 @@ func secretTypes(schemas *types.Schemas) *types.Schemas {
|
||||
AddMapperForType(&Version, v1.Secret{},
|
||||
m.SetValue{
|
||||
Field: "type",
|
||||
To: "type",
|
||||
IfEq: "kubernetes.io/service-account-token",
|
||||
Value: "serviceAccountToken",
|
||||
},
|
||||
m.SetValue{
|
||||
Field: "type",
|
||||
To: "type",
|
||||
IfEq: "kubernetes.io/dockercfg",
|
||||
Value: "dockerCredential",
|
||||
},
|
||||
m.SetValue{
|
||||
Field: "type",
|
||||
To: "type",
|
||||
IfEq: "kubernetes.io/dockerconfigjson",
|
||||
Value: "dockerCredential",
|
||||
},
|
||||
m.SetValue{
|
||||
Field: "type",
|
||||
To: "type",
|
||||
IfEq: "kubernetes.io/basic-auth",
|
||||
Value: "basicAuth",
|
||||
},
|
||||
m.SetValue{
|
||||
Field: "type",
|
||||
To: "type",
|
||||
IfEq: "kubernetes.io/ssh-auth",
|
||||
Value: "sshAuth",
|
||||
},
|
||||
m.SetValue{
|
||||
Field: "type",
|
||||
To: "type",
|
||||
IfEq: "kubernetes.io/ssh-auth",
|
||||
Value: "sshAuth",
|
||||
},
|
||||
m.SetValue{
|
||||
Field: "type",
|
||||
To: "type",
|
||||
IfEq: "kubernetes.io/tls",
|
||||
Value: "certificate",
|
||||
},
|
||||
&m.Move{From: "type", To: "kind"},
|
||||
&mapper.NamespaceIDMapper{},
|
||||
m.Condition{
|
||||
Field: "kind",
|
||||
Value: "sshAuth",
|
||||
@ -72,6 +64,7 @@ func secretTypes(schemas *types.Schemas) *types.Schemas {
|
||||
Value: "sshAuth",
|
||||
IgnoreDefinition: true,
|
||||
},
|
||||
m.AnnotationField{Field: "fingerprint", IgnoreDefinition: true},
|
||||
},
|
||||
},
|
||||
m.Condition{
|
||||
@ -190,10 +183,6 @@ func secretTypes(schemas *types.Schemas) *types.Schemas {
|
||||
From: "data/ca.crt",
|
||||
To: "caCrt",
|
||||
},
|
||||
m.UntypedMove{
|
||||
From: "data/namespace",
|
||||
To: "namespace",
|
||||
},
|
||||
m.UntypedMove{
|
||||
From: "data/token",
|
||||
To: "token",
|
||||
@ -202,10 +191,6 @@ func secretTypes(schemas *types.Schemas) *types.Schemas {
|
||||
Field: "caCrt",
|
||||
IgnoreDefinition: true,
|
||||
},
|
||||
m.Base64{
|
||||
Field: "namespace",
|
||||
IgnoreDefinition: true,
|
||||
},
|
||||
m.Base64{
|
||||
Field: "token",
|
||||
IgnoreDefinition: true,
|
||||
@ -232,24 +217,49 @@ func secretTypes(schemas *types.Schemas) *types.Schemas {
|
||||
return f
|
||||
})
|
||||
}, projectOverride{}).
|
||||
MustImportAndCustomize(&Version, v3.ServiceAccountToken{}, func(schema *types.Schema) {
|
||||
schema.BaseType = "secret"
|
||||
schema.Mapper = schemas.Schema(&Version, "secret").Mapper
|
||||
}, projectOverride{}).
|
||||
MustImportAndCustomize(&Version, v3.DockerCredential{}, func(schema *types.Schema) {
|
||||
schema.BaseType = "secret"
|
||||
schema.Mapper = schemas.Schema(&Version, "secret").Mapper
|
||||
}, projectOverride{}).
|
||||
MustImportAndCustomize(&Version, v3.Certificate{}, func(schema *types.Schema) {
|
||||
schema.BaseType = "secret"
|
||||
schema.Mapper = schemas.Schema(&Version, "secret").Mapper
|
||||
}, projectOverride{}).
|
||||
MustImportAndCustomize(&Version, v3.BasicAuth{}, func(schema *types.Schema) {
|
||||
schema.BaseType = "secret"
|
||||
schema.Mapper = schemas.Schema(&Version, "secret").Mapper
|
||||
}, projectOverride{}).
|
||||
MustImportAndCustomize(&Version, v3.SSHAuth{}, func(schema *types.Schema) {
|
||||
schema.BaseType = "secret"
|
||||
schema.Mapper = schemas.Schema(&Version, "secret").Mapper
|
||||
}, projectOverride{})
|
||||
Init(func(schemas *types.Schemas) *types.Schemas {
|
||||
return addSecretSubtypes(schemas,
|
||||
v3.ServiceAccountToken{},
|
||||
v3.DockerCredential{},
|
||||
v3.Certificate{},
|
||||
v3.BasicAuth{},
|
||||
v3.SSHAuth{})
|
||||
})
|
||||
}
|
||||
|
||||
func addSecretSubtypes(schemas *types.Schemas, objs ...interface{}) *types.Schemas {
|
||||
namespaced := map[string]bool{
|
||||
"secret": true,
|
||||
}
|
||||
|
||||
for _, obj := range objs {
|
||||
schemas.MustImportAndCustomize(&Version, obj, func(schema *types.Schema) {
|
||||
schema.BaseType = "secret"
|
||||
schema.Mapper = schemas.Schema(&Version, "secret").Mapper
|
||||
namespaced[schema.ID] = true
|
||||
}, projectOverride{})
|
||||
}
|
||||
|
||||
for name := range namespaced {
|
||||
baseSchema := schemas.Schema(&Version, name)
|
||||
|
||||
newFields := map[string]types.Field{}
|
||||
for name, field := range baseSchema.ResourceFields {
|
||||
if name == "namespaceId" {
|
||||
field.Required = false
|
||||
}
|
||||
newFields[name] = field
|
||||
}
|
||||
|
||||
schema := *baseSchema
|
||||
schema.ID = "namespaced" + convert.Capitalize(schema.ID)
|
||||
schema.PluralName = "namespaced" + convert.Capitalize(schema.PluralName)
|
||||
schema.CodeName = "Namespaced" + schema.CodeName
|
||||
schema.CodeNamePlural = "Namespaced" + schema.CodeNamePlural
|
||||
schemas.AddSchema(schema)
|
||||
|
||||
baseSchema.ResourceFields = newFields
|
||||
}
|
||||
|
||||
return schemas
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"github.com/rancher/norman/types"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
@ -62,6 +63,8 @@ type Link struct {
|
||||
}
|
||||
|
||||
type ServiceAccountToken struct {
|
||||
types.Namespaced
|
||||
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
@ -70,48 +73,63 @@ type ServiceAccountToken struct {
|
||||
Token string `json:"token" norman:"writeOnly"`
|
||||
CACRT string `json:"caCrt"`
|
||||
}
|
||||
type NamespacedServiceAccountToken ServiceAccountToken
|
||||
|
||||
type DockerCredential struct {
|
||||
types.Namespaced
|
||||
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
Registries map[string]RegistryCredential `json:"registries"`
|
||||
}
|
||||
type NamespacedDockerCredential DockerCredential
|
||||
|
||||
type RegistryCredential struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password" norman:"writeOnly"`
|
||||
Auth string `json:"auth"`
|
||||
Auth string `json:"auth" norman:"writeOnly"`
|
||||
}
|
||||
|
||||
type Certificate struct {
|
||||
types.Namespaced
|
||||
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
Certs string `json:"certs"`
|
||||
Key string `json:"key" norman:"writeOnly"`
|
||||
CertFingerprint string `json:"certFingerprint"`
|
||||
CN string `json:"cn"`
|
||||
Version string `json:"version"`
|
||||
Issuer string `json:"issuer"`
|
||||
IssuedAt string `json:"issuedAt"`
|
||||
Algorithm string `json:"Algorithm"`
|
||||
SerialNumber string `json:"serialNumber"`
|
||||
KeySize string `json:"keySize"`
|
||||
SubjectAlternativeNames string `json:"subjectAlternativeNames"`
|
||||
Certs string `json:"certs"`
|
||||
Key string `json:"key" norman:"writeOnly"`
|
||||
|
||||
CertFingerprint string `json:"certFingerprint" norman:"nocreate,noupdate"`
|
||||
CN string `json:"cn" norman:"nocreate,noupdate"`
|
||||
Version string `json:"version" norman:"nocreate,noupdate"`
|
||||
Issuer string `json:"issuer" norman:"nocreate,noupdate"`
|
||||
IssuedAt string `json:"issuedAt" norman:"nocreate,noupdate"`
|
||||
Algorithm string `json:"algorithm" norman:"nocreate,noupdate"`
|
||||
SerialNumber string `json:"serialNumber" norman:"nocreate,noupdate"`
|
||||
KeySize string `json:"keySize" norman:"nocreate,noupdate"`
|
||||
SubjectAlternativeNames string `json:"subjectAlternativeNames" norman:"nocreate,noupdate"`
|
||||
}
|
||||
type NamespacedCertificate Certificate
|
||||
|
||||
type BasicAuth struct {
|
||||
types.Namespaced
|
||||
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password" norman:"writeOnly"`
|
||||
}
|
||||
type NamespacedBasicAuth BasicAuth
|
||||
|
||||
type SSHAuth struct {
|
||||
types.Namespaced
|
||||
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
PrivateKey string `json:"privateKey"`
|
||||
PrivateKey string `json:"privateKey" norman:"writeOnly"`
|
||||
Fingerprint string `json:"certFingerprint" norman:"nocreate,noupdate"`
|
||||
}
|
||||
type NamespacedSSHAuth SSHAuth
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
|
||||
var (
|
||||
ProjectTypes = []string{
|
||||
projectClient.RegistryCredentialType,
|
||||
projectClient.BasicAuthType,
|
||||
projectClient.CertificateType,
|
||||
projectClient.DockerCredentialType,
|
||||
|
@ -75,6 +75,7 @@ func Set(data map[string]interface{}) {
|
||||
if i, err := convert.ToTimestamp(val); err == nil {
|
||||
if time.Unix(i/1000, 0).Add(5 * time.Second).Before(time.Now()) {
|
||||
data["state"] = "active"
|
||||
data["transitioning"] = "no"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user