~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/Azure/azure-sdk-for-go/storage/util.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package storage
 
2
 
 
3
import (
 
4
        "bytes"
 
5
        "crypto/hmac"
 
6
        "crypto/sha256"
 
7
        "encoding/base64"
 
8
        "encoding/xml"
 
9
        "fmt"
 
10
        "io"
 
11
        "io/ioutil"
 
12
        "net/http"
 
13
        "net/url"
 
14
        "time"
 
15
)
 
16
 
 
17
func (c Client) computeHmac256(message string) string {
 
18
        h := hmac.New(sha256.New, c.accountKey)
 
19
        h.Write([]byte(message))
 
20
        return base64.StdEncoding.EncodeToString(h.Sum(nil))
 
21
}
 
22
 
 
23
func currentTimeRfc1123Formatted() string {
 
24
        return timeRfc1123Formatted(time.Now().UTC())
 
25
}
 
26
 
 
27
func timeRfc1123Formatted(t time.Time) string {
 
28
        return t.Format(http.TimeFormat)
 
29
}
 
30
 
 
31
func mergeParams(v1, v2 url.Values) url.Values {
 
32
        out := url.Values{}
 
33
        for k, v := range v1 {
 
34
                out[k] = v
 
35
        }
 
36
        for k, v := range v2 {
 
37
                vals, ok := out[k]
 
38
                if ok {
 
39
                        vals = append(vals, v...)
 
40
                        out[k] = vals
 
41
                } else {
 
42
                        out[k] = v
 
43
                }
 
44
        }
 
45
        return out
 
46
}
 
47
 
 
48
func prepareBlockListRequest(blocks []Block) string {
 
49
        s := `<?xml version="1.0" encoding="utf-8"?><BlockList>`
 
50
        for _, v := range blocks {
 
51
                s += fmt.Sprintf("<%s>%s</%s>", v.Status, v.ID, v.Status)
 
52
        }
 
53
        s += `</BlockList>`
 
54
        return s
 
55
}
 
56
 
 
57
func xmlUnmarshal(body io.Reader, v interface{}) error {
 
58
        data, err := ioutil.ReadAll(body)
 
59
        if err != nil {
 
60
                return err
 
61
        }
 
62
        return xml.Unmarshal(data, v)
 
63
}
 
64
 
 
65
func xmlMarshal(v interface{}) (io.Reader, int, error) {
 
66
        b, err := xml.Marshal(v)
 
67
        if err != nil {
 
68
                return nil, 0, err
 
69
        }
 
70
        return bytes.NewReader(b), len(b), nil
 
71
}