Last active
February 28, 2018 17:56
-
-
Save ahume/e02945f95a5b421d830ea942a0bff9fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"net/http" | |
"os" | |
"github.com/concourse/go-concourse/concourse" | |
) | |
func main() { | |
bat := BasicAuthTransport{ | |
username: os.Getenv("CONCOURSE_USERNAME"), | |
password: os.Getenv("CONCOURSE_PASSWORD"), | |
} | |
client := concourse.NewClient(os.Getenv("CONCOURSE_URL"), &http.Client{Transport: bat}, false) | |
workers, err := client.ListWorkers() | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Println(workers) | |
} | |
type BasicAuthTransport struct { | |
username string | |
password string | |
} | |
func (bat BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { | |
req.Header.Set("Authorization", fmt.Sprintf("Basic %s", | |
base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", | |
bat.username, bat.password))))) | |
fmt.Println("Doing request", req) | |
return http.DefaultTransport.RoundTrip(req) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment