Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 1 | // 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 Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 5 | // The following enables go generate to generate the doc.go file. |
Nicolas Lacasse | 1b1b938 | 2015-09-24 10:00:35 -0700 | [diff] [blame] | 6 | //go:generate go run $JIRI_ROOT/release/go/src/v.io/x/lib/cmdline/testdata/gendoc.go . -help |
Todd Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 7 | |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 8 | package main |
| 9 | |
| 10 | import ( |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 11 | "fmt" |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 12 | |
Matt Rosencrantz | 53ac585 | 2015-09-04 15:14:54 -0700 | [diff] [blame] | 13 | "v.io/v23" |
Todd Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 14 | "v.io/v23/context" |
| 15 | "v.io/x/lib/cmdline" |
Robin Thellend | 8d31fe7 | 2015-10-28 14:50:19 -0700 | [diff] [blame] | 16 | "v.io/x/ref/lib/security" |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 17 | "v.io/x/ref/lib/signals" |
Todd Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 18 | "v.io/x/ref/lib/v23cmd" |
Asim Shankar | c7fafb4 | 2015-11-17 15:23:03 -0800 | [diff] [blame] | 19 | _ "v.io/x/ref/runtime/factories/roaming" |
Robin Thellend | 8d31fe7 | 2015-10-28 14:50:19 -0700 | [diff] [blame] | 20 | "v.io/x/ref/services/internal/restsigner" |
Todd Wang | 5bcf1c1 | 2015-04-03 18:49:40 -0700 | [diff] [blame] | 21 | irole "v.io/x/ref/services/role/roled/internal" |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
Robin Thellend | 8d31fe7 | 2015-10-28 14:50:19 -0700 | [diff] [blame] | 24 | var ( |
| 25 | configDir string |
| 26 | name string |
| 27 | remoteSignerBlessings string |
| 28 | ) |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 29 | |
| 30 | func main() { |
Todd Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 31 | 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 Thellend | 8d31fe7 | 2015-10-28 14:50:19 -0700 | [diff] [blame] | 33 | 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 Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 34 | |
Todd Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 35 | cmdline.HideGlobalFlagsExcept() |
| 36 | cmdline.Main(cmdRoleD) |
| 37 | } |
| 38 | |
| 39 | var 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 | |
| 46 | func 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 Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 49 | } |
Todd Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 50 | if len(name) == 0 { |
| 51 | return env.UsageErrorf("-name must be specified") |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 52 | } |
Robin Thellend | 8d31fe7 | 2015-10-28 14:50:19 -0700 | [diff] [blame] | 53 | 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 Rosencrantz | 53ac585 | 2015-09-04 15:14:54 -0700 | [diff] [blame] | 70 | ctx, _, err := v23.WithNewDispatchingServer(ctx, name, irole.NewDispatcher(configDir, name)) |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 71 | if err != nil { |
Todd Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 72 | return fmt.Errorf("NewServer failed: %v", err) |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 73 | } |
Matt Rosencrantz | bb6295d | 2015-06-19 15:13:58 -0700 | [diff] [blame] | 74 | fmt.Printf("NAME=%s\n", name) |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 75 | <-signals.ShutdownOnSignals(ctx) |
Todd Wang | 7a6a4c2 | 2015-05-12 23:57:16 -0700 | [diff] [blame] | 76 | return nil |
Robin Thellend | 83cd612 | 2015-03-30 10:09:13 -0700 | [diff] [blame] | 77 | } |