github.com/digdeepmining/go-atheios@v1.5.13-0.20180902133602-d5687a2e6f43/internal/build/azure.go (about) 1 // Copyright 2016 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package build 18 19 import ( 20 "fmt" 21 "os" 22 23 "github.com/Azure/azure-sdk-for-go/storage" 24 ) 25 26 // AzureBlobstoreConfig is an authentication and configuration struct containing 27 // the data needed by the Azure SDK to interact with a speicifc container in the 28 // blobstore. 29 type AzureBlobstoreConfig struct { 30 Account string // Account name to authorize API requests with 31 Token string // Access token for the above account 32 Container string // Blob container to upload files into 33 } 34 35 // AzureBlobstoreUpload uploads a local file to the Azure Blob Storage. Note, this 36 // method assumes a max file size of 64MB (Azure limitation). Larger files will 37 // need a multi API call approach implemented. 38 // 39 // See: https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx#Anchor_3 40 func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig) error { 41 if *DryRunFlag { 42 fmt.Printf("would upload %q to %s/%s/%s\n", path, config.Account, config.Container, name) 43 return nil 44 } 45 46 // Create an authenticated client against the Azure cloud 47 rawClient, err := storage.NewBasicClient(config.Account, config.Token) 48 if err != nil { 49 return err 50 } 51 client := rawClient.GetBlobService() 52 53 // Stream the file to upload into the designated blobstore container 54 in, err := os.Open(path) 55 if err != nil { 56 return err 57 } 58 defer in.Close() 59 60 info, err := in.Stat() 61 if err != nil { 62 return err 63 } 64 return client.CreateBlockBlobFromReader(config.Container, name, uint64(info.Size()), in, nil) 65 }