Exemple #1
0
func discovery() {
	var err error
	var opts []grpc.DialOption

	if insecureDiscovery {
		opts = append(opts, grpc.WithInsecure())
	} else {
		auth := credentials.NewClientTLSFromCert(nil, getServerName(discoveryServiceURL))
		opts = append(opts, grpc.WithTransportCredentials(auth))
	}
	discoveryConn, err = grpc.Dial(discoveryServiceURL, opts...)
	if err != nil {
		logrus.Fatalf("grpc.go: error while connection to discovery service %v", err)
	}
	discoveryClient = pb.NewDiscoveryClient(discoveryConn)
	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
	res, err := discoveryClient.Get(ctx, &pb.DiscoveryRequest{
		Environment: discoveryEnv,
		SdkVersion:  Version + "-otsimoctl",
		OsName:      runtime.GOOS,
	})
	if err != nil {
		logrus.Fatalf("grpc:go: failed to get discovery config err=%v", err)
	}
	discoveryServices = res
}
Exemple #2
0
func discoveryGet(clictx *cli.Context) error {
	var err error
	var opts []grpc.DialOption

	if insecureDiscovery {
		opts = append(opts, grpc.WithInsecure())
	} else {
		auth := credentials.NewClientTLSFromCert(nil, getServerName(discoveryServiceURL))
		opts = append(opts, grpc.WithTransportCredentials(auth))
	}
	logrus.Infof("discovery.go: connecting to discovery service at url %s", discoveryServiceURL)

	dcon, err := grpc.Dial(discoveryServiceURL, opts...)
	if err != nil {
		logrus.Fatalf("discovery.go: error while connection to discovery service %v", err)
	}
	dc := pb.NewDiscoveryClient(dcon)
	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)

	req := pb.DiscoveryRequest{}
	if filename := clictx.String("filename"); filename != "" {
		d, err := os.Open(filename)
		if err != nil {
			return err
		}
		defer d.Close()
		if err := jsonpb.Unmarshal(d, &req); err != nil {
			return err
		}
	} else {
		req.Environment = clictx.String("env")
		req.SdkVersion = clictx.String("sdk")
		req.OsName = clictx.String("os")
		req.CountryCode = clictx.String("country-code")
		req.AppBundleId = clictx.String("bundle-id")
		req.AppBundleVersion = clictx.String("bundle-version")
	}
	res, err := dc.Get(ctx, &req)
	if err != nil {
		return err
	}
	m := jsonpb.Marshaler{EnumsAsInts: false, EmitDefaults: true, Indent: "  "}
	s, err := m.MarshalToString(res)
	fmt.Println(s)
	return nil
}