Skip to content

Commit

Permalink
Updated Kubernetes authentication model
Browse files Browse the repository at this point in the history
  • Loading branch information
jbristowe committed Nov 18, 2020
1 parent 5c0852a commit b7e50fd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 43 deletions.
16 changes: 0 additions & 16 deletions octopusdeploy/endpoint_authentication.go

This file was deleted.

2 changes: 1 addition & 1 deletion octopusdeploy/endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type EndpointResource struct {
AadUserCredentialPassword SensitiveValue `json:"AadUserCredentialPassword,omitempty"`
AccountID string `json:"AccountId"`
ApplicationsDirectory string `json:"ApplicationsDirectory,omitempty"`
Authentication EndpointAuthentication `json:"Authentication,omitempty"`
Authentication IKubernetesAuthentication `json:"Authentication,omitempty"`
CertificateSignatureAlgorithm string `json:"CertificateSignatureAlgorithm,omitempty"`
CertificateStoreLocation string `json:"CertificateStoreLocation,omitempty"`
CertificateStoreName string `json:"CertificateStoreName,omitempty"`
Expand Down
34 changes: 17 additions & 17 deletions octopusdeploy/kubernetes_authentication.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package octopusdeploy

// kubernetesAuthentication is the base definition of Kubernetes-based
// authentication.
type kubernetesAuthentication struct {
AuthenticationType string `json:"AuthenticationType" validate:"required,oneof=KubernetesAws KubernetesAzure KubernetesCertificate KubernetesStandard None"`
}

// newKubernetesAuthentication creates and initializes a new Kubernetes-based
// authentication.
func newKubernetesAuthentication(authenticationType string) *kubernetesAuthentication {
kubernetesAuthentication := &kubernetesAuthentication{
AuthenticationType: authenticationType,
}
return kubernetesAuthentication
type KubernetesAuthentication struct {
AccountID string `json:"AccountId,omitempty"`
AdminLogin string `json:"AdminLogin,omitempty"`
AssumeRole bool `json:"AssumeRole,omitempty"`
AssumedRoleARN string `json:"AssumedRoleArn,omitempty"`
AssumedRoleSession string `json:"AssumedRoleSession,omitempty"`
AssumeRoleSessionDuration int `json:"AssumeRoleSessionDurationSeconds,omitempty"`
AssumeRoleExternalID string `json:"AssumeRoleExternalId,omitempty"`
AuthenticationType string `json:"AuthenticationType,omitempty"`
ClientCertificate string `json:"ClientCertificate,omitempty"`
ClusterName string `json:"ClusterName,omitempty"`
ClusterResourceGroup string `json:"ClusterResourceGroup,omitempty"`
UseInstanceRole bool `json:"UseInstanceRole,omitempty"`
}

// GetAuthenticationType returns the authentication type of this
// Kubernetes-based authenication.
func (e kubernetesAuthentication) GetAuthenticationType() string {
return e.AuthenticationType
// Kubernetes-based authentication.
func (k *KubernetesAuthentication) GetAuthenticationType() string {
return k.AuthenticationType
}

var _ IKubernetesAuthentication = &kubernetesAuthentication{}
var _ IKubernetesAuthentication = &KubernetesAuthentication{}
15 changes: 11 additions & 4 deletions octopusdeploy/kubernetes_certificate_authentication.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package octopusdeploy

type KubernetesCertificateAuthentication struct {
ClientCertificate string `json:"ClientCertificate,omitempty"`

kubernetesAuthentication
AuthenticationType string `json:"AuthenticationType"`
ClientCertificate string `json:"ClientCertificate,omitempty"`
}

// NewKubernetesCertificateAuthentication creates and initializes a Kubernetes
// certificate authentication.
func NewKubernetesCertificateAuthentication() *KubernetesCertificateAuthentication {
return &KubernetesCertificateAuthentication{
kubernetesAuthentication: *newKubernetesAuthentication("KubernetesCertificate"),
AuthenticationType: "KubernetesCertificate",
}
}

// GetAuthenticationType returns the authentication type of this
// Kubernetes-based authentication.
func (k *KubernetesCertificateAuthentication) GetAuthenticationType() string {
return k.AuthenticationType
}

var _ IKubernetesAuthentication = &KubernetesCertificateAuthentication{}
2 changes: 1 addition & 1 deletion octopusdeploy/kubernetes_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func CreateTestKubernetesAwsEndpoint(t *testing.T) *KubernetesEndpoint {

kubernetesEndpoint.DefaultWorkerPoolID = defaultWorkerPoolID
kubernetesEndpoint.ClusterCertificate = clusterCertificate
kubernetesEndpoint.Authentication = *authentication
kubernetesEndpoint.Authentication = authentication
kubernetesEndpoint.ID = id
kubernetesEndpoint.ModifiedBy = lastModifiedBy
kubernetesEndpoint.ModifiedOn = &lastModifiedOn
Expand Down
15 changes: 11 additions & 4 deletions octopusdeploy/kubernetes_standard_authentication.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package octopusdeploy

type KubernetesStandardAuthentication struct {
AccountID string `json:"AccountId,omitempty"`

kubernetesAuthentication
AccountID string `json:"AccountId,omitempty"`
AuthenticationType string `json:"AuthenticationType"`
}

// NewKubernetesStandardAuthentication creates and initializes a Kubernetes AWS
Expand All @@ -14,6 +13,14 @@ func NewKubernetesStandardAuthentication(authenticationType string) *KubernetesS
}

return &KubernetesStandardAuthentication{
kubernetesAuthentication: *newKubernetesAuthentication(authenticationType),
AuthenticationType: authenticationType,
}
}

// GetAuthenticationType returns the authentication type of this
// Kubernetes-based authentication.
func (k *KubernetesStandardAuthentication) GetAuthenticationType() string {
return k.AuthenticationType
}

var _ IKubernetesAuthentication = &KubernetesStandardAuthentication{}

0 comments on commit b7e50fd

Please sign in to comment.