Exemplo n.º 1
0
// main the control function
func main() {

	cfg := resolveConfig(nil)

	var opts []grpc.ServerOption
	creds, err := credentials.NewServerTLSFromFile(path.Join(cfg.path, "server.crt"), path.Join(cfg.path, "server.key"))
	FatalIf(err, "Couldn't load cert from file")
	opts = []grpc.ServerOption{grpc.Creds(creds)}
	s := grpc.NewServer(opts...)
	var cOpts []grpc.DialOption
	tlsConfig := &ftls.Config{
		MutualTLS:          !cfg.skipMutualTLS,
		InsecureSkipVerify: cfg.insecureSkipVerify,
		CertFile:           path.Join(cfg.path, "client.crt"),
		KeyFile:            path.Join(cfg.path, "client.key"),
		CAFile:             path.Join(cfg.path, "ca.pem"),
	}
	rOpts, err := ftls.NewGRPCClientDialOpt(&ftls.Config{
		MutualTLS:          false,
		InsecureSkipVerify: cfg.insecureSkipVerify,
		CAFile:             path.Join(cfg.path, "ca.pem"),
	})
	if err != nil {
		grpclog.Fatalln("Cannot setup tls config for synd client:", err)
	}

	clientID, _ := os.Hostname()
	if clientID != "" {
		clientID += "/oohhc-filesysd"
	}

	gstore := api.NewReplGroupStore(&api.ReplGroupStoreConfig{
		AddressIndex:       2,
		StoreFTLSConfig:    tlsConfig,
		GRPCOpts:           cOpts,
		RingServer:         cfg.oortGroupSyndicate,
		RingCachePath:      path.Join(cfg.path, "ring/groupstore.ring"),
		RingServerGRPCOpts: []grpc.DialOption{rOpts},
		RingClientID:       clientID,
	})
	if gerr := gstore.Startup(context.Background()); gerr != nil {
		grpclog.Fatalln("Cannot start valuestore connector:", gerr)
	}

	fs, err := NewFileSystemWS(gstore)
	if err != nil {
		grpclog.Fatalln(err)
	}
	l, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.port))
	FatalIf(err, "Failed to bind to port")
	fb.RegisterFileSystemAPIServer(s, NewFileSystemAPIServer(fs))
	grpclog.Printf("Starting up on %d...\n", cfg.port)
	s.Serve(l)
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: polvi/rolo
func main() {
	flag.Parse()
	lis, err := net.Listen("tcp", *serverAddr)
	if err != nil {
		grpclog.Fatalf("failed to listen: %v", err)
	}
	var opts []grpc.ServerOption
	if *tls {
		creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
		if err != nil {
			grpclog.Fatalf("Failed to generate credentials %v", err)
		}
		opts = append(opts, grpc.Creds(creds))
	}
	grpcServer := grpc.NewServer(opts...)
	oidcClient, err := util.GetOIDCClient(*clientID, *clientSecret, *discovery, *redirectURL)
	if err != nil {
		grpclog.Fatalf("unable to get oidc client: %s", err)
	}
	s, err := server.NewRoloServer(oidcClient, *policyFile)
	if err != nil {
		grpclog.Fatalln("unable to create ca from parent:", err)
	}
	pb.RegisterRoloServer(grpcServer, s)
	grpclog.Println("serving at", *serverAddr)
	grpcServer.Serve(lis)
}
Exemplo n.º 3
0
func main() {
	v1, v2 := 12, 23

	// Dial the server insecurely
	conn, err := grpc.Dial("127.0.0.1:1234", grpc.WithInsecure())
	if err != nil {
		grpclog.Fatalln("fail to dial:", err)
	}
	defer conn.Close()

	// Get a client using the connection
	client := pb.NewTestClient(conn)
	resp, err := client.Add(context.Background(), &pb.NumericRequest{V1: int32(v1), V2: int32(v2)})
	if err != nil {
		grpclog.Fatalln("failed server call:", err)
	}
	grpclog.Println("resp:", resp)
}
Exemplo n.º 4
0
func main() {
	values := []int32{1, 1, 2, 3, 5, 8}
	testType := pb.TestType_TYPE_1

	// Dial the server
	conn, err := grpc.Dial("127.0.0.1:1234", grpc.WithInsecure())
	if err != nil {
		grpclog.Fatalln("fail to dial:", err)
	}
	defer conn.Close()

	// Get a client using the connection
	client := pb.NewBetterTestClient(conn)
	resp, err := client.Add(context.Background(), &pb.BetterNumericRequest{Type: testType, Values: values})
	if err != nil {
		grpclog.Fatalln("failed server call:", err)
	}
	grpclog.Println("resp:", resp)
}
Exemplo n.º 5
0
func main() {
	v1, v2 := int32(12), int32(23)

	// Get TLS creds
	creds, err := credentials.NewClientTLSFromFile("server.crt", "grpc.bouldergo.com")
	if err != nil {
		grpclog.Fatalf("Failed to generate credentials %v", err)
	}

	// Dial the server securely
	conn, err := grpc.Dial("127.0.0.1:1234", grpc.WithTransportCredentials(creds))
	if err != nil {
		grpclog.Fatalln("fail to dial:", err)
	}
	defer conn.Close()

	// Get a client using the connection
	client := pb.NewTestClient(conn)
	resp, err := client.Add(context.Background(), &pb.NumericRequest{V1: v1, V2: v2})
	if err != nil {
		grpclog.Fatalln("failed server call:", err)
	}
	grpclog.Println("resp:", resp)
}
Exemplo n.º 6
0
Arquivo: main.go Projeto: polvi/cad
func main() {
	flag.Parse()
	lis, err := net.Listen("tcp", *serverAddr)
	if err != nil {
		grpclog.Fatalf("failed to listen: %v", err)
	}
	var opts []grpc.ServerOption
	if *tls {
		creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
		if err != nil {
			grpclog.Fatalf("Failed to generate credentials %v", err)
		}
		opts = append(opts, grpc.Creds(creds))
	}
	grpcServer := grpc.NewServer(opts...)
	c := &server.CaServer{}
	if !*selfSigned && *parentAddr == "" && (*caCertFile == "" || *caKeyFile == "") {
		grpclog.Fatalln("Must specify -self-signed or -parent-addr or -ca-key/cert")
	}
	def, err := time.ParseDuration(*defaultDuration)
	if err != nil {
		grpclog.Fatalln(err)
	}
	max, err := time.ParseDuration(*maxDuration)
	if err != nil {
		grpclog.Fatalln(err)
	}
	min, err := time.ParseDuration(*minDuration)
	if err != nil {
		grpclog.Fatalln(err)
	}

	if *selfSigned {
		dur, err := time.ParseDuration(*selfSignedDuration)
		if err != nil {
			grpclog.Fatalln(err)
		}
		c, err = server.NewSelfSignedCaServer(dur, def, min, max)
		if err != nil {
			grpclog.Fatalf("unable to generate self signed ca: %s", err)
		}
		grpclog.Println("generated self-signed ca")
	}
	if *parentAddr != "" {
		f, err := os.Open(*idRefreshTokenFile)
		if err != nil {
			grpclog.Fatalln("unable to open refresh token:", err)
		}
		refToken, err := ioutil.ReadAll(f)
		if err != nil {
			grpclog.Fatalln("unable to read refresh token:", err)
		}
		c, err = server.NewCaServerFromParent(*parentAddr, string(refToken))
		if err != nil {
			grpclog.Fatalln("unable to create ca from parent:", err)
		}
		grpclog.Println("setup ca from parent", *parentAddr)
	}
	if *caCertFile != "" && *caKeyFile != "" {
		c, err = server.NewCaServerFromLocalFiles(*caCertFile, *caKeyFile, def, max, min)
		if err != nil {
			grpclog.Fatalln("unable to create ca from local files:", err)
		}
		grpclog.Println("setup ca from localfiles", *caCertFile, *caKeyFile)
	}

	pb.RegisterCaServer(grpcServer, c)
	grpclog.Println("serving at", *serverAddr)
	grpcServer.Serve(lis)
}
Exemplo n.º 7
0
func (g *defaultLogger) Fatalln(args ...interface{}) {
	grpclog.Fatalln(args...)
}
Exemplo n.º 8
0
func main() {
	flag.Parse()
	if *printVersionInfo {
		fmt.Println("formicd version:", formicdVersion)
		fmt.Println("build date:", buildDate)
		fmt.Println("go version:", goVersion)
		return
	}

	cfg := resolveConfig(nil)

	setupMetrics(cfg.metricsAddr, cfg.metricsCollectors)

	var opts []grpc.ServerOption
	creds, err := credentials.NewServerTLSFromFile(path.Join(cfg.path, "server.crt"), path.Join(cfg.path, "server.key"))
	FatalIf(err, "Couldn't load cert from file")
	opts = []grpc.ServerOption{grpc.Creds(creds)}
	s := grpc.NewServer(opts...)

	var vcOpts []grpc.DialOption
	vtlsConfig := &ftls.Config{
		MutualTLS:          !cfg.skipMutualTLS,
		InsecureSkipVerify: cfg.insecureSkipVerify,
		CertFile:           path.Join(cfg.path, "client.crt"),
		KeyFile:            path.Join(cfg.path, "client.key"),
		CAFile:             path.Join(cfg.path, "ca.pem"),
	}
	vrOpts, err := ftls.NewGRPCClientDialOpt(&ftls.Config{
		MutualTLS:          false,
		InsecureSkipVerify: cfg.insecureSkipVerify,
		CAFile:             path.Join(cfg.path, "ca.pem"),
	})
	if err != nil {
		grpclog.Fatalln("Cannot setup value store tls config for synd client:", err)
	}

	var gcOpts []grpc.DialOption
	gtlsConfig := &ftls.Config{
		MutualTLS:          !cfg.skipMutualTLS,
		InsecureSkipVerify: cfg.insecureSkipVerify,
		CertFile:           path.Join(cfg.path, "client.crt"),
		KeyFile:            path.Join(cfg.path, "client.key"),
		CAFile:             path.Join(cfg.path, "ca.pem"),
	}
	grOpts, err := ftls.NewGRPCClientDialOpt(&ftls.Config{
		MutualTLS:          false,
		InsecureSkipVerify: cfg.insecureSkipVerify,
		CAFile:             path.Join(cfg.path, "ca.pem"),
	})
	if err != nil {
		grpclog.Fatalln("Cannot setup group store tls config for synd client:", err)
	}

	clientID, _ := os.Hostname()
	if clientID != "" {
		clientID += "/formicd"
	}

	vstore := api.NewReplValueStore(&api.ReplValueStoreConfig{
		AddressIndex:               2,
		StoreFTLSConfig:            vtlsConfig,
		GRPCOpts:                   vcOpts,
		RingServer:                 cfg.oortValueSyndicate,
		RingCachePath:              path.Join(cfg.path, "ring/valuestore.ring"),
		RingServerGRPCOpts:         []grpc.DialOption{vrOpts},
		RingClientID:               clientID,
		ConcurrentRequestsPerStore: cfg.concurrentRequestsPerStore,
	})
	if verr := vstore.Startup(context.Background()); verr != nil {
		grpclog.Fatalln("Cannot start valuestore connector:", verr)
	}

	gstore := api.NewReplGroupStore(&api.ReplGroupStoreConfig{
		AddressIndex:               2,
		StoreFTLSConfig:            gtlsConfig,
		GRPCOpts:                   gcOpts,
		RingServer:                 cfg.oortGroupSyndicate,
		RingCachePath:              path.Join(cfg.path, "ring/groupstore.ring"),
		RingServerGRPCOpts:         []grpc.DialOption{grOpts},
		RingClientID:               clientID,
		ConcurrentRequestsPerStore: cfg.concurrentRequestsPerStore,
	})
	if gerr := gstore.Startup(context.Background()); gerr != nil {
		grpclog.Fatalln("Cannot start valuestore connector:", gerr)
	}

	fs, err := NewOortFS(vstore, gstore)
	if err != nil {
		grpclog.Fatalln(err)
	}
	l, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.port))
	FatalIf(err, "Failed to bind to port")
	pb.RegisterApiServer(s, NewApiServer(fs, cfg.nodeId))
	grpclog.Printf("Starting up on %d...\n", cfg.port)
	s.Serve(l)
}