Fix typos, update types and add comments

Signed-off-by: Clément Blaise <clementblaise@me.com>
This commit is contained in:
Clément Blaise 2024-06-06 01:15:16 +08:00
parent f3cde1bfc8
commit c2fac0f7b2
2 changed files with 13 additions and 9 deletions

View File

@ -129,17 +129,17 @@ func GetExtraResources(req *v1beta1.RunFunctionRequest) (map[string][]resource.E
return out, nil
}
// GetCredential from the supplied request.
func GetCredential(req *v1beta1.RunFunctionRequest, name string) (resource.Credential, error) {
// GetCredentials from the supplied request.
func GetCredentials(req *v1beta1.RunFunctionRequest, name string) (resource.Credentials, error) {
cred, exists := req.GetCredentials()[name]
if !exists {
return resource.Credential{}, errors.Errorf("%s: credential not found", name)
return resource.Credentials{}, errors.Errorf("%s: credential not found", name)
}
switch t := cred.GetSource().(type) {
case *v1beta1.Credentials_CredentialData:
return resource.Credential{Type: resource.CredentialsTypeData, Data: cred.GetCredentialData().GetData()}, nil
return resource.Credentials{Type: resource.CredentialsTypeData, Data: cred.GetCredentialData().GetData()}, nil
default:
return resource.Credential{}, errors.Errorf("%s: not a supported credential source", t)
return resource.Credentials{}, errors.Errorf("%s: not a supported credential source", t)
}
}

View File

@ -57,17 +57,21 @@ type Extra struct {
Resource *unstructured.Unstructured
}
// CredentialsType is the type of credentials
// CredentialsType is the type of credentials.
type CredentialsType string
const (
// CredentialsTypeData is a Credential which of type Data
// CredentialsTypeData is a Credential of type Data.
CredentialsTypeData = "Data"
)
// Credential is a secret requested by a Function
type Credential struct {
// Credentials is a secret requested by a Function.
type Credentials struct {
// Type represents the type of credentials.
Type CredentialsType
// Data is a map of key-value pairs where the keys are strings, and the values are byte slices
// containing sensitive data.
Data map[string][]byte
}