github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/actor/v3action/application_manifest.go (about)

     1  package v3action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     6  )
     7  
     8  //go:generate counterfeiter . ManifestParser
     9  
    10  type ManifestParser interface {
    11  	AppNames() []string
    12  	RawAppManifest(name string) ([]byte, error)
    13  }
    14  
    15  // ApplyApplicationManifest reads in the manifest from the path and provides it
    16  // to the cloud controller.
    17  func (actor Actor) ApplyApplicationManifest(parser ManifestParser, spaceGUID string) (Warnings, error) {
    18  	var allWarnings Warnings
    19  
    20  	for _, appName := range parser.AppNames() {
    21  		rawManifest, err := parser.RawAppManifest(appName)
    22  		if err != nil {
    23  			return allWarnings, err
    24  		}
    25  
    26  		app, getAppWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
    27  
    28  		allWarnings = append(allWarnings, getAppWarnings...)
    29  		if err != nil {
    30  			return allWarnings, err
    31  		}
    32  
    33  		jobURL, applyManifestWarnings, err := actor.CloudControllerClient.UpdateApplicationApplyManifest(app.GUID, rawManifest)
    34  		allWarnings = append(allWarnings, applyManifestWarnings...)
    35  		if err != nil {
    36  			return allWarnings, err
    37  		}
    38  
    39  		pollWarnings, err := actor.CloudControllerClient.PollJob(jobURL)
    40  		allWarnings = append(allWarnings, pollWarnings...)
    41  		if err != nil {
    42  			if newErr, ok := err.(ccerror.V3JobFailedError); ok {
    43  				return allWarnings, actionerror.ApplicationManifestError{Message: newErr.Detail}
    44  			}
    45  			return allWarnings, err
    46  		}
    47  	}
    48  
    49  	return allWarnings, nil
    50  }