func TestGetTaskError(t *testing.T) { _, err := tc.GetTask("magicfoobar") if !(err != nil) { t.Errorf("Error expected in task fetching") } }
// XXX: This is a terrible test since it will eventually fail but the docker // worker tests will ensure this will work... func TestGetTask(t *testing.T) { task, err := tc.GetTask("6dS50KOBRjCZX2L-ql3atQ") if err != nil { t.Fatalf("Error fetching task: %s", err) } if task.Scopes[0] != "docker-worker:cache:tc-vcs" { t.Errorf("Could not fetch task...") } }
func main() { // Parse the docopt string and exit on any error or help message. arguments, err := docopt.Parse(usage, nil, true, version, false, true) taskId := arguments["<taskId>"].(string) port, err := strconv.Atoi(arguments["--port"].(string)) if err != nil { log.Fatalf("Failed to convert port to integer") } // Parse out additional scopes to add... var additionalScopes []string if arguments["<scope>"] != nil { additionalScopes = arguments["<scope>"].([]string) } else { additionalScopes = make([]string, 0) } // Client is is required but has a default. clientId := arguments["--client-id"] if clientId == nil || clientId == "" { clientId = os.Getenv("TASKCLUSTER_CLIENT_ID") } // Access token is also required but has a default. accessToken := arguments["--access-token"] if accessToken == nil || accessToken == "" { accessToken = os.Getenv("TASKCLUSTER_ACCESS_TOKEN") } log.Printf("%v - %v", clientId, accessToken) // Ensure we have credentials our auth proxy is pretty much useless without // it. if accessToken == "" || clientId == "" { log.Fatalf( "Credentials must be passed via environment variables or flags...", ) } // Fetch the task to get the scopes we should be using... task, err := tc.GetTask(taskId) if err != nil { log.Fatalf("Could not fetch taskcluster task '%s' : %s", taskId, err) } scopes := append(additionalScopes, task.Scopes...) log.Println("Proxy with scopes: ", scopes) routes := Routes{ Scopes: scopes, ClientId: clientId.(string), AccessToken: accessToken.(string), } startError := http.ListenAndServe(fmt.Sprintf(":%d", port), routes) if startError != nil { log.Fatal(startError) } }