| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885 |
- package client
- import (
- "context"
- "fmt"
- "github.com/porter-dev/porter/api/server/handlers/porter_app"
- "github.com/porter-dev/porter/internal/models"
- appInternal "github.com/porter-dev/porter/internal/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,
- appName string,
- ) (*porter_app.ParsePorterYAMLToProtoResponse, error) {
- resp := &porter_app.ParsePorterYAMLToProtoResponse{}
- req := &porter_app.ParsePorterYAMLToProtoRequest{
- B64Yaml: b64Yaml,
- AppName: appName,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/parse",
- projectID, clusterID,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // GetAppManifests returns the manifests for a given app based on the latest successful app revision
- func (c *Client) GetAppManifests(
- ctx context.Context,
- projectID, clusterID uint,
- appName string,
- ) (*porter_app.AppManifestsResponse, error) {
- resp := &porter_app.AppManifestsResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/manifests",
- projectID, clusterID, appName,
- ),
- nil,
- resp,
- )
- return resp, err
- }
- // ValidatePorterAppInput is the input struct to ValidatePorterApp
- type ValidatePorterAppInput struct {
- ProjectID uint
- ClusterID uint
- AppName string
- Base64AppProto string
- Base64AppOverrides string
- DeploymentTarget string
- CommitSHA string
- ImageTagOverride string
- }
- // 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,
- inp ValidatePorterAppInput,
- ) (*porter_app.ValidatePorterAppResponse, error) {
- resp := &porter_app.ValidatePorterAppResponse{}
- req := &porter_app.ValidatePorterAppRequest{
- AppName: inp.AppName,
- Base64AppProto: inp.Base64AppProto,
- Base64AppOverrides: inp.Base64AppOverrides,
- DeploymentTargetId: inp.DeploymentTarget,
- CommitSHA: inp.CommitSHA,
- ImageTagOverride: inp.ImageTagOverride,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/validate",
- inp.ProjectID, inp.ClusterID,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // ApplyPorterAppInput is the input struct to ApplyPorterApp
- type ApplyPorterAppInput struct {
- ProjectID uint
- ClusterID uint
- Base64AppProto string
- DeploymentTarget string
- AppRevisionID string
- ForceBuild bool
- Variables map[string]string
- Secrets map[string]string
- HardEnvUpdate bool
- }
- // ApplyPorterApp takes in a base64 encoded app definition and applies it to the cluster
- func (c *Client) ApplyPorterApp(
- ctx context.Context,
- inp ApplyPorterAppInput,
- ) (*porter_app.ApplyPorterAppResponse, error) {
- resp := &porter_app.ApplyPorterAppResponse{}
- req := &porter_app.ApplyPorterAppRequest{
- Base64AppProto: inp.Base64AppProto,
- DeploymentTargetId: inp.DeploymentTarget,
- AppRevisionID: inp.AppRevisionID,
- ForceBuild: inp.ForceBuild,
- Variables: inp.Variables,
- Secrets: inp.Secrets,
- HardEnvUpdate: inp.HardEnvUpdate,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/apply",
- inp.ProjectID, inp.ClusterID,
- ),
- req,
- resp,
- postRequestOpts{
- retryCount: 3,
- onlyRetry500: true,
- },
- )
- return resp, err
- }
- // UpdateAppInput is the input struct to UpdateApp
- type UpdateAppInput struct {
- ProjectID uint
- ClusterID uint
- Name string
- ImageTagOverride string
- GitSource porter_app.GitSource
- DeploymentTargetId string
- CommitSHA string
- AppRevisionID string
- Base64AppProto string
- Base64PorterYAML string
- IsEnvOverride bool
- }
- // UpdateApp updates a porter app
- func (c *Client) UpdateApp(
- ctx context.Context,
- inp UpdateAppInput,
- ) (*porter_app.UpdateAppResponse, error) {
- resp := &porter_app.UpdateAppResponse{}
- req := &porter_app.UpdateAppRequest{
- Name: inp.Name,
- GitSource: inp.GitSource,
- DeploymentTargetId: inp.DeploymentTargetId,
- CommitSHA: inp.CommitSHA,
- ImageTagOverride: inp.ImageTagOverride,
- AppRevisionID: inp.AppRevisionID,
- Base64AppProto: inp.Base64AppProto,
- Base64PorterYAML: inp.Base64PorterYAML,
- IsEnvOverride: inp.IsEnvOverride,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/update",
- inp.ProjectID, inp.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
- }
- // CurrentAppRevisionInput is the input struct to CurrentAppRevision
- type CurrentAppRevisionInput struct {
- ProjectID uint
- ClusterID uint
- AppName string
- // DeploymentTargetName is the name of the deployment target to get the current app revision for. One of this or DeploymentTargetID must be set.
- DeploymentTargetName string
- // DeploymentTargetID is the id of the deployment target to get the current app revision for. One of this or DeploymentTargetName must be set.
- DeploymentTargetID string
- }
- // CurrentAppRevision returns the currently deployed app revision for a given project, app name and deployment target
- func (c *Client) CurrentAppRevision(
- ctx context.Context,
- input CurrentAppRevisionInput,
- ) (*porter_app.LatestAppRevisionResponse, error) {
- resp := &porter_app.LatestAppRevisionResponse{}
- req := &porter_app.LatestAppRevisionRequest{
- DeploymentTargetName: input.DeploymentTargetName,
- DeploymentTargetID: input.DeploymentTargetID,
- }
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/latest",
- input.ProjectID, input.ClusterID, input.AppName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // CreatePorterAppDBEntryInput is the input struct to CreatePorterAppDBEntry
- type CreatePorterAppDBEntryInput struct {
- AppName string
- GitRepoName string
- GitRepoID uint
- GitBranch string
- ImageRepository string
- PorterYamlPath string
- ImageTag string
- Local bool
- DeploymentTargetID string
- }
- // CreatePorterAppDBEntry creates an entry in the porter app
- func (c *Client) CreatePorterAppDBEntry(
- ctx context.Context,
- projectID uint, clusterID uint,
- inp CreatePorterAppDBEntryInput,
- ) error {
- var sourceType appInternal.SourceType
- var image *appInternal.Image
- if inp.Local {
- sourceType = appInternal.SourceType_Local
- }
- if inp.GitRepoName != "" {
- sourceType = appInternal.SourceType_Github
- }
- if inp.ImageRepository != "" {
- sourceType = appInternal.SourceType_DockerRegistry
- image = &appInternal.Image{
- Repository: inp.ImageRepository,
- Tag: inp.ImageTag,
- }
- }
- req := &porter_app.CreateAppRequest{
- Name: inp.AppName,
- SourceType: sourceType,
- GitSource: porter_app.GitSource{
- GitBranch: inp.GitBranch,
- GitRepoName: inp.GitRepoName,
- GitRepoID: inp.GitRepoID,
- },
- Image: image,
- PorterYamlPath: inp.PorterYamlPath,
- DeploymentTargetID: inp.DeploymentTargetID,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/create",
- projectID, clusterID,
- ),
- req,
- &types.PorterApp{},
- )
- return err
- }
- // CreateSubdomain returns a subdomain for a given service that point to the ingress-nginx service in the cluster
- func (c *Client) CreateSubdomain(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string, serviceName string,
- ) (*porter_app.CreateSubdomainResponse, error) {
- resp := &porter_app.CreateSubdomainResponse{}
- req := &porter_app.CreateSubdomainRequest{
- ServiceName: serviceName,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/subdomain",
- projectID, clusterID, appName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // PredeployStatus checks the current status of a predeploy job for an app revision
- func (c *Client) PredeployStatus(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string, appRevisionId string,
- ) (*porter_app.PredeployStatusResponse, error) {
- resp := &porter_app.PredeployStatusResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/%s/predeploy-status",
- projectID, clusterID, appName, appRevisionId,
- ),
- nil,
- resp,
- )
- if resp.Status == "" {
- return nil, fmt.Errorf("no predeploy status found")
- }
- return resp, err
- }
- // GetRevision returns an app revision
- func (c *Client) GetRevision(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string, appRevisionId string,
- ) (*porter_app.GetAppRevisionResponse, error) {
- resp := &porter_app.GetAppRevisionResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/revisions/%s",
- projectID, clusterID, appName, appRevisionId,
- ),
- nil,
- resp,
- )
- return resp, err
- }
- // GetRevisionStatus returns the status of an app revision
- func (c *Client) GetRevisionStatus(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string, appRevisionId string,
- ) (*porter_app.GetAppRevisionStatusResponse, error) {
- resp := &porter_app.GetAppRevisionStatusResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/revisions/%s/status",
- projectID, clusterID, appName, appRevisionId,
- ),
- nil,
- resp,
- )
- return resp, err
- }
- // UpdateRevisionStatus updates the status of an app revision
- func (c *Client) UpdateRevisionStatus(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string, appRevisionId string,
- status models.AppRevisionStatus,
- ) (*porter_app.UpdateAppRevisionStatusResponse, error) {
- resp := &porter_app.UpdateAppRevisionStatusResponse{}
- req := &porter_app.UpdateAppRevisionStatusRequest{
- Status: status,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/revisions/%s",
- projectID, clusterID, appName, appRevisionId,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // GetBuildEnv returns the build environment for a given app proto
- func (c *Client) GetBuildEnv(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string, appRevisionId string,
- ) (*porter_app.GetBuildEnvResponse, error) {
- resp := &porter_app.GetBuildEnvResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/revisions/%s/build-env",
- projectID, clusterID, appName, appRevisionId,
- ),
- nil,
- resp,
- )
- return resp, err
- }
- // GetAppEnvVariables returns all env variables for a given app
- func (c *Client) GetAppEnvVariables(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string,
- ) (*porter_app.AppEnvVariablesResponse, error) {
- resp := &porter_app.AppEnvVariablesResponse{}
- req := &porter_app.AppEnvVariablesRequest{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/env-variables",
- projectID, clusterID, appName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // GetBuildFromRevision returns the build environment for a given app proto
- func (c *Client) GetBuildFromRevision(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string, appRevisionId string,
- ) (*porter_app.GetBuildFromRevisionResponse, error) {
- resp := &porter_app.GetBuildFromRevisionResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/revisions/%s/build",
- projectID, clusterID, appName, appRevisionId,
- ),
- nil,
- resp,
- )
- return resp, err
- }
- // ReportRevisionStatusInput is the input struct to ReportRevisionStatus
- type ReportRevisionStatusInput struct {
- ProjectID uint
- ClusterID uint
- AppName string
- AppRevisionID string
- PRNumber int
- CommitSHA string
- }
- // ReportRevisionStatus reports the status of an app revision to external services
- func (c *Client) ReportRevisionStatus(
- ctx context.Context,
- inp ReportRevisionStatusInput,
- ) (*porter_app.ReportRevisionStatusResponse, error) {
- resp := &porter_app.ReportRevisionStatusResponse{}
- req := &porter_app.ReportRevisionStatusRequest{
- PRNumber: inp.PRNumber,
- CommitSHA: inp.CommitSHA,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/revisions/%s/status",
- inp.ProjectID, inp.ClusterID, inp.AppName, inp.AppRevisionID,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // CreateOrUpdateAppEnvironment updates the app environment group and creates it if it doesn't exist
- func (c *Client) CreateOrUpdateAppEnvironment(
- ctx context.Context,
- projectID uint, clusterID uint,
- appName string,
- deploymentTargetID string,
- variables map[string]string,
- secrets map[string]string,
- Base64AppProto string,
- ) (*porter_app.UpdateAppEnvironmentResponse, error) {
- resp := &porter_app.UpdateAppEnvironmentResponse{}
- req := &porter_app.UpdateAppEnvironmentRequest{
- DeploymentTargetID: deploymentTargetID,
- Variables: variables,
- Secrets: secrets,
- HardUpdate: false,
- Base64AppProto: Base64AppProto,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/update-environment",
- projectID, clusterID, appName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // PorterYamlV2Pods gets all pods for a given deployment target id and app name
- func (c *Client) PorterYamlV2Pods(
- ctx context.Context,
- projectID, clusterID uint,
- porterAppName string,
- deploymentTargetName string,
- ) (*types.GetReleaseAllPodsResponse, error) {
- req := &porter_app.PodStatusRequest{
- DeploymentTargetName: deploymentTargetName,
- }
- resp := &types.GetReleaseAllPodsResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/pods",
- projectID, clusterID,
- porterAppName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // UpdateImage updates the image for a porter app (porter yaml v2 only)
- func (c *Client) UpdateImage(
- ctx context.Context,
- projectID, clusterID uint,
- appName, deploymentTargetName, tag string,
- ) (*porter_app.UpdateImageResponse, error) {
- req := &porter_app.UpdateImageRequest{
- Tag: tag,
- DeploymentTargetName: deploymentTargetName,
- }
- resp := &porter_app.UpdateImageResponse{}
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/update-image",
- projectID, clusterID, appName,
- ),
- &req,
- resp,
- )
- return resp, err
- }
- // ListAppRevisions lists the last ten app revisions for a given app
- func (c *Client) ListAppRevisions(
- ctx context.Context,
- projectID, clusterID uint,
- appName string,
- deploymentTargetID string,
- ) (*porter_app.ListAppRevisionsResponse, error) {
- resp := &porter_app.ListAppRevisionsResponse{}
- req := &porter_app.ListAppRevisionsRequest{
- DeploymentTargetID: deploymentTargetID,
- }
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/revisions",
- projectID, clusterID,
- appName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // RollbackRevision reverts an app to a previous revision
- func (c *Client) RollbackRevision(
- ctx context.Context,
- projectID, clusterID uint,
- appName string,
- deploymentTargetName string,
- ) (*porter_app.RollbackAppRevisionResponse, error) {
- resp := &porter_app.RollbackAppRevisionResponse{}
- req := &porter_app.RollbackAppRevisionRequest{
- DeploymentTargetName: deploymentTargetName,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/rollback",
- projectID, clusterID,
- appName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // UseNewApplyLogic checks whether the CLI should use the new apply logic
- func (c *Client) UseNewApplyLogic(
- ctx context.Context,
- projectID, clusterID uint,
- ) (*porter_app.UseNewApplyLogicResponse, error) {
- resp := &porter_app.UseNewApplyLogicResponse{}
- req := &porter_app.UseNewApplyLogicRequest{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/use-new-apply-logic",
- projectID, clusterID,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // RunAppJob runs a job for an app
- func (c *Client) RunAppJob(
- ctx context.Context,
- projectID, clusterID uint,
- appName string, jobName string,
- deploymentTargetName string,
- ) (*porter_app.RunAppJobResponse, error) {
- resp := &porter_app.RunAppJobResponse{}
- req := &porter_app.RunAppJobRequest{
- ServiceName: jobName,
- DeploymentTargetName: deploymentTargetName,
- }
- err := c.postRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/run",
- projectID, clusterID,
- appName,
- ),
- req,
- resp,
- )
- return resp, err
- }
- // RunAppJobStatusInput contains all the information necessary to check the status of a job
- type RunAppJobStatusInput struct {
- // AppName is the name of the app associated with the job
- AppName string
- // Cluster is the id of the cluster against which to retrieve a helm agent for
- ClusterID uint
- // DeploymentTargetName is the id of the deployment target the job was run against
- DeploymentTargetName string
- // ServiceName is the name of the app service that was triggered
- ServiceName string
- // JobRunID is the UID returned from the /apps/{porter_app_name}/run endpoint
- JobRunID string
- // ProjectID is the project in which the cluster exists
- ProjectID uint
- }
- // RunAppJobStatus gets the status for a job app run
- func (c *Client) RunAppJobStatus(
- ctx context.Context,
- input RunAppJobStatusInput,
- ) (*porter_app.AppJobRunStatusResponse, error) {
- resp := &porter_app.AppJobRunStatusResponse{}
- req := &porter_app.AppJobRunStatusRequest{
- DeploymentTargetName: input.DeploymentTargetName,
- JobRunID: input.JobRunID,
- ServiceName: input.ServiceName,
- }
- err := c.getRequest(
- fmt.Sprintf(
- "/projects/%d/clusters/%d/apps/%s/run-status",
- input.ProjectID, input.ClusterID,
- input.AppName,
- ),
- req,
- resp,
- )
- return resp, err
- }
|