-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
57 lines (48 loc) · 1.48 KB
/
profile.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
package utils
import (
"io"
"net/http"
"os"
"path/filepath"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/pathutil"
"github.com/bitrise-io/go-xcode/profileutil"
)
// GetDefaultProvisioningProfile ...
func GetDefaultProvisioningProfile() (profileutil.ProvisioningProfileInfoModel, error) {
defaultProfileURL := os.Getenv("BITRISE_DEFAULT_PROVISION_URL")
if defaultProfileURL == "" {
return profileutil.ProvisioningProfileInfoModel{}, nil
}
tmpDir, err := pathutil.NormalizedOSTempDirPath("tmp_default_profile")
if err != nil {
return profileutil.ProvisioningProfileInfoModel{}, err
}
tmpDst := filepath.Join(tmpDir, "default.mobileprovision")
tmpDstFile, err := os.Create(tmpDst)
if err != nil {
return profileutil.ProvisioningProfileInfoModel{}, err
}
defer func() {
if err := tmpDstFile.Close(); err != nil {
log.Errorf("Failed to close file (%s), error: %s", tmpDst, err)
}
}()
response, err := http.Get(defaultProfileURL)
if err != nil {
return profileutil.ProvisioningProfileInfoModel{}, err
}
defer func() {
if err := response.Body.Close(); err != nil {
log.Errorf("Failed to close response body, error: %s", err)
}
}()
if _, err := io.Copy(tmpDstFile, response.Body); err != nil {
return profileutil.ProvisioningProfileInfoModel{}, err
}
defaultProfile, err := profileutil.NewProvisioningProfileInfoFromFile(tmpDst)
if err != nil {
return profileutil.ProvisioningProfileInfoModel{}, err
}
return defaultProfile, nil
}