-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathforce.go
84 lines (74 loc) · 2.45 KB
/
force.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"encoding/base64"
"fmt"
)
type ForceClient struct {
portType *MetadataPortType
loginResult *LoginResult
}
func NewForceClient(endpoint string, apiversion string) *ForceClient {
portType := NewMetadataPortType(fmt.Sprintf("https://%s/services/Soap/u/%s", endpoint, apiversion), true, nil)
return &ForceClient{portType: portType}
}
func (client *ForceClient) Login(username string, password string) error {
loginRequest := LoginRequest{Username: username, Password: password}
loginResponse, err := client.portType.Login(&loginRequest)
if err != nil {
return err
}
client.loginResult = &loginResponse.LoginResult
return nil
}
func (client *ForceClient) Deploy(buf []byte) (*DeployResponse, error) {
request := Deploy{
ZipFile: base64.StdEncoding.EncodeToString(buf),
DeployOptions: nil,
}
sessionHeader := SessionHeader{
SessionId: client.loginResult.SessionId,
}
client.portType.SetHeader(&sessionHeader)
client.portType.SetServerUrl(client.loginResult.MetadataServerUrl)
return client.portType.Deploy(&request)
}
func (client *ForceClient) CheckDeployStatus(resultId *ID) (*CheckDeployStatusResponse, error) {
check_request := CheckDeployStatus{AsyncProcessId: resultId, IncludeDetails: true}
return client.portType.CheckDeployStatus(&check_request)
}
func (client *ForceClient) Retrieve(request *Retrieve) (*RetrieveResponse, error) {
sessionHeader := SessionHeader{
SessionId: client.loginResult.SessionId,
}
client.portType.SetHeader(&sessionHeader)
client.portType.SetServerUrl(client.loginResult.MetadataServerUrl)
return client.portType.Retrieve(request)
}
func (client *ForceClient) CheckRetrieveStatus(id *ID) (*CheckRetrieveStatusResponse, error) {
request := CheckRetrieveStatus{
AsyncProcessId: id,
}
sessionHeader := SessionHeader{
SessionId: client.loginResult.SessionId,
}
client.portType.SetHeader(&sessionHeader)
client.portType.SetServerUrl(client.loginResult.MetadataServerUrl)
return client.portType.CheckRetrieveStatus(&request)
}
func createRetrieveRequest(metaPackageFile *MetaPackageFile) *Retrieve {
request := &Retrieve{
RetrieveRequest: &RetrieveRequest{
ApiVersion: metaPackageFile.Version,
Unpackaged: &Package{},
},
}
types := []*PackageTypeMembers{}
for _, metaType := range metaPackageFile.Types {
types = append(types, &PackageTypeMembers{
Name: metaType.Name,
Members: metaType.Members,
})
}
request.RetrieveRequest.Unpackaged.Types = types
return request
}