Skip to content

Commit

Permalink
Merge pull request #138 from harness/PL-25840
Browse files Browse the repository at this point in the history
[PL-25840]: Model and enum changes for sshkey type secret
  • Loading branch information
rathodmeetsatish authored Jul 8, 2022
2 parents 127236e + 4ce3c2e commit 33c6a8c
Show file tree
Hide file tree
Showing 17 changed files with 412 additions and 14 deletions.
20 changes: 20 additions & 0 deletions harness/nextgen/enum_ssh_authentication_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package nextgen

type SSHAuthenticationType string

var SSHAuthenticationTypes = struct {
Kerberos SSHAuthenticationType
SSH SSHAuthenticationType
}{
Kerberos: "Kerberos",
SSH: "SSH",
}

var SSHAuthenticationTypeValues = []string{
SSHAuthenticationTypes.Kerberos.String(),
SSHAuthenticationTypes.SSH.String(),
}

func (e SSHAuthenticationType) String() string {
return string(e)
}
23 changes: 23 additions & 0 deletions harness/nextgen/enum_ssh_config_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package nextgen

type SSHConfigType string

var SSHConfigTypes = struct {
Password SSHConfigType
KeyPath SSHConfigType
KeyReference SSHConfigType
}{
Password: "Password",
KeyPath: "KeyPath",
KeyReference: "KeyReference",
}

var SSHConfigTypeValues = []string{
SSHConfigTypes.Password.String(),
SSHConfigTypes.KeyPath.String(),
SSHConfigTypes.KeyReference.String(),
}

func (e SSHConfigType) String() string {
return string(e)
}
20 changes: 20 additions & 0 deletions harness/nextgen/enum_ssh_specification_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package nextgen

type SSHSpecificationType string

var SSHSpecificationTypes = struct {
KerberosConfigDTO SSHSpecificationType
SSHConfig SSHSpecificationType
}{
KerberosConfigDTO: "KerberosConfigDTO",
SSHConfig: "SSHConfig",
}

var SSHSpecificationTypeValues = []string{
SSHSpecificationTypes.KerberosConfigDTO.String(),
SSHSpecificationTypes.SSHConfig.String(),
}

func (e SSHSpecificationType) String() string {
return string(e)
}
20 changes: 20 additions & 0 deletions harness/nextgen/enum_tgt_generation_method_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package nextgen

type TgtGenerationMethodType string

var TgtGenerationMethodTypes = struct {
TGTKeyTabFilePathSpecDTO TgtGenerationMethodType
TGTPasswordSpecDTO TgtGenerationMethodType
}{
TGTKeyTabFilePathSpecDTO: "KeyTabFilePath",
TGTPasswordSpecDTO: "Password",
}

var TgtGenerationMethodTypeValues = []string{
TgtGenerationMethodTypes.TGTKeyTabFilePathSpecDTO.String(),
TgtGenerationMethodTypes.TGTPasswordSpecDTO.String(),
}

func (e TgtGenerationMethodType) String() string {
return string(e)
}
7 changes: 6 additions & 1 deletion harness/nextgen/model_base_ssh_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
*/
package nextgen

import "encoding/json"

// This is the SSH specification details as defined in Harness.
type BaseSshSpec struct {
Type_ string `json:"type"`
Type_ SSHSpecificationType `json:"type"`
KerberosConfig *KerberosConfig `json:"-"`
SSHConfig *SshConfig `json:"-"`
Spec json.RawMessage `json:"spec"`
}
10 changes: 7 additions & 3 deletions harness/nextgen/model_kerberos_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
*/
package nextgen

import "encoding/json"

