/
helpers.go
39 lines (36 loc) · 1.17 KB
/
helpers.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
package collector
import (
"context"
"fmt"
jenkinsv1 "github.com/jenkins-x/jx/pkg/apis/jenkins.io/v1"
"github.com/jenkins-x/jx/pkg/gits"
"github.com/pkg/errors"
"gocloud.dev/blob"
"time"
// lets import all the blob providers we need
_ "gocloud.dev/blob/azureblob"
_ "gocloud.dev/blob/fileblob"
_ "gocloud.dev/blob/gcsblob"
_ "gocloud.dev/blob/s3blob"
)
// NewCollector creates a new collector from the storage configuration
func NewCollector(storageLocation *jenkinsv1.StorageLocation, settings *jenkinsv1.TeamSettings, gitter gits.Gitter) (Collector, error) {
classifier := storageLocation.Classifier
if classifier == "" {
classifier = "default"
}
gitURL := storageLocation.GitURL
if gitURL != "" {
return NewGitCollector(gitter, gitURL, storageLocation.GetGitBranch())
}
ctx, _ := context.WithTimeout(context.Background(), time.Second*20)
u := storageLocation.BucketURL
if u == "" {
return nil, fmt.Errorf("No GitURL or BucketURL is configured for the storage location in the TeamSettings")
}
bucket, err := blob.Open(ctx, u)
if err != nil {
return nil, errors.Wrapf(err, "failed to open bucket %s", u)
}
return NewBucketCollector(u, bucket, classifier)
}