github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/api/copy_application_source/copy_application_source.go (about)

     1  package copy_application_source
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/cloudfoundry/cli/cf/configuration/core_config"
     8  	"github.com/cloudfoundry/cli/cf/net"
     9  )
    10  
    11  type CopyApplicationSourceRepository interface {
    12  	CopyApplication(sourceAppGuid, targetAppGuid string) error
    13  }
    14  
    15  type CloudControllerApplicationSourceRepository struct {
    16  	config  core_config.Reader
    17  	gateway net.Gateway
    18  }
    19  
    20  func NewCloudControllerCopyApplicationSourceRepository(config core_config.Reader, gateway net.Gateway) *CloudControllerApplicationSourceRepository {
    21  	return &CloudControllerApplicationSourceRepository{
    22  		config:  config,
    23  		gateway: gateway,
    24  	}
    25  }
    26  
    27  func (repo *CloudControllerApplicationSourceRepository) CopyApplication(sourceAppGuid, targetAppGuid string) error {
    28  	url := fmt.Sprintf("/v2/apps/%s/copy_bits", targetAppGuid)
    29  	body := fmt.Sprintf(`{"source_app_guid":"%s"}`, sourceAppGuid)
    30  	return repo.gateway.CreateResource(repo.config.ApiEndpoint(), url, strings.NewReader(body), new(interface{}))
    31  }