// This is the Kerberos configuration details, defined in Harness.
type KerberosConfig struct {
Type_ string `json:"type"`
// This is the authorization role, the user/service has in the realm.
Principal string `json:"principal"`
// Name of the Realm.
Realm string `json:"realm"`
TgtGenerationMethod string `json:"tgtGenerationMethod,omitempty"`
Spec *TgtGenerationSpecDto `json:"spec,omitempty"`
Realm string `json:"realm"`
TgtGenerationMethod TgtGenerationMethodType `json:"tgtGenerationMethod,omitempty"`
KeyTabFilePathSpec *TgtKeyTabFilePathSpecDto `json:"-"`
PasswordSpec *TgtPasswordSpecDto `json:"-"`
Spec json.RawMessage `json:"spec,omitempty"`
}
57 changes: 57 additions & 0 deletions harness/nextgen/model_kerberos_config_spec_serialization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package nextgen

import (
"encoding/json"
"fmt"
)

func (a *KerberosConfig) UnmarshalJSON(data []byte) error {

type Alias KerberosConfig

aux := &struct {
*Alias
}{
Alias: (*Alias)(a),
}

err := json.Unmarshal(data, &aux)
if err != nil {
return err
}

switch a.TgtGenerationMethod {
case TgtGenerationMethodTypes.TGTKeyTabFilePathSpecDTO:
err = json.Unmarshal(aux.Spec, &a.KeyTabFilePathSpec)
case TgtGenerationMethodTypes.TGTPasswordSpecDTO:
err = json.Unmarshal(aux.Spec, &a.PasswordSpec)
default:
panic(fmt.Sprintf("unknown Tgt generation method type %s", a.TgtGenerationMethod))
}

return err
}

