-
Notifications
You must be signed in to change notification settings - Fork 1
/
arm_GET.go
40 lines (31 loc) · 861 Bytes
/
arm_GET.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
40
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
)
func ArmGet(rawUrl string, apiVersion string, jmespathQuery string) {
azureConfiguration := GetAzureConfiguration()
url := ArmUrl(azureConfiguration, rawUrl, apiVersion)
log.Debug("GET ", url)
req, reqErr := http.NewRequest("GET", url, nil)
if reqErr != nil {
log.Fatal(reqErr)
}
req.Header.Set("Authorization", "BEARER "+azureConfiguration.AccessToken)
resp, httpGetErr := http.DefaultClient.Do(req)
if httpGetErr != nil {
log.Fatal(reqErr)
}
defer resp.Body.Close()
respBody, readErr := ioutil.ReadAll(resp.Body)
if httpGetErr != nil {
log.Fatal(readErr)
}
if resp.StatusCode > 399 {
log.Fatal("HTTP StatusCode ", resp.StatusCode, "\n", jsonPrettyPrint(respBody))
} else {
fmt.Print(applyJmespathToJson(respBody, jmespathQuery))
}
}