Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • oss/libraries/go/services/job-queues
1 result
Select Git revision
Show changes
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -31,6 +31,10 @@ func (c *CounterResult) GetResult() string {
return fmt.Sprintf("Count: %d", c.Count)
}
func (c *CounterResult) GetError() (string, int) {
return "", 0
}
// CounterRunnable is a runnable that counts
type CounterRunnable struct {
Count int `json:"count" yaml:"count"`
......
......@@ -41,6 +41,13 @@ func (f *FileOperationResult) GetResult() string {
return f.Content
}
func (f *FileOperationResult) GetError() (string, int) {
if f.Success == false {
return "FileOperationResult failed", 1
}
return "", 0
}
const (
FileOperationRead = "read"
FileOperationWrite = "write"
......
......@@ -42,6 +42,10 @@ func (d *DBResult) GetResult() string {
return fmt.Sprintf("RowsAffected: %d", d.RowsAffected)
}
func (d *DBResult) GetError() (string, int) {
return "", 0
}
type DBRunnable struct {
Type string
DSN string
......@@ -72,17 +76,24 @@ func (d *DBRunnable) Run(ctx context.Context) (RunResult[DBResult], error) {
case "mysql":
db, err = gorm.Open(mysql.Open(d.DSN), &gorm.Config{})
default:
return RunResult[DBResult]{Status: ResultStatusFailed}, ErrUnsupportedDatabaseType
return RunResult[DBResult]{Status: ResultStatusFailed,
Data: DBResult{},
}, ErrUnsupportedDatabaseType
}
if err != nil {
return RunResult[DBResult]{Status: ResultStatusFailed}, err
return RunResult[DBResult]{Status: ResultStatusFailed,
Data: DBResult{},
},
err
}
}
result := db.Exec(d.Query)
if result.Error != nil {
return RunResult[DBResult]{Status: ResultStatusFailed}, result.Error
return RunResult[DBResult]{Status: ResultStatusFailed,
Data: DBResult{},
}, result.Error
}
return RunResult[DBResult]{
......
......@@ -50,6 +50,13 @@ func (h *HTTPResult) GetResult() string {
return fmt.Sprintf("StatusCode: %d\n\n%s", h.StatusCode, h.Body)
}
func (h *HTTPResult) GetError() (string, int) {
if h.StatusCode >= 400 {
return fmt.Sprintf("StatusCode: %d\n\n%s", h.StatusCode, h.Body), h.StatusCode
}
return "", 0
}
type HTTPRunnable struct {
URL string
Method string
......
......@@ -79,6 +79,13 @@ func (m *MailResult) GetResult() string {
return fmt.Sprintf("Sent: %t\n\nServerReply: %s\n\nSmtpStatusCode: %d", m.Sent, m.ServerReply, m.SmtpStatusCode)
}
func (m *MailResult) GetError() (string, int) {
if !m.Sent {
return fmt.Sprintf("Sent: %t\n\nServerReply: %s\n\nSmtpStatusCode: %d", m.Sent, m.ServerReply, m.SmtpStatusCode), 1
}
return "", 0
}
type MailRunnable struct {
To string
From string
......
......@@ -86,6 +86,10 @@ func (s *SFTPResult) GetResult() string {
return fmt.Sprintf("FilesCopied: %v", s.FilesCopied)
}
func (s *SFTPResult) GetError() (string, int) {
return "", 0
}
const (
CredentialTypePassword = "password"
CredentialTypeKey = "key"
......@@ -122,11 +126,14 @@ func (s *SFTPRunnable) Run(_ context.Context) (RunResult[SFTPResult], error) {
case CredentialTypeKey:
key, err := ssh.ParsePrivateKey([]byte(s.Credential))
if err != nil {
return RunResult[SFTPResult]{Status: ResultStatusFailed}, err
return RunResult[SFTPResult]{Status: ResultStatusFailed,
Data: SFTPResult{},
}, err
}
authMethod = ssh.PublicKeys(key)
default:
return RunResult[SFTPResult]{Status: ResultStatusFailed}, ErrUnsupportedCredentialType
return RunResult[SFTPResult]{Status: ResultStatusFailed,
Data: SFTPResult{}}, ErrUnsupportedCredentialType
}
var hkCallback ssh.HostKeyCallback
......@@ -136,7 +143,9 @@ func (s *SFTPRunnable) Run(_ context.Context) (RunResult[SFTPResult], error) {
hostkeyBytes := []byte(s.HostKey)
hostKey, err := ssh.ParsePublicKey(hostkeyBytes)
if err != nil {
return RunResult[SFTPResult]{Status: ResultStatusFailed}, err
return RunResult[SFTPResult]{Status: ResultStatusFailed,
Data: SFTPResult{},
}, err
}
hkCallback = ssh.FixedHostKey(hostKey)
......@@ -159,13 +168,17 @@ func (s *SFTPRunnable) Run(_ context.Context) (RunResult[SFTPResult], error) {
client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", s.Host, s.Port), config)
if err != nil {
return RunResult[SFTPResult]{Status: ResultStatusFailed}, err
return RunResult[SFTPResult]{Status: ResultStatusFailed,
Data: SFTPResult{},
}, err
}
defer client.Close()
sftpClient, err := sftp.NewClient(client)
if err != nil {
return RunResult[SFTPResult]{Status: ResultStatusFailed}, err
return RunResult[SFTPResult]{Status: ResultStatusFailed,
Data: SFTPResult{},
}, err
}
defer sftpClient.Close()
......@@ -177,7 +190,9 @@ func (s *SFTPRunnable) Run(_ context.Context) (RunResult[SFTPResult], error) {
case RemoteToLocal:
filesCopied, err = s.copyRemoteToLocal(sftpClient)
default:
return RunResult[SFTPResult]{Status: ResultStatusFailed}, ErrUnsupportedTransferDirection
return RunResult[SFTPResult]{Status: ResultStatusFailed,
Data: SFTPResult{},
}, ErrUnsupportedTransferDirection
}
if err != nil {
......
......@@ -41,6 +41,13 @@ func (s *ShellResult) GetResult() string {
return s.Output
}
func (s *ShellResult) GetError() (string, int) {
if s.ExitCode != 0 {
return s.Error, s.ExitCode
}
return "", 0
}
type ShellRunnable struct {
ScriptPath string
Script string
......