Ejemplo n.º 1
0
// GetDiscovery gets the Discovery client for ttnctl
func GetDiscovery(ctx log.Interface) (*grpc.ClientConn, discovery.DiscoveryClient) {
	path := path.Join(GetDataDir(), "/ca.cert")
	cert, err := ioutil.ReadFile(path)
	if err == nil && !api.RootCAs.AppendCertsFromPEM(cert) {
		ctx.Warnf("Could not add root certificates from %s", path)
	}

	conn, err := api.Dial(viper.GetString("discovery-address"))
	if err != nil {
		ctx.WithError(err).Fatal("Could not connect to Discovery server")
	}
	return conn, discovery.NewDiscoveryClient(conn)
}
Ejemplo n.º 2
0
		if len(args) == 0 {
			cmd.UsageFunc()(cmd)
			return
		}

		path := filepath.Clean(viper.GetString("key-dir") + "/ca.cert")
		cert, err := ioutil.ReadFile(path)
		if err == nil && !api.RootCAs.AppendCertsFromPEM(cert) {
			ctx.Warnf("Could not add root certificates from %s", path)
		}

		conn, err := api.Dial(viper.GetString("discovery-address"))
		if err != nil {
			ctx.WithError(err).Fatal("Could not connect to Discovery server")
		}
		client := discovery.NewDiscoveryClient(conn)

		client.GetAll(context.Background(), &discovery.GetServiceRequest{})

		md := metadata.Pairs(
			"service-name", "broker",
			"id", viper.GetString("id"),
			"token", viper.GetString("auth-token"),
		)
		dscContext := metadata.NewContext(context.Background(), md)

		success := true
		for _, prefixString := range args {
			ctx := ctx.WithField("Prefix", prefixString)
			prefix, err := types.ParseDevAddrPrefix(prefixString)
			if err != nil {