forked from concourse/concourse
/
resource.go
50 lines (44 loc) · 1.2 KB
/
resource.go
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
package concourse
import (
"github.com/pf-qiu/concourse/v6/atc"
"github.com/pf-qiu/concourse/v6/go-concourse/concourse/internal"
"github.com/tedsuo/rata"
)
func (team *team) Resource(pipelineRef atc.PipelineRef, resourceName string) (atc.Resource, bool, error) {
params := rata.Params{
"pipeline_name": pipelineRef.Name,
"resource_name": resourceName,
"team_name": team.Name(),
}
var resource atc.Resource
err := team.connection.Send(internal.Request{
RequestName: atc.GetResource,
Params: params,
Query: pipelineRef.QueryParams(),
}, &internal.Response{
Result: &resource,
})
switch err.(type) {
case nil:
return resource, true, nil
case internal.ResourceNotFoundError:
return resource, false, nil
default:
return resource, false, err
}
}
func (team *team) ListResources(pipelineRef atc.PipelineRef) ([]atc.Resource, error) {
params := rata.Params{
"pipeline_name": pipelineRef.Name,
"team_name": team.Name(),
}
var resources []atc.Resource
err := team.connection.Send(internal.Request{
RequestName: atc.ListResources,
Params: params,
Query: pipelineRef.QueryParams(),
}, &internal.Response{
Result: &resources,
})
return resources, err
}