| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- package client
- import (
- "context"
- "fmt"
- "github.com/porter-dev/porter/api/server/handlers/porter_app"
- "github.com/porter-dev/porter/api/types"
- )
- func (c *Client) NewGetPorterApp(
- ctx context.Context,
- projectID, clusterID uint,
- appName string,
- ) (*types.PorterApp, error) {
- resp := &types.PorterApp{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/applications/%s",
- projectID, clusterID, appName,
- ),
- nil,
- resp,
- )
- return resp, err
- }
- func (c *Client) NewCreatePorterApp(
- ctx context.Context,
- projectID, clusterID uint,
- appName string,
- req *types.CreatePorterAppRequest,
- ) (*types.PorterApp, error) {
- resp := &types.PorterApp{}
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/applications/%s",
- projectID, clusterID, appName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // NewCreateOrUpdatePorterAppEvent will create a porter app event if one does not exist, or else it will update the existing one if an ID is passed in the object
- func (c *Client) NewCreateOrUpdatePorterAppEvent(
- ctx context.Context,
- projectID, clusterID uint,
- appName string,
- req *types.CreateOrUpdatePorterAppEventRequest,
- ) (types.PorterAppEvent, error) {
- resp := &types.PorterAppEvent{}
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/applications/%s/events",
- projectID, clusterID, appName,
- ),
- req,
- resp,
- )
- return *resp, err
- }
- // TODO: remove these functions once they are no longer called (check telemetry)
- func (c *Client) GetPorterApp(
- ctx context.Context,
- projectID, clusterID uint,
- stackName string,
- ) (*types.PorterApp, error) {
- resp := &types.PorterApp{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/stacks/%s",
- projectID, clusterID, stackName,
- ),
- nil,
- resp,
- )
- return resp, err
- }
- func (c *Client) CreatePorterApp(
- ctx context.Context,
- projectID, clusterID uint,
- name string,
- req *types.CreatePorterAppRequest,
- ) (*types.PorterApp, error) {
- resp := &types.PorterApp{}
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/stacks/%s",
- projectID, clusterID, name,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // CreateOrUpdatePorterAppEvent will create a porter app event if one does not exist, or else it will update the existing one if an ID is passed in the object
- func (c *Client) CreateOrUpdatePorterAppEvent(
- ctx context.Context,
- projectID, clusterID uint,
- name string,
- req *types.CreateOrUpdatePorterAppEventRequest,
- ) (types.PorterAppEvent, error) {
- resp := &types.PorterAppEvent{}
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/stacks/%s/events",
- projectID, clusterID, name,
- ),
- req,
- resp,
- )
- return *resp, err
- }
- // ListEnvGroups (List all Env Groups for a given cluster)
- func (c *Client) ListEnvGroups(
- ctx context.Context,
- projectID, clusterID uint,
- ) (types.ListEnvironmentGroupsResponse, error) {
- resp := &types.ListEnvironmentGroupsResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/environment-groups",
- projectID, clusterID,
- ),
- nil,
- resp,
- )
- return *resp, err
- }
- // ParseYAML takes in a base64 encoded porter yaml and returns an app proto
- func (c *Client) ParseYAML(
- ctx context.Context,
- projectID, clusterID uint,
- b64Yaml string,
- ) (*porter_app.ParsePorterYAMLToProtoResponse, error) {
- resp := &porter_app.ParsePorterYAMLToProtoResponse{}
- req := &porter_app.ParsePorterYAMLToProtoRequest{
- B64Yaml: b64Yaml,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/parse",
- projectID, clusterID,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // ValidatePorterApp takes in a base64 encoded app definition that is potentially partial and returns a complete definition
- // using any previous app revisions and defaults
- func (c *Client) ValidatePorterApp(
- ctx context.Context,
- projectID, clusterID uint,
- base64AppProto string,
- deploymentTarget string,
- ) (*porter_app.ValidatePorterAppResponse, error) {
- resp := &porter_app.ValidatePorterAppResponse{}
- req := &porter_app.ValidatePorterAppRequest{
- Base64AppProto: base64AppProto,
- DeploymentTargetId: deploymentTarget,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/validate",
- projectID, clusterID,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // ApplyPorterApp takes in a base64 encoded app definition and applies it to the cluster
- func (c *Client) ApplyPorterApp(
- ctx context.Context,
- projectID, clusterID uint,
- base64AppProto string,
- deploymentTarget string,
- appRevisionID string,
- ) (*porter_app.ApplyPorterAppResponse, error) {
- resp := &porter_app.ApplyPorterAppResponse{}
- req := &porter_app.ApplyPorterAppRequest{
- Base64AppProto: base64AppProto,
- DeploymentTargetId: deploymentTarget,
- AppRevisionID: appRevisionID,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/apply",
- projectID, clusterID,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // DefaultDeploymentTarget returns the default deployment target for a given project and cluster
- func (c *Client) DefaultDeploymentTarget(
- ctx context.Context,
- projectID, clusterID uint,
- ) (*porter_app.DefaultDeploymentTargetResponse, error) {
- resp := &porter_app.DefaultDeploymentTargetResponse{}
- req := &porter_app.DefaultDeploymentTargetRequest{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/default-deployment-target",
- projectID, clusterID,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // CurrentAppRevision returns the currently deployed app revision for a given project, app name and deployment target
- func (c *Client) CurrentAppRevision(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string, deploymentTarget string,
- ) (*porter_app.LatestAppRevisionResponse, error) {
- resp := &porter_app.LatestAppRevisionResponse{}
- req := &porter_app.LatestAppRevisionRequest{
- DeploymentTargetID: deploymentTarget,
- }
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/latest",
- projectID, clusterID, appName,
- ),
- req,
- resp,
- )
- return resp, err
- }
|