Jelajahi Sumber

move streamevent to client method, change rename back

Ivan Galakhov 4 tahun lalu
induk
melakukan
74a7f7e399

+ 40 - 1
cli/cmd/api/api.go

@@ -1,9 +1,12 @@
 package api
 
 import (
+	"bytes"
+	"context"
 	"encoding/base64"
 	"encoding/json"
 	"fmt"
+	"github.com/porter-dev/porter/cli/cmd/deploy"
 	"io/ioutil"
 	"net/http"
 	"path/filepath"
@@ -62,7 +65,7 @@ func NewClientWithToken(baseURL, token string) *Client {
 	return client
 }
 
-func (c *Client) SendRequest(req *http.Request, v interface{}, useCookie bool) (*HTTPError, error) {
+func (c *Client) sendRequest(req *http.Request, v interface{}, useCookie bool) (*HTTPError, error) {
 	req.Header.Set("Content-Type", "application/json; charset=utf-8")
 	req.Header.Set("Accept", "application/json; charset=utf-8")
 
@@ -121,6 +124,42 @@ func (c *Client) saveCookie(cookie *http.Cookie) error {
 	return ioutil.WriteFile(c.CookieFilePath, data, 0644)
 }
 
+// StreamEvent sends an event from deployment to the api
+func (c *Client) StreamEvent(event deploy.Event, token string, projID uint, name string) error {
+	form := deploy.StreamEventForm{
+		Event: event,
+		Token: token,
+	}
+
+	body := new(bytes.Buffer)
+	err := json.NewEncoder(body).Encode(form)
+
+	if err != nil {
+		return err
+	}
+
+	req, err := http.NewRequest(
+		"POST",
+		fmt.Sprintf("%s/projects/%d/releases/%s/steps", c.BaseURL, projID, name),
+		body,
+	)
+
+	if err != nil {
+		return err
+	}
+
+	req = req.WithContext(context.Background())
+
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
+		if httpErr != nil {
+			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
+		}
+		return err
+	}
+
+	return nil
+}
+
 // retrieves single cookie from file
 func (c *Client) getCookie() (*http.Cookie, error) {
 	data, err := ioutil.ReadFile(c.CookieFilePath)

+ 5 - 5
cli/cmd/api/deploy.go

@@ -36,7 +36,7 @@ func (c *Client) GetReleaseWebhook(
 	req = req.WithContext(ctx)
 	bodyResp := &GetReleaseWebhookResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -64,7 +64,7 @@ func (c *Client) DeployWithWebhook(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -109,7 +109,7 @@ func (c *Client) UpdateBatchImage(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -168,7 +168,7 @@ func (c *Client) DeployTemplate(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -212,7 +212,7 @@ func (c *Client) UpgradeRelease(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 1 - 1
cli/cmd/api/domain.go

@@ -48,7 +48,7 @@ func (c *Client) CreateDNSRecord(
 
 	res := &CreateDNSRecordResponse{}
 
-	if httpErr, err := c.SendRequest(req, res, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, res, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 3 - 3
cli/cmd/api/git_repo.go

@@ -30,7 +30,7 @@ func (c *Client) ListGitRepos(
 	req = req.WithContext(ctx)
 	bodyResp := &ListGitRepoResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -70,7 +70,7 @@ func (c *Client) GetRepoZIPDownloadURL(
 	req = req.WithContext(ctx)
 	bodyResp := &GetRepoTarballDownloadURLResp{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -102,7 +102,7 @@ func (c *Client) ListGithubRepos(
 	req = req.WithContext(ctx)
 	bodyResp := &ListGithubReposResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 1 - 1
cli/cmd/api/github_action.go

@@ -54,7 +54,7 @@ func (c *Client) CreateGithubAction(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 3 - 3
cli/cmd/api/helm_repo.go

@@ -46,7 +46,7 @@ func (c *Client) CreateHelmRepo(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateHelmRepoResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -78,7 +78,7 @@ func (c *Client) ListHelmRepos(
 	req = req.WithContext(ctx)
 	bodyResp := &ListHelmRepoResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -111,7 +111,7 @@ func (c *Client) ListCharts(
 	req = req.WithContext(ctx)
 	bodyResp := &ListChartsResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 4 - 4
cli/cmd/api/integration.go

@@ -46,7 +46,7 @@ func (c *Client) CreateAWSIntegration(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateAWSIntegrationResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -91,7 +91,7 @@ func (c *Client) CreateGCPIntegration(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateGCPIntegrationResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -137,7 +137,7 @@ func (c *Client) CreateBasicAuthIntegration(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateBasicAuthIntegrationResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -169,7 +169,7 @@ func (c *Client) ListOAuthIntegrations(
 	req = req.WithContext(ctx)
 	bodyResp := &ListOAuthIntegrationResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 4 - 4
cli/cmd/api/k8s.go

@@ -37,7 +37,7 @@ func (c *Client) GetK8sNamespaces(
 	req = req.WithContext(ctx)
 	bodyResp := &GetK8sNamespacesResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -77,7 +77,7 @@ func (c *Client) GetKubeconfig(
 	req = req.WithContext(ctx)
 	bodyResp := &GetKubeconfigResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -116,7 +116,7 @@ func (c *Client) GetRelease(
 	req = req.WithContext(ctx)
 	bodyResp := &GetReleaseResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -155,7 +155,7 @@ func (c *Client) GetK8sAllPods(
 	req = req.WithContext(ctx)
 	bodyResp := &GetReleaseAllPodsResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 9 - 9
cli/cmd/api/project.go

@@ -29,7 +29,7 @@ func (c *Client) GetProject(ctx context.Context, projectID uint) (*GetProjectRes
 	req = req.WithContext(ctx)
 	bodyResp := &GetProjectResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -63,7 +63,7 @@ func (c *Client) GetProjectCluster(
 	req = req.WithContext(ctx)
 	bodyResp := &GetProjectClusterResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -95,7 +95,7 @@ func (c *Client) ListProjectClusters(
 	req = req.WithContext(ctx)
 	bodyResp := ListProjectClustersResponse{}
 
-	if httpErr, err := c.SendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -138,7 +138,7 @@ func (c *Client) CreateProject(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateProjectResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -186,7 +186,7 @@ func (c *Client) CreateProjectCandidates(
 	req = req.WithContext(ctx)
 	bodyResp := CreateProjectCandidatesResponse{}
 
-	if httpErr, err := c.SendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -219,7 +219,7 @@ func (c *Client) GetProjectCandidates(
 	req = req.WithContext(ctx)
 	bodyResp := GetProjectCandidatesResponse{}
 
-	if httpErr, err := c.SendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -261,7 +261,7 @@ func (c *Client) CreateProjectCluster(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateProjectClusterResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -290,7 +290,7 @@ func (c *Client) DeleteProjectCluster(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -319,7 +319,7 @@ func (c *Client) DeleteProject(ctx context.Context, projectID uint) (*DeleteProj
 	req = req.WithContext(ctx)
 	bodyResp := &DeleteProjectResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 13 - 13
cli/cmd/api/registry.go

@@ -48,7 +48,7 @@ func (c *Client) CreateECR(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateECRResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -95,7 +95,7 @@ func (c *Client) CreatePrivateRegistry(
 	req = req.WithContext(ctx)
 	bodyResp := &CreatePrivateRegistryResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -142,7 +142,7 @@ func (c *Client) CreateGCR(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateGCRResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -189,7 +189,7 @@ func (c *Client) CreateDOCR(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateDOCRResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -221,7 +221,7 @@ func (c *Client) ListRegistries(
 	req = req.WithContext(ctx)
 	bodyResp := &ListRegistryResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -250,7 +250,7 @@ func (c *Client) DeleteProjectRegistry(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -286,7 +286,7 @@ func (c *Client) GetECRAuthorizationToken(
 	bodyResp := &GetTokenResponse{}
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -326,7 +326,7 @@ func (c *Client) GetGCRAuthorizationToken(
 	bodyResp := &GetTokenResponse{}
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -355,7 +355,7 @@ func (c *Client) GetDockerhubAuthorizationToken(
 	bodyResp := &GetTokenResponse{}
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -395,7 +395,7 @@ func (c *Client) GetDOCRAuthorizationToken(
 	bodyResp := &GetTokenResponse{}
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -428,7 +428,7 @@ func (c *Client) ListRegistryRepositories(
 	req = req.WithContext(ctx)
 	bodyResp := &ListRegistryRepositoryResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -462,7 +462,7 @@ func (c *Client) ListImages(
 	req = req.WithContext(ctx)
 	bodyResp := &ListImagesResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -501,7 +501,7 @@ func (c *Client) CreateRepository(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 2 - 2
cli/cmd/api/template.go

@@ -25,7 +25,7 @@ func (c *Client) ListTemplates(
 
 	bodyResp := make([]*models.PorterChartList, 0)
 
-	if httpErr, err := c.SendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -54,7 +54,7 @@ func (c *Client) GetTemplate(
 
 	bodyResp := &models.PorterChartRead{}
 
-	if httpErr, err := c.SendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 7 - 7
cli/cmd/api/user.go

@@ -30,7 +30,7 @@ func (c *Client) AuthCheck(ctx context.Context) (*AuthCheckResponse, error) {
 
 	bodyResp := &AuthCheckResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -72,7 +72,7 @@ func (c *Client) Login(ctx context.Context, loginRequest *LoginRequest) (*LoginR
 	req = req.WithContext(ctx)
 	bodyResp := &LoginResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, false); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, false); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -97,7 +97,7 @@ func (c *Client) Logout(ctx context.Context) error {
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -142,7 +142,7 @@ func (c *Client) CreateUser(
 	req = req.WithContext(ctx)
 	bodyResp := &CreateUserResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, false); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, false); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -173,7 +173,7 @@ func (c *Client) GetUser(ctx context.Context, userID uint) (*GetUserResponse, er
 
 	bodyResp := &GetUserResponse{}
 
-	if httpErr, err := c.SendRequest(req, bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -203,7 +203,7 @@ func (c *Client) ListUserProjects(ctx context.Context, userID uint) (ListUserPro
 
 	bodyResp := ListUserProjectsResponse{}
 
-	if httpErr, err := c.SendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}
@@ -243,7 +243,7 @@ func (c *Client) DeleteUser(
 
 	req = req.WithContext(ctx)
 
-	if httpErr, err := c.SendRequest(req, nil, true); httpErr != nil || err != nil {
+	if httpErr, err := c.sendRequest(req, nil, true); httpErr != nil || err != nil {
 		if httpErr != nil {
 			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
 		}

+ 1 - 34
cli/cmd/deploy/deploy.go

@@ -1,13 +1,11 @@
 package deploy
 
 import (
-	"bytes"
 	"context"
 	"encoding/json"
 	"errors"
 	"fmt"
 	"io/ioutil"
-	"net/http"
 	"os"
 	"path/filepath"
 	"strings"
@@ -465,38 +463,7 @@ func (d *DeployAgent) downloadRepoToDir(downloadURL string) (string, error) {
 }
 
 func (d *DeployAgent) StreamEvent(event Event, token string) error {
-	form := StreamEventForm{
-		Event: event,
-		Token: token,
-	}
-
-	body := new(bytes.Buffer)
-	err := json.NewEncoder(body).Encode(form)
-
-	if err != nil {
-		return err
-	}
-
-	req, err := http.NewRequest(
-		"POST",
-		fmt.Sprintf("%s/projects/%d/releases/%s/steps", d.client.BaseURL, d.opts.ProjectID, d.release.Name),
-		body,
-	)
-
-	if err != nil {
-		return err
-	}
-
-	req = req.WithContext(context.Background())
-
-	if httpErr, err := d.client.SendRequest(req, nil, true); httpErr != nil || err != nil {
-		if httpErr != nil {
-			return fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
-		}
-		return err
-	}
-
-	return nil
+	return d.client.StreamEvent(event, token, d.opts.ProjectID, d.release.Name)
 }
 
 type NestedMapFieldNotFoundError struct {