Skip to content

Instantly share code, notes, and snippets.

@ahume
Last active February 28, 2018 17:56
Show Gist options
  • Save ahume/e02945f95a5b421d830ea942a0bff9fb to your computer and use it in GitHub Desktop.
Save ahume/e02945f95a5b421d830ea942a0bff9fb to your computer and use it in GitHub Desktop.
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