summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lwirzenius@wikimedia.org>2020-01-02 18:23:17 +0200
committerLars Wirzenius <lwirzenius@wikimedia.org>2020-01-02 18:23:17 +0200
commit384ca68f54caec5a231c5662829ff44942be45af (patch)
treee643005ace3fe2336cd20b4c79938798e0026363
parentb05ab7ddfba7552d4a35e345882e0fcf3d8b3dea (diff)
downloadickadmin-384ca68f54caec5a231c5662829ff44942be45af.tar.gz
Change: retrieve and list all builds
-rw-r--r--ickadmin.go53
1 files changed, 50 insertions, 3 deletions
diff --git a/ickadmin.go b/ickadmin.go
index f3ca9a8..ecc97c2 100644
--- a/ickadmin.go
+++ b/ickadmin.go
@@ -26,6 +26,17 @@ type project struct {
Project string
}
+type builds struct {
+ Builds []build
+}
+
+type build struct {
+ Project string
+ Build_id string
+ Status string
+ Exit_code int
+}
+
type config struct {
idp string
id string
@@ -61,8 +72,16 @@ func main() {
if projects == nil {
os.Exit(1)
}
- for _, p := range projects.Projects {
- fmt.Printf("project: %v\n", p.Project)
+
+ builds, err := get_builds(cfg, token)
+ if err != nil {
+ os.Exit(1)
+ }
+ if builds == nil {
+ os.Exit(1)
+ }
+ for _, b := range builds.Builds {
+ fmt.Printf("build: %v\n", b.Build_id)
}
}
@@ -87,7 +106,7 @@ func get_creds(filename string) (*config, error) {
func get_access_token(cfg *config) (string, error) {
data := url.Values{}
data.Add("grant_type", "client_credentials")
- data.Add("scope", "uapi_projects_get")
+ data.Add("scope", "uapi_projects_get uapi_builds_get")
url := fmt.Sprintf("%s/token", cfg.idp)
@@ -142,3 +161,31 @@ func get_projects(cfg *config, token string) (*projects, error) {
return &res, nil
}
+
+func get_builds(cfg *config, token string) (*builds, error) {
+ url := fmt.Sprintf("%s/builds", cfg.idp)
+
+ client := &http.Client{}
+ req, err := http.NewRequest("GET", url, nil)
+ req.Header.Add("Authorization", fmt.Sprintf("bearer %s", token))
+
+ resp, err := client.Do(req)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "GET %s: %v\n", url, err)
+ return nil, err
+ }
+
+ bodyText, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "reading HTTP response: %v\n", err)
+ return nil, err
+ }
+
+// s := string(bodyText)
+// fmt.Printf("%v", s)
+
+ res := builds{}
+ json.Unmarshal(bodyText, &res)
+
+ return &res, nil
+}