blob: 0c153db022cdbb8df23bbafb109cad9a7aeae5a0 [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
Ryan Brown04384432015-08-27 16:08:32 -070027 // EnvAgentPath is the name of the environment variable pointing to a socket
28 // of the agentd process containing all the credentials for a principal (the
29 // blessing store, the blessing roots, possibly the private key etc.).
Ryan Brown0a3e28a2015-08-12 14:59:14 -070030 //
Ryan Brown04384432015-08-27 16:08:32 -070031 // Typically only one of EnvCredentials or EnvAgentPath will be set in a
Ryan Brown0a3e28a2015-08-12 14:59:14 -070032 // process. If both are set, then EnvCredentials takes preference.
33 EnvAgentPath = "V23_AGENT_PATH"
34
Todd Wang8123b5e2015-05-14 18:44:43 -070035 // EnvAgentEndpoint is the name of the environment variable pointing to an
36 // agentd process containing all the credentials a principal (the blessing
37 // store, the blessing roots, possibly the private key etc.).
38 //
Ryan Brown0a3e28a2015-08-12 14:59:14 -070039 // EnvAgentEndpoint is deprecated. New agentd processes should use EnvAgentPath.
40 // If both are set, EnvAgentPath takes preference.
Todd Wang8123b5e2015-05-14 18:44:43 -070041 EnvAgentEndpoint = "V23_AGENT_ENDPOINT"
42
43 // EnvNamespacePrefix is the prefix of all environment variables that define a
44 // namespace root.
45 EnvNamespacePrefix = "V23_NAMESPACE"
46
47 // EnvI18nCatalogueFiles is the name of the environment variable pointing to a
48 // comma-separated list of i18n catalogue files to be loaded at startup.
49 EnvI18nCatalogueFiles = "V23_I18N_CATALOGUE"
50
51 // EnvOAuthIdentityProvider is the name of the environment variable pointing
52 // to the url of the OAuth identity provider used by the principal
53 // seekblessings command.
54 EnvOAuthIdentityProvider = "V23_OAUTH_IDENTITY_PROVIDER"
55)
56
57// EnvNamespaceRoots returns the set of namespace roots to be used by the
58// process, as specified by environment variables.
59//
60// It returns both a map of environment variable name to value and the list of
61// values.
62func EnvNamespaceRoots() (map[string]string, []string) {
63 m := make(map[string]string)
64 var l []string
65 for _, ev := range os.Environ() {
66 p := strings.SplitN(ev, "=", 2)
67 if len(p) != 2 {
68 continue
69 }
70 k, v := p[0], p[1]
71 if strings.HasPrefix(k, EnvNamespacePrefix) && len(v) > 0 {
72 l = append(l, v)
73 m[k] = v
74 }
75 }
76 return m, l
77}
78
79// EnvClearCredentials unsets all environment variables that are used by the
80// Runtime to intialize the principal.
81func EnvClearCredentials() error {
82 for _, v := range []string{
83 EnvCredentials,
84 EnvAgentEndpoint,
85 } {
86 if err := os.Unsetenv(v); err != nil {
87 return err
88 }
89 }
90 return nil
91}