diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-11-03 00:21:05 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-11-03 16:32:53 +0800 |
commit | 3b62c145f8d699767e13770d1bb21d07c2ba9b46 (patch) | |
tree | 341fbd27e33b08431a6b950f009d6230d502fd3e /internal/build/azure.go | |
parent | 1b73c79234a1597f1f8b11cff5e01b935f6817a2 (diff) | |
download | go-tangerine-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar go-tangerine-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.gz go-tangerine-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.bz2 go-tangerine-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.lz go-tangerine-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.xz go-tangerine-3b62c145f8d699767e13770d1bb21d07c2ba9b46.tar.zst go-tangerine-3b62c145f8d699767e13770d1bb21d07c2ba9b46.zip |
travis, build: implement uploading archives to azure
Diffstat (limited to 'internal/build/azure.go')
-rw-r--r-- | internal/build/azure.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/build/azure.go b/internal/build/azure.go new file mode 100644 index 000000000..124c3f6ec --- /dev/null +++ b/internal/build/azure.go @@ -0,0 +1,58 @@ +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. + +package build + +import ( + "os" + + "github.com/Azure/azure-sdk-for-go/storage" +) + +// AzureBlobstoreConfig is an authentication and configuration struct containing +// the data needed by the Azure SDK to interact with a speicifc container in the +// blobstore. +type AzureBlobstoreConfig struct { + Account string // Account name to authorize API requests with + Token string // Access token for the above account + Container string // Blob container to upload files into +} + +// AzureBlobstoreUpload uploads a local file to the Azure Blob Storage. Note, this +// method assumes a max file size of 64MB (Azure limitation). Larger files will +// need a multi API call approach implemented. +// +// See: https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx#Anchor_3 +func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig) error { + // Create an authenticated client against the Azure cloud + rawClient, err := storage.NewBasicClient(config.Account, config.Token) + if err != nil { + return err + } + client := rawClient.GetBlobService() + + // Stream the file to upload into the designated blobstore container + in, err := os.Open(path) + if err != nil { + return err + } + defer in.Close() + + info, err := in.Stat() + if err != nil { + return err + } + return client.CreateBlockBlobFromReader(config.Container, name, uint64(info.Size()), in, nil) +} |