github.com/buildkite/cli
Advanced tools
| #!/bin/bash | ||
| set -euo pipefail | ||
| go mod tidy | ||
| if ! git diff --quiet; then | ||
| echo "The Go module dependency setup is not clean. Please run 'go mod tidy' and commit any resulting changes." | ||
| exit 1 | ||
| fi |
+177
| package github | ||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
| "net/http" | ||
| "net/url" | ||
| "strconv" | ||
| "time" | ||
| githubclient "github.com/google/go-github/github" | ||
| githuboauth "golang.org/x/oauth2/github" | ||
| "github.com/skratchdot/open-golang/open" | ||
| "golang.org/x/oauth2" | ||
| ) | ||
| const ( | ||
| oauthClientID = "d5a2938d576279fbc995" | ||
| oauthScopes = "user:email,repo" | ||
| githubStageOneURI = "https://github.com/login/device/code" | ||
| githubStageThreeURI = "https://github.com/login/oauth/access_token" | ||
| githubGrantType = "urn:ietf:params:oauth:grant-type:device_code" | ||
| ) | ||
| type githubStageOneResponse struct { | ||
| deviceCode string | ||
| userCode string | ||
| verificationURI string | ||
| expiresAt time.Time | ||
| interval int | ||
| } | ||
| func NewClientFromToken(token *oauth2.Token) *githubclient.Client { | ||
| oauthConf := oauth2.Config{ | ||
| ClientID: oauthClientID, | ||
| Endpoint: githuboauth.Endpoint, | ||
| } | ||
| oauthClient := oauthConf.Client(oauth2.NoContext, token) | ||
| return githubclient.NewClient(oauthClient) | ||
| } | ||
| func Authenticate() (*oauth2.Token, error) { | ||
| stageOne, err := requestGithubStageOne() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| fmt.Println("User Code:", stageOne.userCode) | ||
| if err := open.Run(stageOne.verificationURI); err != nil { | ||
| return nil, err | ||
| } | ||
| token, err := requestGithubStageThree(stageOne) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return token, nil | ||
| } | ||
| func requestGithubStageOne() (*githubStageOneResponse, error) { | ||
| uri := fmt.Sprintf("%s?client_id=%s&scope=%s", githubStageOneURI, oauthClientID, oauthScopes) | ||
| resp, err := http.Post(uri, "application/json", nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer resp.Body.Close() | ||
| if resp.StatusCode != 200 { | ||
| return nil, fmt.Errorf("Github returned non-200 response (%d)", resp.StatusCode) | ||
| } | ||
| body, err := ioutil.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| params, err := parseQueryWithSingleValues(string(body)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| response := githubStageOneResponse{} | ||
| if deviceCode, ok := params["device_code"]; ok { | ||
| response.deviceCode = deviceCode | ||
| } | ||
| if userCode, ok := params["user_code"]; ok { | ||
| response.userCode = userCode | ||
| } | ||
| if verificationURI, ok := params["verification_uri"]; ok { | ||
| response.verificationURI = verificationURI | ||
| } | ||
| if expiresIn, ok := params["expires_in"]; ok { | ||
| expiresInInt, err := strconv.Atoi(expiresIn) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| response.expiresAt = time.Now().Add(time.Second * time.Duration(expiresInInt)) | ||
| } | ||
| if interval, ok := params["interval"]; ok { | ||
| intervalInt, err := strconv.Atoi(interval) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| response.interval = intervalInt | ||
| } | ||
| return &response, nil | ||
| } | ||
| func requestGithubStageThree(stageOne *githubStageOneResponse) (*oauth2.Token, error) { | ||
| uri := fmt.Sprintf("%s?client_id=%s&device_code=%s&grant_type=%s", githubStageThreeURI, oauthClientID, stageOne.deviceCode, githubGrantType) | ||
| for { | ||
| fmt.Printf(".") | ||
| resp, err := http.Post(uri, "application/json", nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer resp.Body.Close() | ||
| if resp.StatusCode != 200 { | ||
| return nil, fmt.Errorf("Github returned non-200 response (%d)", resp.StatusCode) | ||
| } | ||
| body, err := ioutil.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| params, err := parseQueryWithSingleValues(string(body)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if errType, ok := params["error"]; ok { | ||
| if errType != "authorization_pending" { | ||
| return nil, fmt.Errorf("Error response from GitHub: %s (%s)", params["error_description"], errType) | ||
| } | ||
| } | ||
| if accessToken, ok := params["access_token"]; ok { | ||
| fmt.Printf("\n") | ||
| token := oauth2.Token{AccessToken: accessToken} | ||
| return &token, nil | ||
| } | ||
| time.Sleep(time.Second * time.Duration(stageOne.interval)) | ||
| } | ||
| } | ||
| // Takes a query string like: | ||
| // | ||
| // foo=bar&baz=1 | ||
| // | ||
| // .. and returns a map[string]string | ||
| // | ||
| // {"foo" => "bar", "baz" => "1"} | ||
| // | ||
| // Query strings can have duplicate keys and the values are merged into an array, | ||
| // however this assumes there's only a single value and ignores any extras. | ||
| func parseQueryWithSingleValues(data string) (map[string]string, error) { | ||
| initialParams, err := url.ParseQuery(data) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| result := make(map[string]string) | ||
| for k, v := range initialParams { | ||
| if len(v) > 0 { | ||
| result[k] = v[0] | ||
| } | ||
| } | ||
| return result, nil | ||
| } |
| version: '2.1' | ||
| services: | ||
| app: | ||
| image: golang:1.12 | ||
| agent: | ||
| image: golang:1.16 | ||
| volumes: | ||
@@ -7,0 +7,0 @@ - go-module-cache:/go/pkg/mod |
@@ -32,4 +32,4 @@ env: | ||
| command: | | ||
| keys=$$(buildkite-agent meta-data keys --delimiter=".") | ||
| [[ \${keys} == "family.size" ]] | ||
| keys=$$(buildkite-agent meta-data keys | tr "\n" ",") | ||
| [[ \${keys} == "family,size," ]] | ||
@@ -36,0 +36,0 @@ - wait |
| steps: | ||
| - name: "Lint" | ||
| command: ".buildkite/steps/lint.sh" | ||
| plugins: | ||
| docker#v3.5.0: | ||
| image: "golang:1.16" | ||
| - name: "Test" | ||
@@ -24,5 +30,16 @@ command: "go test -v -failfast ./..." | ||
| targets: | ||
| - version: "1.11" | ||
| - version: "1.16" | ||
| goos: darwin | ||
| goarch: amd64 | ||
| - version: "1.16" | ||
| goos: darwin | ||
| goarch: arm64 | ||
| - version: "1.16" | ||
| goos: linux | ||
| goarch: amd64 | ||
| gomodule: "on" | ||
| - version: "1.16" | ||
| goos: linux | ||
| goarch: arm64 | ||
| - version: "1.16" | ||
| goos: windows | ||
| goarch: amd64 |
| #!/bin/bash | ||
| set -euo pipefail | ||
| bash -c "`curl -sL https://raw.githubusercontent.com/buildkite/agent/master/install.sh`" | ||
| bash -c "$(curl -sL https://raw.githubusercontent.com/buildkite/agent/master/install.sh)" | ||
| export PATH="/root/.buildkite-agent/bin:$PATH" | ||
| go run ./cmd/bk run .buildkite/local.yml |
+20
-0
@@ -7,2 +7,22 @@ # Changelog | ||
| ## [v1.2.0](https://github.com/buildkite/cli/compare/v1.1.0...v1.2.0) (2021-03-11) | ||
| ### Changed | ||
| * `bk build create` accepts `--meta-data` when creating a remote build [#108](https://github.com/buildkite/cli/pull/108) ([keithpitt](https://github.com/keithpitt)) (👋 @apanzerj) | ||
| * Windows `HOMEPATH` `APPDATA` etc env vars passed to `bk local run` [#92](https://github.com/buildkite/cli/pull/92) ([Helcaraxan](https://github.com/Helcaraxan)) | ||
| * GitHub auth uses new-in-2020 "device flow" [#100](https://github.com/buildkite/cli/pull/100) ([yob](https://github.com/yob)) | ||
| ### Added | ||
| * Binaries for `darwin/arm64` (Apple Silicon) and `linux/arm64` [#107](https://github.com/buildkite/cli/pull/107) ([sj26](https://github.com/sj26)) | ||
| ### Maintenance | ||
| * Go 1.16 [#88](https://github.com/buildkite/cli/pull/88) [#109](https://github.com/buildkite/cli/pull/109) ([pda](https://github.com/pda)) | ||
| * CI pipeline maintenance [#89](https://github.com/buildkite/cli/pull/89) [#90](https://github.com/buildkite/cli/pull/90) ([pda](https://github.com/pda)) [#86](https://github.com/buildkite/cli/pull/86) ([Helcaraxan](https://github.com/Helcaraxan)) | ||
| * Homebrew tap formula fixes [#85](https://github.com/buildkite/cli/pull/85) ([JuanitoFatas](https://github.com/JuanitoFatas)) | ||
| * macOS 11 Big Sur compiler error fix (keyring & go-keychain libs) [#101](https://github.com/buildkite/cli/pull/101) ([pda](https://github.com/pda)) | ||
| * README usage example fix [#93](https://github.com/buildkite/cli/pull/93) ([rohansingh](https://github.com/rohansingh)) | ||
| ## [v1.1.0](https://github.com/buildkite/cli/tree/v1.1.0) (2020-05-08) | ||
@@ -9,0 +29,0 @@ [Full Changelog](https://github.com/buildkite/cli/compare/v1.0.0...v1.1.0) |
+20
-8
@@ -21,6 +21,7 @@ package cli | ||
| Branch string | ||
| Commit string | ||
| Message string | ||
| Env []string | ||
| Branch string | ||
| Commit string | ||
| Message string | ||
| Env []string | ||
| Metadata map[string]string | ||
| } | ||
@@ -30,6 +31,7 @@ | ||
| params := buildkiteBuildParams{ | ||
| Branch: ctx.Branch, | ||
| Commit: ctx.Commit, | ||
| Message: ctx.Message, | ||
| Env: ctx.Env, | ||
| Branch: ctx.Branch, | ||
| Commit: ctx.Commit, | ||
| Message: ctx.Message, | ||
| Env: ctx.Env, | ||
| Metadata: ctx.Metadata, | ||
| } | ||
@@ -172,5 +174,14 @@ | ||
| Env []string | ||
| Metadata map[string]string | ||
| } | ||
| func createBuildkiteBuild(client *graphql.Client, params buildkiteBuildParams) (buildkiteBuildDetails, error) { | ||
| var metaData []interface{} | ||
| for key, value := range params.Metadata { | ||
| metaData = append(metaData, map[string]interface{}{ | ||
| "key": key, | ||
| "value": value, | ||
| }) | ||
| } | ||
| resp, err := client.Do(` | ||
@@ -192,2 +203,3 @@ mutation($input: BuildCreateInput!) { | ||
| "env": params.Env, | ||
| "metaData": metaData, | ||
| }}) | ||
@@ -194,0 +206,0 @@ if err != nil { |
+2
-4
@@ -46,9 +46,7 @@ package cli | ||
| ctx.WaitForKeyPress(color.WhiteString("When you press enter, your default browser will open and authenticate to github.com")) | ||
| ctx.Printf(color.WhiteString("In a moment, we'll print a unique code and open a github.com URL in your default browser. To authenticate bk, enter the unique code into the browser.\n\n")) | ||
| s := ctx.Spinner() | ||
| s.Start() | ||
| ctx.WaitForKeyPress(color.WhiteString("Press enter to continue\n\n")) | ||
| token, err := github.Authenticate() | ||
| s.Stop() | ||
@@ -55,0 +53,0 @@ if err != nil { |
+7
-1
@@ -199,3 +199,5 @@ package main | ||
| buildCreateCtx := cli.BuildCreateCommandContext{} | ||
| buildCreateCtx := cli.BuildCreateCommandContext{ | ||
| Metadata: make(map[string]string), | ||
| } | ||
| buildCreateCmd := buildCmd. | ||
@@ -240,2 +242,6 @@ Command("create", "Create a new build in a pipeline"). | ||
| buildCreateCmd. | ||
| Flag("meta-data", "Meta-data to pass to the build"). | ||
| StringMapVar(&buildCreateCtx.Metadata) | ||
| // -------------------------- | ||
@@ -242,0 +248,0 @@ // browse command |
+5
-6
| module github.com/buildkite/cli | ||
| go 1.16 | ||
| require ( | ||
| github.com/99designs/keyring v1.1.3 | ||
| github.com/99designs/keyring v1.1.6 | ||
| github.com/ahmetb/go-cursor v0.0.0-20131010032410-8136607ea412 | ||
| github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect | ||
| github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect | ||
| github.com/aulanov/go.dbus v0.0.0-20150729231527-25c3068a42a0 // indirect | ||
| github.com/bmatcuk/doublestar v1.1.1 | ||
@@ -14,3 +15,2 @@ github.com/briandowns/spinner v0.0.0-20170614154858-48dbb65d7bd5 | ||
| github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect | ||
| github.com/davecgh/go-spew v1.1.1 | ||
| github.com/fatih/color v1.7.0 | ||
@@ -29,5 +29,4 @@ github.com/go-test/deep v1.0.1 | ||
| github.com/mattn/go-isatty v0.0.3 // indirect | ||
| github.com/mattn/go-zglob v0.0.1 | ||
| github.com/mitchellh/go-homedir v1.1.0 | ||
| github.com/mattn/go-zglob v0.0.1 | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/sahilm/fuzzy v0.0.5 | ||
@@ -44,2 +43,2 @@ github.com/satori/go.uuid v1.2.0 | ||
| go 1.13 | ||
| replace github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 |
+10
-33
@@ -1,5 +0,5 @@ | ||
| github.com/99designs/keyring v0.0.0-20190110203331-82da6802f65f h1:WXiWWJrYCaOaYimBAXlRdRJ7qOisrYyMLYnCvvhHVms= | ||
| github.com/99designs/keyring v0.0.0-20190110203331-82da6802f65f/go.mod h1:aKt8W/yd91/xHY6ixZAJZ2vYbhr3pP8DcrvuGSGNPJk= | ||
| github.com/99designs/keyring v1.1.3 h1:mEV3iyZWjkxQ7R8ia8GcG97vCX5zQQ7n4o8R2BylwQY= | ||
| github.com/99designs/keyring v1.1.3/go.mod h1:657DQuMrBZRtuL/voxVyiyb6zpMehlm5vLB9Qwrv904= | ||
| github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= | ||
| github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= | ||
| github.com/99designs/keyring v1.1.6 h1:kVDC2uCgVwecxCk+9zoCt2uEL6dt+dfVzMvGgnVcIuM= | ||
| github.com/99designs/keyring v1.1.6/go.mod h1:16e0ds7LGQQcT59QqkTg72Hh5ShM51Byv5PEmW6uoRU= | ||
| github.com/ahmetb/go-cursor v0.0.0-20131010032410-8136607ea412 h1:mjEdk5IWaOUyDfmIScVahVtW56YQ1gBv8RMyHl69Z30= | ||
@@ -11,4 +11,2 @@ github.com/ahmetb/go-cursor v0.0.0-20131010032410-8136607ea412/go.mod h1:6/fH+MoHXlGOc3iy8TSNB4eM1oaBDMs1oxPVN40M3h0= | ||
| github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= | ||
| github.com/aulanov/go.dbus v0.0.0-20150729231527-25c3068a42a0 h1:EEDvbomAQ+MFWqJ9FM6RXyJTkc4lckyWsbc5CGQkG1Y= | ||
| github.com/aulanov/go.dbus v0.0.0-20150729231527-25c3068a42a0/go.mod h1:VHvUx+4lTCaJ8zUnEXF4cWEc9c8lnDt4PGLwlZ+3yaM= | ||
| github.com/bmatcuk/doublestar v1.1.1 h1:YroD6BJCZBYx06yYFEWvUuKVWQn3vLLQAVmDmvTSaiQ= | ||
@@ -24,4 +22,2 @@ github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= | ||
| github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= | ||
| github.com/danieljoos/wincred v1.0.1 h1:fcRTaj17zzROVqni2FiToKUVg3MmJ4NtMSGCySPIr/g= | ||
| github.com/danieljoos/wincred v1.0.1/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U= | ||
| github.com/danieljoos/wincred v1.0.2 h1:zf4bhty2iLuwgjgpraD2E9UbvO+fe54XXGJbOwe23fU= | ||
@@ -32,6 +28,4 @@ github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U= | ||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/dvsekhvalnov/jose2go v0.0.0-20170216131308-f21a8cedbbae h1:UTOyRlLeWJrZx+ynml6q6qzZ1uDkJe/0Z5CMZRbEIJg= | ||
| github.com/dvsekhvalnov/jose2go v0.0.0-20170216131308-f21a8cedbbae/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= | ||
| github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a h1:mq+R6XEM6lJX5VlLyZIrUSP8tSuJp82xTK89hvBwJbU= | ||
| github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= | ||
| github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b h1:HBah4D48ypg3J7Np4N+HY/ZR76fx3HEUGxDU6Uk39oQ= | ||
| github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= | ||
| github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= | ||
@@ -54,11 +48,4 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= | ||
| github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= | ||
| github.com/keybase/go-keychain v0.0.0-20180801170200-15d3657f24fc h1:hsMxTKUbDWam6afrf6TFFBUCCGejgYQzIpwSe14WI4c= | ||
| github.com/keybase/go-keychain v0.0.0-20180801170200-15d3657f24fc/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= | ||
| github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM= | ||
| github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= | ||
| github.com/keybase/go-keychain v0.0.0-20191022214133-1c06e666bc46 h1:Sf/pnA7dyCXbGM4scY7MvmkRyHml+N35u7f9kx6+Wf0= | ||
| github.com/keybase/go-keychain v0.0.0-20191022214133-1c06e666bc46/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= | ||
| github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||
| github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
| github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= | ||
| github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
@@ -79,6 +66,6 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | ||
| github.com/mattn/go-zglob v0.0.1/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo= | ||
| github.com/mitchellh/go-homedir v0.0.0-20180523094522-3864e76763d9 h1:Y94YB7jrsihrbGSqRNMwRWJ2/dCxr0hdC2oPRohkx0A= | ||
| github.com/mitchellh/go-homedir v0.0.0-20180523094522-3864e76763d9/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= | ||
| github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= | ||
| github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= | ||
| github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= | ||
| github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= | ||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
@@ -93,17 +80,10 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= | ||
| github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= | ||
| github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= | ||
| github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | ||
| github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
| github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||
| github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
| golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613 h1:MQ/ZZiDsUapFFiMS+vzwXkCTeEKaum+Do5rINYJDmxc= | ||
| golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= | ||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
| golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= | ||
| golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||
| golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIoF2s4qxv0xSSS0BVZUE/ss= | ||
| golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||
| golang.org/x/net v0.0.0-20180530034148-89e543239a64 h1:otRUcJnCzmletog6NvNtimZZStU31VhmAuuno53i0Nk= | ||
| golang.org/x/net v0.0.0-20180530034148-89e543239a64/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||
| golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= | ||
@@ -115,7 +95,4 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
| golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
| golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43 h1:PvnWIWTbA7gsEBkKjt0HV9hckYfcqYv8s/ju7ArZ0do= | ||
| golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI= | ||
| golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
@@ -122,0 +99,0 @@ golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c h1:S/FtSvpNLtFBgjTqcKsRpsa6aVsI6iztaz1bQd9BJwE= |
+4
-0
@@ -419,2 +419,6 @@ package local | ||
| cmd.Env = append(cmd.Env, | ||
| "APPDATA="+os.Getenv("APPDATA"), | ||
| "LOCALAPPDATA="+os.Getenv("LOCALAPPDATA"), | ||
| "HOMEPATH="+os.Getenv("HOMEPATH"), | ||
| "USERPROFILE="+os.Getenv("USERPROFILE"), | ||
| "PATH="+os.Getenv("PATH"), | ||
@@ -421,0 +425,0 @@ "SystemRoot="+os.Getenv("SystemRoot"), |
+9
-1
@@ -7,3 +7,3 @@ SRC := $(shell find . -name '*.go') | ||
| .PHONY: build | ||
| build: build/bk-windows-amd64-$(VERSION).exe build/bk-linux-amd64-$(VERSION) build/bk-darwin-amd64-$(VERSION) | ||
| build: build/bk-windows-amd64-$(VERSION).exe build/bk-linux-amd64-$(VERSION) build/bk-linux-arm64-$(VERSION) build/bk-darwin-amd64-$(VERSION) build/bk-darwin-arm64-$(VERSION) | ||
@@ -18,2 +18,6 @@ build/bk-windows-amd64-$(VERSION).exe: $(SRC) | ||
| build/bk-linux-arm64-$(VERSION): $(SRC) | ||
| mkdir -p build | ||
| GOOS=linux GOARCH=arm64 go build -o build/$(BINARY)-linux-arm64-$(VERSION) -ldflags="$(LD_FLAGS)" ./cmd/bk | ||
| build/bk-darwin-amd64-$(VERSION): $(SRC) | ||
@@ -23,4 +27,8 @@ mkdir -p build | ||
| build/bk-darwin-arm64-$(VERSION): $(SRC) | ||
| mkdir -p build | ||
| GOOS=darwin GOARCH=arm64 go build -o build/$(BINARY)-darwin-arm64-$(VERSION) -ldflags="$(LD_FLAGS)" ./cmd/bk | ||
| .PHONY: clean | ||
| clean: | ||
| -rm -rf build/ |
+1
-1
@@ -32,3 +32,3 @@ # bk - The Buildkite CLI | ||
| # List the pipelines that you have access to | ||
| bk pipelines list | ||
| bk pipeline list | ||
@@ -35,0 +35,0 @@ # Triggers a build for the current directory's commit and branch |
+1
-1
@@ -5,3 +5,3 @@ package cli | ||
| // Version is the version of the CLI tool | ||
| Version = "1.1.0" | ||
| Version = "1.2.0" | ||
| ) | ||
@@ -8,0 +8,0 @@ |
| package github | ||
| import ( | ||
| "fmt" | ||
| "net" | ||
| "net/http" | ||
| githubclient "github.com/google/go-github/github" | ||
| githuboauth "golang.org/x/oauth2/github" | ||
| "github.com/skratchdot/open-golang/open" | ||
| "golang.org/x/oauth2" | ||
| ) | ||
| var ( | ||
| ServerBind = "127.0.0.1:7024" | ||
| ServerAddress = "http://127.0.0.1:7024" | ||
| ) | ||
| var ( | ||
| oauthConf = oauth2.Config{ | ||
| ClientID: "d5a2938d576279fbc995", | ||
| ClientSecret: "aadcab62248629c3d0018b9e54e4d3fc37fdd29e", | ||
| Scopes: []string{"user:email", "repo"}, | ||
| Endpoint: githuboauth.Endpoint, | ||
| } | ||
| ) | ||
| func NewClientFromToken(token *oauth2.Token) *githubclient.Client { | ||
| oauthClient := oauthConf.Client(oauth2.NoContext, token) | ||
| return githubclient.NewClient(oauthClient) | ||
| } | ||
| func Authenticate() (*oauth2.Token, error) { | ||
| ln, err := net.Listen("tcp", ServerBind) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| handler := githubAuthHandler{ | ||
| OAuthStateString: "da39a3ee5e6b4b0d3255bfef95601890afd80709", | ||
| TokenCh: make(chan *oauth2.Token), | ||
| } | ||
| go func() { | ||
| _ = http.Serve(ln, handler) | ||
| }() | ||
| if err := open.Run(ServerAddress); err != nil { | ||
| return nil, err | ||
| } | ||
| select { | ||
| case token := <-handler.TokenCh: | ||
| return token, ln.Close() | ||
| case err := <-handler.ErrCh: | ||
| return nil, err | ||
| } | ||
| } | ||
| type githubAuthHandler struct { | ||
| OAuthConf *oauth2.Config | ||
| OAuthStateString string | ||
| TokenCh chan *oauth2.Token | ||
| ErrCh chan error | ||
| } | ||
| func (handler githubAuthHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { | ||
| switch req.URL.Path { | ||
| case `/`: | ||
| http.Redirect(w, req, "/login", http.StatusMovedPermanently) | ||
| case `/login`: | ||
| url := oauthConf.AuthCodeURL(handler.OAuthStateString, oauth2.AccessTypeOnline) | ||
| http.Redirect(w, req, url, http.StatusTemporaryRedirect) | ||
| case `/github_oauth_cb`: | ||
| // check the oauth state string matches, prevent replay attacks | ||
| if state := req.FormValue("state"); state != handler.OAuthStateString { | ||
| err := fmt.Errorf("Invalid oauth state, expected %q, got %q", handler.OAuthStateString, state) | ||
| http.Error(w, err.Error(), http.StatusInternalServerError) | ||
| handler.ErrCh <- err | ||
| return | ||
| } | ||
| token, err := oauthConf.Exchange(oauth2.NoContext, req.FormValue("code")) | ||
| if err != nil { | ||
| http.Error(w, err.Error(), http.StatusInternalServerError) | ||
| handler.ErrCh <- err | ||
| return | ||
| } | ||
| handler.TokenCh <- token | ||
| fmt.Fprintf(w, "Successfully authenticated! You can close this tab and return to cli now") | ||
| default: | ||
| http.Error(w, "Page not found", http.StatusNotFound) | ||
| } | ||
| } |