forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_application_source.go
33 lines (26 loc) · 1000 Bytes
/
copy_application_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package copyapplicationsource
import (
"fmt"
"strings"
"github.com/cloudfoundry/cli/cf/configuration/coreconfig"
"github.com/cloudfoundry/cli/cf/net"
)
//go:generate counterfeiter . Repository
type Repository interface {
CopyApplication(sourceAppGUID, targetAppGUID string) error
}
type CloudControllerApplicationSourceRepository struct {
config coreconfig.Reader
gateway net.Gateway
}
func NewCloudControllerCopyApplicationSourceRepository(config coreconfig.Reader, gateway net.Gateway) *CloudControllerApplicationSourceRepository {
return &CloudControllerApplicationSourceRepository{
config: config,
gateway: gateway,
}
}
func (repo *CloudControllerApplicationSourceRepository) CopyApplication(sourceAppGUID, targetAppGUID string) error {
url := fmt.Sprintf("/v2/apps/%s/copy_bits", targetAppGUID)
body := fmt.Sprintf(`{"source_app_guid":"%s"}`, sourceAppGUID)
return repo.gateway.CreateResource(repo.config.APIEndpoint(), url, strings.NewReader(body), new(interface{}))
}