Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
feat: Refactor git remote repository credentials models (#475)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Git credentials for git authentication were moved to a separate sub-structure and split to either ssh or http sub-structures depending on the used authentication method.

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT authored Jun 28, 2022
1 parent 3ed2fc6 commit fc5b6f9
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 84 deletions.
37 changes: 3 additions & 34 deletions pkg/api/models/create_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,16 @@ import "encoding/json"

// CreateProject create project
type CreateProject struct {

// git remote URL
GitRemoteURL string `json:"gitRemoteURL,omitempty"`

// git token
GitToken string `json:"gitToken,omitempty"`

// git private key
GitPrivateKey string `json:"gitPrivateKey,omitempty"`

// git private key passphrase
GitPrivateKeyPass string `json:"gitPrivateKeyPass,omitempty"`

// git proxy URL
GitProxyURL string `json:"gitProxyUrl,omitempty"`

// git proxy scheme
GitProxyScheme string `json:"gitProxyScheme,omitempty"`

// git proxy user
GitProxyUser string `json:"gitProxyUser,omitempty"`

// insecure skip tls
InsecureSkipTLS bool `json:"insecureSkipTLS"`

// git proxy password
GitProxyPassword string `json:"gitProxyPassword,omitempty"`

//git PEM Certificate
GitPemCertificate string `json:"gitPemCertificate,omitempty"`

// git user
GitUser string `json:"gitUser,omitempty"`

// name
// Required: true
Name *string `json:"name"`

// shipyard
// Required: true
Shipyard *string `json:"shipyard"`

// git auth credentials
GitCredentials *GitAuthCredentials `json:"gitCredentials,omitempty"`
}

// ToJSON converts object to JSON string
Expand Down
36 changes: 19 additions & 17 deletions pkg/api/models/expanded_project.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package models

import "encoding/json"

// ExpandedProject expanded project
//
// swagger:model ExpandedProject
Expand All @@ -8,12 +10,6 @@ type ExpandedProject struct {
// Creation date of the project
CreationDate string `json:"creationDate,omitempty"`

// Git remote URI
GitRemoteURI string `json:"gitRemoteURI,omitempty"`

// Git User
GitUser string `json:"gitUser,omitempty"`

// last event context
LastEventContext *EventContextInfo `json:"lastEventContext,omitempty"`

Expand All @@ -26,18 +22,24 @@ type ExpandedProject struct {
// Version of the shipyard file
ShipyardVersion string `json:"shipyardVersion,omitempty"`

// git proxy URL
GitProxyURL string `json:"gitProxyUrl,omitempty"`

// git proxy scheme
GitProxyScheme string `json:"gitProxyScheme,omitempty"`
// stages
Stages []*ExpandedStage `json:"stages"`

// git proxy user
GitProxyUser string `json:"gitProxyUser,omitempty"`
// git auth credentials
GitCredentials *GitAuthCredentialsSecure `json:"gitCredentials,omitempty"`
}

// insecure skip tls
InsecureSkipTLS bool `json:"insecureSkipTLS"`
// ToJSON converts object to JSON string
func (a *ExpandedProject) ToJSON() ([]byte, error) {
return json.Marshal(a)
}

// stages
Stages []*ExpandedStage `json:"stages"`
// FromJSON converts JSON string to object
func (a *ExpandedProject) FromJSON(b []byte) error {
var res ExpandedProject
if err := json.Unmarshal(b, &res); err != nil {
return err
}
*a = res
return nil
}
199 changes: 199 additions & 0 deletions pkg/api/models/git_credentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package models

import "encoding/json"

// GitAuthCredentials stores git credentials
type GitAuthCredentials struct {

// git remote URL
RemoteURL string `json:"remoteURL" bson:"remoteURL"`

// git user
User string `json:"user,omitempty" bson:"user"`

// https git credentials
HttpsAuth *HttpsGitAuth `json:"https,omitempty" bson:"https"`

//ssh git credentials
SshAuth *SshGitAuth `json:"ssh,omitempty" bson:"ssh"`
}

// ToJSON converts object to JSON string
func (p *GitAuthCredentials) ToJSON() ([]byte, error) {
return json.Marshal(p)
}

// FromJSON converts JSON string to object
func (p *GitAuthCredentials) FromJSON(b []byte) error {
var res GitAuthCredentials
if err := json.Unmarshal(b, &res); err != nil {
return err
}
*p = res
return nil
}

// HttpsGitAuth stores HTTPS git credentials
type HttpsGitAuth struct {
// Git token
Token string `json:"token" bson:"token"`

//git PEM Certificate
Certificate string `json:"certificate,omitempty" bson:"certificate"`

// insecure skip tls
InsecureSkipTLS bool `json:"insecureSkipTLS" bson:"insecureSkipTLS"`

// git proxy credentials
Proxy *ProxyGitAuth `json:"proxy,omitempty" bson:"proxy"`
}

// ToJSON converts object to JSON string
func (p *HttpsGitAuth) ToJSON() ([]byte, error) {
return json.Marshal(p)
}

// FromJSON converts JSON string to object
func (p *HttpsGitAuth) FromJSON(b []byte) error {
var res HttpsGitAuth
if err := json.Unmarshal(b, &res); err != nil {
return err
}
*p = res
return nil
}

// SshGitAuth stores SSH git credentials
type SshGitAuth struct {
// git private key
PrivateKey string `json:"privateKey" bson:"privateKey"`

// git private key passphrase
PrivateKeyPass string `json:"privateKeyPass,omitempty" bson:"privateKeyPass"`
}

// ToJSON converts object to JSON string
func (p *SshGitAuth) ToJSON() ([]byte, error) {
return json.Marshal(p)
}

// FromJSON converts JSON string to object
func (p *SshGitAuth) FromJSON(b []byte) error {
var res SshGitAuth
if err := json.Unmarshal(b, &res); err != nil {
return err
}
*p = res
return nil
}

// ProxyGitAuth stores proxy git credentials
type ProxyGitAuth struct {
// git proxy URL
URL string `json:"url" bson:"url"`

// git proxy scheme
Scheme string `json:"scheme" bson:"scheme"`

// git proxy user
User string `json:"user,omitempty" bson:"user"`

// git proxy password
Password string `json:"password,omitempty" bson:"password"`
}

// ToJSON converts object to JSON string
func (p *ProxyGitAuth) ToJSON() ([]byte, error) {
return json.Marshal(p)
}

// FromJSON converts JSON string to object
func (p *ProxyGitAuth) FromJSON(b []byte) error {
var res ProxyGitAuth
if err := json.Unmarshal(b, &res); err != nil {
return err
}
*p = res
return nil
}

// GitAuthCredentialsSecure stores git credentials without secure information
// model for retrieving credentials data with GET request
type GitAuthCredentialsSecure struct {
// git remote URL
RemoteURL string `json:"remoteURL" bson:"remoteURL"`

// git user
User string `json:"user,omitempty" bson:"user"`

// https git credentials
HttpsAuth *HttpsGitAuthSecure `json:"https,omitempty" bson:"https"`
}

// ToJSON converts object to JSON string
func (p *GitAuthCredentialsSecure) ToJSON() ([]byte, error) {
return json.Marshal(p)
}

// FromJSON converts JSON string to object
func (p *GitAuthCredentialsSecure) FromJSON(b []byte) error {
var res GitAuthCredentialsSecure
if err := json.Unmarshal(b, &res); err != nil {
return err
}
*p = res
return nil
}

// HttpsGitAuthSecure stores HTTPS git credentials without secure information
// model for retrieving credentials data with GET request
type HttpsGitAuthSecure struct {
// insecure skip tls
InsecureSkipTLS bool `json:"insecureSkipTLS" bson:"insecureSkipTLS"`

// git proxy credentials
Proxy *ProxyGitAuthSecure `json:"proxy,omitempty" bson:"proxy"`
}

// ToJSON converts object to JSON string
func (p *HttpsGitAuthSecure) ToJSON() ([]byte, error) {
return json.Marshal(p)
}

// FromJSON converts JSON string to object
func (p *HttpsGitAuthSecure) FromJSON(b []byte) error {
var res HttpsGitAuthSecure
if err := json.Unmarshal(b, &res); err != nil {
return err
}
*p = res
return nil
}

// ProxyGitAuthSecure stores proxy git credentials without secure information
// model for retrieving credentials data with GET request
type ProxyGitAuthSecure struct {
// git proxy URL
URL string `json:"url" bson:"url"`

// git proxy scheme
Scheme string `json:"scheme" bson:"scheme"`

// git proxy user
User string `json:"user,omitempty" bson:"user"`
}

// ToJSON converts object to JSON string
func (p *ProxyGitAuthSecure) ToJSON() ([]byte, error) {
return json.Marshal(p)
}

// FromJSON converts JSON string to object
func (p *ProxyGitAuthSecure) FromJSON(b []byte) error {
var res ProxyGitAuthSecure
if err := json.Unmarshal(b, &res); err != nil {
return err
}
*p = res
return nil
}
36 changes: 3 additions & 33 deletions pkg/api/models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,6 @@ type Project struct {
// Creation date of the service
CreationDate string `json:"creationDate,omitempty"`

// Git remote URI
GitRemoteURI string `json:"gitRemoteURI,omitempty"`

// Git token
GitToken string `json:"gitToken,omitempty"`

// git private key
GitPrivateKey string `json:"gitPrivateKey,omitempty"`

// git private key passphrase
GitPrivateKeyPass string `json:"gitPrivateKeyPass,omitempty"`

// git proxy URL
GitProxyURL string `json:"gitProxyUrl,omitempty"`

// git proxy scheme
GitProxyScheme string `json:"gitProxyScheme,omitempty"`

// git proxy user
GitProxyUser string `json:"gitProxyUser,omitempty"`

// insecure skip tls
InsecureSkipTLS bool `json:"insecureSkipTLS"`

// git proxy password
GitProxyPassword string `json:"gitProxyPassword,omitempty"`

//git PEM Certificate
GitPemCertificate string `json:"gitPemCertificate,omitempty"`

// Git User
GitUser string `json:"gitUser,omitempty"`

// Project name
ProjectName string `json:"projectName,omitempty"`

Expand All @@ -49,6 +16,9 @@ type Project struct {

// stages
Stages []*Stage `json:"stages"`

// git auth credentials
GitCredentials *GitAuthCredentials `json:"gitCredentials,omitempty"`
}

// ToJSON converts object to JSON string
Expand Down

0 comments on commit fc5b6f9

Please sign in to comment.