blob: e9001d8b57032a506a0fb2448ae3f6652181746a [file] [log] [blame]
Robin Thellend83cd6122015-03-30 10:09:13 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Todd Wang7a6a4c22015-05-12 23:57:16 -07005// The following enables go generate to generate the doc.go file.
Nicolas Lacasse1b1b9382015-09-24 10:00:35 -07006//go:generate go run $JIRI_ROOT/release/go/src/v.io/x/lib/cmdline/testdata/gendoc.go . -help
Todd Wang7a6a4c22015-05-12 23:57:16 -07007
Robin Thellend83cd6122015-03-30 10:09:13 -07008package main
9
10import (
Robin Thellend83cd6122015-03-30 10:09:13 -070011 "fmt"
Robin Thellend83cd6122015-03-30 10:09:13 -070012
Matt Rosencrantz53ac5852015-09-04 15:14:54 -070013 "v.io/v23"
Todd Wang7a6a4c22015-05-12 23:57:16 -070014 "v.io/v23/context"
15 "v.io/x/lib/cmdline"
Robin Thellend8d31fe72015-10-28 14:50:19 -070016 "v.io/x/ref/lib/security"
Robin Thellend83cd6122015-03-30 10:09:13 -070017 "v.io/x/ref/lib/signals"
Todd Wang7a6a4c22015-05-12 23:57:16 -070018 "v.io/x/ref/lib/v23cmd"
Asim Shankarc7fafb42015-11-17 15:23:03 -080019 _ "v.io/x/ref/runtime/factories/roaming"
Robin Thellend8d31fe72015-10-28 14:50:19 -070020 "v.io/x/ref/services/internal/restsigner"
Todd Wang5bcf1c12015-04-03 18:49:40 -070021 irole "v.io/x/ref/services/role/roled/internal"
Robin Thellend83cd6122015-03-30 10:09:13 -070022)
23
Robin Thellend8d31fe72015-10-28 14:50:19 -070024var (
25 configDir string
26 name string
27 remoteSignerBlessings string
28)
Robin Thellend83cd6122015-03-30 10:09:13 -070029
30func main() {
Todd Wang7a6a4c22015-05-12 23:57:16 -070031 cmdRoleD.Flags.StringVar(&configDir, "config-dir", "", "The directory where the role configuration files are stored.")
32 cmdRoleD.Flags.StringVar(&name, "name", "", "The name to publish for this service.")
Robin Thellend8d31fe72015-10-28 14:50:19 -070033 cmdRoleD.Flags.StringVar(&remoteSignerBlessings, "remote-signer-blessing-dir", "", "Path to the blessings to use with the remote signer. Use the empty string to disable the remote signer.")
Robin Thellend83cd6122015-03-30 10:09:13 -070034
Todd Wang7a6a4c22015-05-12 23:57:16 -070035 cmdline.HideGlobalFlagsExcept()
36 cmdline.Main(cmdRoleD)
37}
38
39var cmdRoleD = &cmdline.Command{
40 Runner: v23cmd.RunnerFunc(runRoleD),
41 Name: "roled",
42 Short: "Runs the Role interface daemon.",
43 Long: "Command roled runs the Role interface daemon.",
44}
45
46func runRoleD(ctx *context.T, env *cmdline.Env, args []string) error {
47 if len(configDir) == 0 {
48 return env.UsageErrorf("-config-dir must be specified")
Robin Thellend83cd6122015-03-30 10:09:13 -070049 }
Todd Wang7a6a4c22015-05-12 23:57:16 -070050 if len(name) == 0 {
51 return env.UsageErrorf("-name must be specified")
Robin Thellend83cd6122015-03-30 10:09:13 -070052 }
Robin Thellend8d31fe72015-10-28 14:50:19 -070053 if remoteSignerBlessings != "" {
54 signer, err := restsigner.NewRestSigner()
55 if err != nil {
56 return fmt.Errorf("Failed to create remote signer: %v", err)
57 }
58 state, err := security.NewPrincipalStateSerializer(remoteSignerBlessings)
59 if err != nil {
60 return fmt.Errorf("Failed to create blessing serializer: %v", err)
61 }
62 p, err := security.NewPrincipalFromSigner(signer, state)
63 if err != nil {
64 return fmt.Errorf("Failed to create principal: %v", err)
65 }
66 if ctx, err = v23.WithPrincipal(ctx, p); err != nil {
67 return fmt.Errorf("Failed to set principal: %v", err)
68 }
69 }
Matt Rosencrantz53ac5852015-09-04 15:14:54 -070070 ctx, _, err := v23.WithNewDispatchingServer(ctx, name, irole.NewDispatcher(configDir, name))
Robin Thellend83cd6122015-03-30 10:09:13 -070071 if err != nil {
Todd Wang7a6a4c22015-05-12 23:57:16 -070072 return fmt.Errorf("NewServer failed: %v", err)
Robin Thellend83cd6122015-03-30 10:09:13 -070073 }
Matt Rosencrantzbb6295d2015-06-19 15:13:58 -070074 fmt.Printf("NAME=%s\n", name)
Robin Thellend83cd6122015-03-30 10:09:13 -070075 <-signals.ShutdownOnSignals(ctx)
Todd Wang7a6a4c22015-05-12 23:57:16 -070076 return nil
Robin Thellend83cd6122015-03-30 10:09:13 -070077}