ContainerImage.Pinniped/internal/registry/credentialrequest/conversions.go
Matt Moyer 2d4d7e588a
Add Go vanity import paths.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
2020-09-18 14:56:24 -05:00

55 lines
1.8 KiB
Go

// Copyright 2020 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package credentialrequest
import (
loginapi "go.pinniped.dev/generated/1.19/apis/login"
pinnipedapi "go.pinniped.dev/generated/1.19/apis/pinniped"
)
func convertToLoginAPI(input *pinnipedapi.CredentialRequest) *loginapi.TokenCredentialRequest {
if input == nil {
return nil
}
result := loginapi.TokenCredentialRequest{}
result.ObjectMeta = input.ObjectMeta
if input.Spec.Token != nil {
result.Spec.Token = input.Spec.Token.Value
}
result.Status.Message = input.Status.Message
if input.Status.Credential != nil {
result.Status.Credential = &loginapi.ClusterCredential{
ExpirationTimestamp: input.Status.Credential.ExpirationTimestamp,
Token: input.Status.Credential.Token,
ClientCertificateData: input.Status.Credential.ClientCertificateData,
ClientKeyData: input.Status.Credential.ClientKeyData,
}
}
return &result
}
func convertFromLoginAPI(input *loginapi.TokenCredentialRequest) *pinnipedapi.CredentialRequest {
if input == nil {
return nil
}
result := pinnipedapi.CredentialRequest{}
result.ObjectMeta = input.ObjectMeta
if input.Spec.Token != "" {
result.Spec.Type = pinnipedapi.TokenCredentialType
result.Spec.Token = &pinnipedapi.CredentialRequestTokenCredential{Value: input.Spec.Token}
}
result.Status.Message = input.Status.Message
if input.Status.Credential != nil {
result.Status.Credential = &pinnipedapi.CredentialRequestCredential{
ExpirationTimestamp: input.Status.Credential.ExpirationTimestamp,
Token: input.Status.Credential.Token,
ClientCertificateData: input.Status.Credential.ClientCertificateData,
ClientKeyData: input.Status.Credential.ClientKeyData,
}
}
return &result
}