Ejemplo n.º 1
0
func main() {

	uaa, err := uaago.NewClient(uaaEndpoint)
	if err != nil {
		fmt.Printf("Error from uaaClient %s\n", err)
		os.Exit(1)
	}

	refresher := tokenRefresher{uaaClient: uaa}

	consumer := consumer.New(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)
	consumer.RefreshTokenFrom(&refresher)
	consumer.SetDebugPrinter(ConsoleDebugPrinter{})

	fmt.Println("===== Streaming metrics")
	msgChan, errorChan := consumer.Firehose(appGuid, "")

	go func() {
		for err := range errorChan {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
		}
	}()

	for msg := range msgChan {
		fmt.Printf("%v \n", msg)
	}
}
func (uaa *UAATokenFetcher) FetchAuthToken() string {
	uaaClient, err := uaago.NewClient(uaa.UaaUrl)
	if err != nil {
		log.Fatalf("Error creating uaa client: %s", err.Error())
	}

	var authToken string
	authToken, err = uaaClient.GetAuthToken(uaa.Username, uaa.Password, uaa.InsecureSSLSkipVerify)
	if err != nil {
		log.Fatalf("Error getting oauth token: %s. Please check your username and password.", err.Error())
	}
	return authToken
}
Ejemplo n.º 3
0
func (uaa *UAATokenFetcher) FetchAuthToken() (string, error) {
	uaaClient, err := uaago.NewClient(uaa.UaaUrl)
	if err != nil {
		return "", err
	}

	var authToken string
	authToken, err = uaaClient.GetAuthToken(uaa.Username, uaa.Password, uaa.InsecureSSLSkipVerify)
	if err != nil {
		return "", err
	}
	return authToken, nil
}
Ejemplo n.º 4
0
func run(args []string) int {
	if len(args[1:]) != 3 {
		fmt.Fprintf(os.Stderr, "Usage %s [URL] [USERNAME] [PASS]", args[0])
		return 1
	}

	uaa, err := uaago.NewClient(args[1])
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create client: %s", err.Error())
		return 1
	}

	token, err := uaa.GetAuthToken(args[2], args[3], false)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Faild to get auth token: %s", err.Error())
		return 1
	}

	fmt.Fprintf(os.Stdout, "TOKEN: %s\n", token)
	return 0
}
Ejemplo n.º 5
0
func main() {

	user := flag.String("user", "example-nozzle", "user who has access to the firehose")
	password := flag.String("pass", "example-nozzle", "password for the user")
	trafficControllerURL := flag.String("tcurl", "wss://doppler.bosh-lite.com:443", "loggregator traffic controller URL and port")
	uaaURL := flag.String("uaaurl", "https://uaa.bosh-lite.com", "UAA URL")

	flag.Parse()

	uaaClient, err := uaago.NewClient(*uaaURL)
	if err != nil {
		log.Fatalf("Error creating uaa client: %s", err.Error())
	}

	var authToken string
	authToken, err = uaaClient.GetAuthToken(*user, *password, true)
	if err != nil {
		log.Fatalf("Error getting oauth token: %s. Please check your username and password.", err.Error())
	}

	connection := noaa.NewConsumer(*trafficControllerURL, &tls.Config{InsecureSkipVerify: true}, nil)

	fmt.Println("===== Streaming Firehose (will only succeed if you have admin credentials)")

	msgChan := make(chan *events.Envelope)
	go func() {
		defer close(msgChan)
		errorChan := make(chan error)
		const firehoseSubscriptionId = "firehose-a"
		go connection.Firehose(firehoseSubscriptionId, authToken, msgChan, errorChan)

		for err := range errorChan {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
		}
	}()

	for msg := range msgChan {
		fmt.Printf("%v \n", msg)
	}
}
Ejemplo n.º 6
0
							"scope":"cloud_controller.write doppler.firehose",
							"jti":"28edda5c-4e37-4a63-9ba3-b32f48530a51"
						}
						`)
							writer.Write(jsonData)
							return
						}
					}
					writer.WriteHeader(http.StatusUnauthorized)
				}))
			})
			AfterEach(func() {
				testServer.Close()
			})
			It("Should get a valid oauth token from the given UAA", func() {
				client, err := uaago.NewClient(testServer.URL)
				Expect(err).ToNot(HaveOccurred())

				token, err := client.GetAuthToken("myusername", "mypassword", false)
				Expect(err).ToNot(HaveOccurred())
				Expect(token).To(Equal("bearer good-token"))
			})
		})

		Context("with https", func() {
			var testServer *httptest.Server
			BeforeEach(func() {
				testServer = httptest.NewTLSServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
					if validRequest(request) {
						authValue := request.Header.Get("Authorization")
						authValueBytes := "Basic " + base64.StdEncoding.EncodeToString([]byte("myusername:mypassword"))