diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/build/azure.go | 50 | ||||
-rw-r--r-- | internal/build/env.go | 7 |
2 files changed, 55 insertions, 2 deletions
diff --git a/internal/build/azure.go b/internal/build/azure.go index 32f535558..2081a9a0b 100644 --- a/internal/build/azure.go +++ b/internal/build/azure.go @@ -20,7 +20,7 @@ import ( "fmt" "os" - "github.com/Azure/azure-sdk-for-go/storage" + storage "github.com/Azure/azure-storage-go" ) // AzureBlobstoreConfig is an authentication and configuration struct containing @@ -42,7 +42,6 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig) fmt.Printf("would upload %q to %s/%s/%s\n", path, config.Account, config.Container, name) return nil } - // Create an authenticated client against the Azure cloud rawClient, err := storage.NewBasicClient(config.Account, config.Token) if err != nil { @@ -63,3 +62,50 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig) } return client.CreateBlockBlobFromReader(config.Container, name, uint64(info.Size()), in, nil) } + +// AzureBlobstoreList lists all the files contained within an azure blobstore. +func AzureBlobstoreList(config AzureBlobstoreConfig) ([]storage.Blob, error) { + // Create an authenticated client against the Azure cloud + rawClient, err := storage.NewBasicClient(config.Account, config.Token) + if err != nil { + return nil, err + } + client := rawClient.GetBlobService() + + // List all the blobs from the container and return them + container := client.GetContainerReference(config.Container) + + blobs, err := container.ListBlobs(storage.ListBlobsParameters{ + MaxResults: 1024 * 1024 * 1024, // Yes, fetch all of them + Timeout: 3600, // Yes, wait for all of them + }) + if err != nil { + return nil, err + } + return blobs.Blobs, nil +} + +// AzureBlobstoreDelete iterates over a list of files to delete and removes them +// from the blobstore. +func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []storage.Blob) error { + if *DryRunFlag { + for _, blob := range blobs { + fmt.Printf("would delete %s (%s) from %s/%s\n", blob.Name, blob.Properties.LastModified, config.Account, config.Container) + } + return nil + } + // Create an authenticated client against the Azure cloud + rawClient, err := storage.NewBasicClient(config.Account, config.Token) + if err != nil { + return err + } + client := rawClient.GetBlobService() + + // Iterate over the blobs and delete them + for _, blob := range blobs { + if err := client.DeleteBlob(config.Container, blob.Name, nil); err != nil { + return err + } + } + return nil +} diff --git a/internal/build/env.go b/internal/build/env.go index 15b2dfe41..c47681ebe 100644 --- a/internal/build/env.go +++ b/internal/build/env.go @@ -30,6 +30,7 @@ var ( GitTagFlag = flag.String("git-tag", "", `Overrides git tag being built`) BuildnumFlag = flag.String("buildnum", "", `Overrides CI build number`) PullRequestFlag = flag.Bool("pull-request", false, `Overrides pull request status of the build`) + CronJobFlag = flag.Bool("cron-job", false, `Overrides cron job status of the build`) ) // Environment contains metadata provided by the build environment. @@ -39,6 +40,7 @@ type Environment struct { Commit, Branch, Tag string // Git info Buildnum string IsPullRequest bool + IsCronJob bool } func (env Environment) String() string { @@ -59,6 +61,7 @@ func Env() Environment { Tag: os.Getenv("TRAVIS_TAG"), Buildnum: os.Getenv("TRAVIS_BUILD_NUMBER"), IsPullRequest: os.Getenv("TRAVIS_PULL_REQUEST") != "false", + IsCronJob: os.Getenv("TRAVIS_EVENT_TYPE") == "cron", } case os.Getenv("CI") == "True" && os.Getenv("APPVEYOR") == "True": return Environment{ @@ -69,6 +72,7 @@ func Env() Environment { Tag: os.Getenv("APPVEYOR_REPO_TAG_NAME"), Buildnum: os.Getenv("APPVEYOR_BUILD_NUMBER"), IsPullRequest: os.Getenv("APPVEYOR_PULL_REQUEST_NUMBER") != "", + IsCronJob: os.Getenv("APPVEYOR_SCHEDULED_BUILD") == "True", } default: return LocalEnv() @@ -118,5 +122,8 @@ func applyEnvFlags(env Environment) Environment { if *PullRequestFlag { env.IsPullRequest = true } + if *CronJobFlag { + env.IsCronJob = true + } return env } |