check_bash.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package executor
  2. import (
  3. "fmt"
  4. schemepkg "git.buran.team/main/cep/scheme"
  5. fw "git.buran.team/main/fairwind"
  6. )
  7. type CheckBash struct {
  8. global *Global
  9. ticket *Ticket
  10. id string
  11. container Container
  12. timeout int
  13. command string
  14. result *Result
  15. }
  16. func NewCheckBash(global *Global, ticket *Ticket, container Container, checkScheme schemepkg.Check) (*CheckBash, error) {
  17. result, err := NewResult(checkScheme.KindBash.Result)
  18. if err != nil {
  19. return nil, fmt.Errorf("can't create bash check: %w", err)
  20. }
  21. return &CheckBash{
  22. global: global,
  23. ticket: ticket,
  24. id: checkScheme.ID,
  25. container: container,
  26. timeout: checkScheme.Timeout,
  27. command: checkScheme.KindBash.Command,
  28. result: result,
  29. }, nil
  30. }
  31. func (this *CheckBash) ID() string {
  32. return this.ID()
  33. }
  34. func (this *CheckBash) Check() CheckResult {
  35. this.global.Log.Debug("beginning bash check", fw.LogValue("uuid", this.ticket.UUID))
  36. result := this.container.Execute(this.timeout, this.command)
  37. if result.Error != nil {
  38. this.global.Log.Debug("bash check ended with error", fw.LogValue("uuid", this.ticket.UUID), fw.LogError(result.Error))
  39. return CheckResult{
  40. Success: false,
  41. Data: nil,
  42. }
  43. }
  44. this.global.Log.Debug("bash check ended successfully", fw.LogValue("uuid", this.ticket.UUID))
  45. return CheckResult{
  46. Success: this.result.Check(result.Code, result.Stdout, result.Stderr),
  47. Data: nil,
  48. }
  49. }