@@ -2,14 +2,20 @@ package codefresh
22
33import (
44 "bytes"
5+ "context"
56 "encoding/json"
67 "fmt"
7- "github.com/google/go-querystring/query"
88 "io/ioutil"
99 "net/http"
1010 "strings"
11+
12+ "github.com/google/go-querystring/query"
1113)
1214
15+ //go:generate mockery -name Codefresh -filename codefresh.go
16+
17+ //go:generate mockery -name UsersAPI -filename users.go
18+
1319type (
1420 Codefresh interface {
1521 Pipelines () IPipelineAPI
@@ -19,8 +25,10 @@ type (
1925 Progresses () IProgressAPI
2026 Clusters () IClusterAPI
2127 Contexts () IContextAPI
28+ Users () UsersAPI
2229 Argo () ArgoAPI
2330 Gitops () GitopsAPI
31+ ArgoRuntime () IArgoRuntimeAPI
2432 }
2533)
2634
@@ -41,6 +49,10 @@ func (c *codefresh) Pipelines() IPipelineAPI {
4149 return newPipelineAPI (c )
4250}
4351
52+ func (c * codefresh ) Users () UsersAPI {
53+ return newUsersAPI (c )
54+ }
55+
4456func (c * codefresh ) Tokens () ITokenAPI {
4557 return newTokenAPI (c )
4658}
@@ -73,7 +85,15 @@ func (c *codefresh) Gitops() GitopsAPI {
7385 return newGitopsAPI (c )
7486}
7587
88+ func (c * codefresh ) ArgoRuntime () IArgoRuntimeAPI {
89+ return newArgoRuntimeAPI (c )
90+ }
91+
7692func (c * codefresh ) requestAPI (opt * requestOptions ) (* http.Response , error ) {
93+ return c .requestAPIWithContext (context .Background (), opt )
94+ }
95+
96+ func (c * codefresh ) requestAPIWithContext (ctx context.Context , opt * requestOptions ) (* http.Response , error ) {
7797 var body []byte
7898 finalURL := fmt .Sprintf ("%s%s" , c .host , opt .path )
7999 if opt .qs != nil {
@@ -82,7 +102,10 @@ func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
82102 if opt .body != nil {
83103 body , _ = json .Marshal (opt .body )
84104 }
85- request , err := http .NewRequest (opt .method , finalURL , bytes .NewBuffer (body ))
105+ request , err := http .NewRequestWithContext (ctx , opt .method , finalURL , bytes .NewBuffer (body ))
106+ if err != nil {
107+ return nil , err
108+ }
86109 request .Header .Set ("Authorization" , c .token )
87110 request .Header .Set ("Content-Type" , "application/json" )
88111
0 commit comments