summaryrefslogtreecommitdiff
path: root/plugins/jobs/pipeline/pipeline.go
blob: 9189817832b1cc5371c5ce127fa107ea5b3d9b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package pipeline

// Pipeline defines pipeline options.
type Pipeline map[string]interface{}

const (
	priority string = "priority"
	driver   string = "driver"
	name     string = "name"
)

// With pipeline value
func (p *Pipeline) With(name string, value interface{}) {
	(*p)[name] = value
}

// Name returns pipeline name.
func (p Pipeline) Name() string {
	return p.String(name, "")
}

// Driver associated with the pipeline.
func (p Pipeline) Driver() string {
	return p.String(driver, "")
}

// Has checks if value presented in pipeline.
func (p Pipeline) Has(name string) bool {
	if _, ok := p[name]; ok {
		return true
	}

	return false
}

// String must return option value as string or return default value.
func (p Pipeline) String(name string, d string) string {
	if value, ok := p[name]; ok {
		if str, ok := value.(string); ok {
			return str
		}
	}

	return d
}

// Int must return option value as string or return default value.
func (p Pipeline) Int(name string, d int) int {
	if value, ok := p[name]; ok {
		if i, ok := value.(int); ok {
			return i
		}
	}

	return d
}

// Priority returns default pipeline priority
func (p Pipeline) Priority() uint64 {
	if value, ok := p[priority]; ok {
		if v, ok := value.(uint64); ok {
			return v
		}
	}

	return 10
}