github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/api/copyapplicationsource/copy_application_source.go (about)

     1  package copyapplicationsource
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     8  	"code.cloudfoundry.org/cli/cf/net"
     9  )
    10  
    11  //go:generate counterfeiter . Repository
    12  
    13  type Repository interface {
    14  	CopyApplication(sourceAppGUID, targetAppGUID string) error
    15  }
    16  
    17  type CloudControllerApplicationSourceRepository struct {
    18  	config  coreconfig.Reader
    19  	gateway net.Gateway
    20  }
    21  
    22  func NewCloudControllerCopyApplicationSourceRepository(config coreconfig.Reader, gateway net.Gateway) *CloudControllerApplicationSourceRepository {
    23  	return &CloudControllerApplicationSourceRepository{
    24  		config:  config,
    25  		gateway: gateway,
    26  	}
    27  }
    28  
    29  func (repo *CloudControllerApplicationSourceRepository) CopyApplication(sourceAppGUID, targetAppGUID string) error {
    30  	url := fmt.Sprintf("/v2/apps/%s/copy_bits", targetAppGUID)
    31  	body := fmt.Sprintf(`{"source_app_guid":"%s"}`, sourceAppGUID)
    32  	return repo.gateway.CreateResource(repo.config.APIEndpoint(), url, strings.NewReader(body), new(interface{}))
    33  }