blob: 31ca4bbf87562724882bb66b12fa19d456f8cd00 [file] [log] [blame]
Todd Wang8123b5e2015-05-14 18:44:43 -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
5// Package ref defines constants used through the Vanadium reference
6// implementation, which is implemented in its subdirectories.
7//
8// For more details about the Vanadium project, please visit https://v.io.
9package ref
10
11import (
12 "os"
13 "strings"
14)
15
16const (
17 // EnvCredentials is the name of the environment variable pointing to a
18 // directory containing all the credentials of a principal (the blessing
19 // store, the blessing roots, possibly the private key etc.).
20 //
21 // Typically only one of EnvCredentials or EnvAgentEndpoint will be set in a
22 // process. If both are set, then EnvCredentials takes preference.
23 //
24 // See v.io/x/ref/lib/security.CreatePersistentPrincipal.
25 EnvCredentials = "V23_CREDENTIALS"
26
27 // EnvAgentEndpoint is the name of the environment variable pointing to an
28 // agentd process containing all the credentials a principal (the blessing
29 // store, the blessing roots, possibly the private key etc.).
30 //
31 // Typically only one of EnvCredentials or EnvAgentEndpoint will be set in a
32 // process. If both are set, then EnvCredentials takes preference.
33 EnvAgentEndpoint = "V23_AGENT_ENDPOINT"
34
35 // EnvNamespacePrefix is the prefix of all environment variables that define a
36 // namespace root.
37 EnvNamespacePrefix = "V23_NAMESPACE"
38
39 // EnvI18nCatalogueFiles is the name of the environment variable pointing to a
40 // comma-separated list of i18n catalogue files to be loaded at startup.
41 EnvI18nCatalogueFiles = "V23_I18N_CATALOGUE"
42
43 // EnvOAuthIdentityProvider is the name of the environment variable pointing
44 // to the url of the OAuth identity provider used by the principal
45 // seekblessings command.
46 EnvOAuthIdentityProvider = "V23_OAUTH_IDENTITY_PROVIDER"
47)
48
49// EnvNamespaceRoots returns the set of namespace roots to be used by the
50// process, as specified by environment variables.
51//
52// It returns both a map of environment variable name to value and the list of
53// values.
54func EnvNamespaceRoots() (map[string]string, []string) {
55 m := make(map[string]string)
56 var l []string
57 for _, ev := range os.Environ() {
58 p := strings.SplitN(ev, "=", 2)
59 if len(p) != 2 {
60 continue
61 }
62 k, v := p[0], p[1]
63 if strings.HasPrefix(k, EnvNamespacePrefix) && len(v) > 0 {
64 l = append(l, v)
65 m[k] = v
66 }
67 }
68 return m, l
69}
70
71// EnvClearCredentials unsets all environment variables that are used by the
72// Runtime to intialize the principal.
73func EnvClearCredentials() error {
74 for _, v := range []string{
75 EnvCredentials,
76 EnvAgentEndpoint,
77 } {
78 if err := os.Unsetenv(v); err != nil {
79 return err
80 }
81 }
82 return nil
83}