func (a *KerberosConfig) MarshalJSON() ([]byte, error) {
type Alias KerberosConfig

var spec []byte
var err error

switch a.TgtGenerationMethod {
case TgtGenerationMethodTypes.TGTKeyTabFilePathSpecDTO:
spec, err = json.Marshal(a.KeyTabFilePathSpec)
case TgtGenerationMethodTypes.TGTPasswordSpecDTO:
spec, err = json.Marshal(a.PasswordSpec)
default:
panic(fmt.Sprintf("unknown Tgt generation method type %s", a.TgtGenerationMethod))
}

if err != nil {
return nil, err
}

a.Spec = json.RawMessage(spec)

return json.Marshal((*Alias)(a))
}
2 changes: 1 addition & 1 deletion harness/nextgen/model_secret_serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (a *Secret) MarshalJSON() ([]byte, error) {
case SecretTypes.SecretFile:
spec, err = json.Marshal(a.File)
case SecretTypes.SSHKey:
// spec, err = json.Marshal(a.AssumeIamRole)
spec, err = json.Marshal(a.SSHKey)
// noop
case SecretTypes.SecretText:
spec, err = json.Marshal(a.Text)
Expand Down
8 changes: 6 additions & 2 deletions harness/nextgen/model_ssh_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
*/
package nextgen

import "encoding/json"

// This is the SSH Authentication specification defined in Harness.
type SshAuth struct {
Spec *BaseSshSpec `json:"spec"`
KerberosConfig *KerberosConfig `json:"-"`
SSHConfig *SshConfig `json:"-"`
Spec json.RawMessage `json:"spec"`
// Specifies authentication scheme, SSH or Kerberos
Type_ string `json:"type"`
Type_ SSHAuthenticationType `json:"type"`
}
57 changes: 57 additions & 0 deletions harness/nextgen/model_ssh_auth_serializer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package nextgen

import (
"encoding/json"
"fmt"
)

func (a *SshAuth) UnmarshalJSON(data []byte) error {

type Alias SshAuth

aux := &struct {
*Alias
}{
Alias: (*Alias)(a),
}

err := json.Unmarshal(data, &aux)
if err != nil {
return err
}

switch a.Type_ {
case SSHAuthenticationTypes.Kerberos:
err = json.Unmarshal(aux.Spec, &a.KerberosConfig)
case SSHAuthenticationTypes.SSH:
err = json.Unmarshal(aux.Spec, &a.SSHConfig)
default:
panic(fmt.Sprintf("unknown SSH authentication type %s", a.Type_))
}

return err
}

func (a *SshAuth) MarshalJSON() ([]byte, error) {
type Alias SshAuth

var spec []byte
var err error

switch a.Type_ {
case SSHAuthenticationTypes.Kerberos:
spec, err = json.Marshal(a.KerberosConfig)
case SSHAuthenticationTypes.SSH:
spec, err = json.Marshal(a.SSHConfig)
default:
panic(fmt.Sprintf("unknown SSH authentication type %s", a.Type_))
}

if err != nil {
return nil, err
}

a.Spec = json.RawMessage(spec)

return json.Marshal((*Alias)(a))
}
11 changes: 8 additions & 3 deletions harness/nextgen/model_ssh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
*/
package nextgen

import "encoding/json"

// This is the SSH configuration details defined in Harness.
type SshConfig struct {
Type_ string `json:"type"`
Type_ SSHConfigType `json:"type"`
// This specifies SSH credential type as Password, KeyPath or KeyReference
CredentialType string `json:"credentialType"`
Spec *SshCredentialSpec `json:"spec"`
CredentialType SSHConfigType `json:"credentialType"`
KeyReferenceCredential *SshKeyReferenceCredentialDto `json:"-"`
KeyPathCredential *SshKeyPathCredential `json:"-"`
PasswordCredential *SshPasswordCredentialDto `json:"-"`
Spec json.RawMessage `json:"spec"`
}
61 changes: 61 additions & 0 deletions harness/nextgen/model_ssh_config_serialization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package nextgen

import (
"encoding/json"
"fmt"
)

func (a *SshConfig) UnmarshalJSON(data []byte) error {

type Alias SshConfig

aux := &struct {
*Alias
}{
Alias: (*Alias)(a),
}

err := json.Unmarshal(data, &aux)
if err != nil {
return err
}

switch a.CredentialType {
case SSHConfigTypes.KeyPath:
err = json.Unmarshal(aux.Spec, &a.KeyPathCredential)
case SSHConfigTypes.KeyReference:
err = json.Unmarshal(aux.Spec, &a.KeyReferenceCredential)
case SSHConfigTypes.Password:
err = json.Unmarshal(aux.Spec, &a.PasswordCredential)
default:
panic(fmt.Sprintf("unknown SSH config type %s", a.Type_))
}

return err
}

func (a *SshConfig) MarshalJSON() ([]byte, error) {
type Alias SshConfig

var spec []byte
var err error

switch a.CredentialType {
case SSHConfigTypes.KeyPath:
spec, err = json.Marshal(a.KeyPathCredential)
case SSHConfigTypes.KeyReference:
spec, err = json.Marshal(a.KeyReferenceCredential)
case SSHConfigTypes.Password:
spec, err = json.Marshal(a.PasswordCredential)
default:
panic(fmt.Sprintf("unknown SSH config type %s", a.Type_))
}

if err != nil {
return nil, err
}

a.Spec = json.RawMessage(spec)

return json.Marshal((*Alias)(a))
}
5 changes: 4 additions & 1 deletion harness/nextgen/model_ssh_credential_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ package nextgen

// This is the SSH credential specification defined in Harness.
type SshCredentialSpec struct {
CredentialType string `json:"credentialType"`
CredentialType string `json:"credentialType"`
KeyPathCredential *SshKeyPathCredential `json:"keyPathCredential"`
KeyReferenceCredential *SshKeyReferenceCredentialDto `json:"keyReferenceCredential"`
PasswordCredential *SshPasswordCredentialDto `json:"passwordCredential"`
}
4 changes: 2 additions & 2 deletions harness/nextgen/model_ssh_key_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ package nextgen

// This is the SSH key authentication details defined in Harness.
type SshKeySpec struct {
ErrorMessageForInvalidYaml string `json:"errorMessageForInvalidYaml,omitempty"`
Type_ string `json:"type"`
ErrorMessageForInvalidYaml string `json:"errorMessageForInvalidYaml,omitempty"`
Type_ SecretSpecType `json:"type"`
// SSH port
Port int32 `json:"port,omitempty"`
Auth *SshAuth `json:"auth"`
Expand Down
Loading

0 comments on commit 33c6a8c

Please sign in to comment.