condition_bash.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 ConditionBash struct {
  8. global *Global
  9. ticket *Ticket
  10. container Container
  11. id string
  12. timeout int
  13. command string
  14. result *Result
  15. }
  16. func NewConditionBash(global *Global, ticket *Ticket, container Container, conditionScheme schemepkg.Condition) (*ConditionBash, error) {
  17. result, err := NewResult(conditionScheme.KindBash.Result)
  18. if err != nil {
  19. return nil, fmt.Errorf("can't create bash condition: %w", err)
  20. }
  21. return &ConditionBash{
  22. global: global,
  23. ticket: ticket,
  24. container: container,
  25. id: conditionScheme.ID,
  26. timeout: conditionScheme.Timeout,
  27. command: conditionScheme.KindBash.Command,
  28. result: result,
  29. }, nil
  30. }
  31. func (this *ConditionBash) ID() string {
  32. return this.id
  33. }
  34. func (this *ConditionBash) Check() bool {
  35. this.global.Log.Debug("checking bash condition", fw.LogValue("uuid", this.ticket.UUID))
  36. defer this.global.Log.Debug("bash condition checked", fw.LogValue("uuid", this.ticket.UUID))
  37. result := this.container.Execute(this.timeout, this.command)
  38. if result.Error != nil {
  39. return false
  40. }
  41. return this.result.Check(result.Code, result.Stdout, result.Stderr)
  42. }