github.com/chenbh/concourse/v6@v6.4.2/atc/resource/resource.go (about) 1 package resource 2 3 import ( 4 "context" 5 "encoding/json" 6 "path/filepath" 7 8 "github.com/chenbh/concourse/v6/atc/runtime" 9 10 "github.com/chenbh/concourse/v6/atc" 11 ) 12 13 //go:generate counterfeiter . ResourceFactory 14 type ResourceFactory interface { 15 NewResource(source atc.Source, params atc.Params, version atc.Version) Resource 16 } 17 18 type resourceFactory struct { 19 } 20 21 func NewResourceFactory() ResourceFactory { 22 return resourceFactory{} 23 24 } 25 func (rf resourceFactory) NewResource(source atc.Source, params atc.Params, version atc.Version) Resource { 26 return &resource{ 27 Source: source, 28 Params: params, 29 Version: version, 30 } 31 } 32 33 //go:generate counterfeiter . Resource 34 35 type Resource interface { 36 Get(context.Context, runtime.ProcessSpec, runtime.Runner) (runtime.VersionResult, error) 37 Put(context.Context, runtime.ProcessSpec, runtime.Runner) (runtime.VersionResult, error) 38 Check(context.Context, runtime.ProcessSpec, runtime.Runner) ([]atc.Version, error) 39 Signature() ([]byte, error) 40 } 41 42 type ResourceType string 43 44 type Metadata interface { 45 Env() []string 46 } 47 48 func ResourcesDir(suffix string) string { 49 return filepath.Join("/tmp", "build", suffix) 50 } 51 52 type resource struct { 53 Source atc.Source `json:"source"` 54 Params atc.Params `json:"params,omitempty"` 55 Version atc.Version `json:"version,omitempty"` 56 } 57 58 func (resource *resource) Signature() ([]byte, error) { 59 return json.Marshal(resource) 60 }