cmd/principal: The --from value from the the environment
Add an environment variable to set the default value for the
seekblessings --from flag.
We will set this in the staging version of vbash so that seekblessings
will always do the right thing.
Change-Id: I4f89f65f01731334f25f744839bd9a3c0999ff10
diff --git a/cmd/principal/main.go b/cmd/principal/main.go
index c1975a4..8cdc55a 100644
--- a/cmd/principal/main.go
+++ b/cmd/principal/main.go
@@ -28,6 +28,7 @@
"v.io/v23/security"
"v.io/v23/vom"
"v.io/x/lib/cmdline"
+ "v.io/x/ref/envvar"
vsecurity "v.io/x/ref/lib/security"
_ "v.io/x/ref/profiles/static"
)
@@ -891,7 +892,11 @@
cmdBless.Flags.StringVar(&flagBlessRemoteToken, "remote-token", "", "Token provided by principal running the 'recvblessings' command")
cmdBless.Flags.StringVar(&flagRemoteArgFile, "remote-arg-file", "", "File containing bless arguments written by 'principal recvblessings -remote-arg-file FILE EXTENSION' command. This can be provided to bless in place of --remote-key, --remote-token, and <principal>")
- cmdSeekBlessings.Flags.StringVar(&flagSeekBlessingsFrom, "from", "https://dev.v.io/auth/google", "URL to use to begin the seek blessings process")
+ defaultFrom := "https://dev.v.io/auth/google"
+ if e := os.Getenv(envvar.OAuthIdentityProvider); e != "" {
+ defaultFrom = e
+ }
+ cmdSeekBlessings.Flags.StringVar(&flagSeekBlessingsFrom, "from", defaultFrom, "URL to use to begin the seek blessings process")
cmdSeekBlessings.Flags.BoolVar(&flagSeekBlessingsSetDefault, "set-default", true, "If true, the blessings obtained will be set as the default blessing in the store")
cmdSeekBlessings.Flags.StringVar(&flagSeekBlessingsForPeer, "for-peer", string(security.AllPrincipals), "If non-empty, the blessings obtained will be marked for peers matching this pattern in the store")
cmdSeekBlessings.Flags.BoolVar(&flagSeekBlessingsBrowser, "browser", true, "If false, the seekblessings command will not open the browser and only print the url to visit.")
diff --git a/cmd/vbash b/cmd/vbash
index 9ccf5b1..d7e3c3e 100755
--- a/cmd/vbash
+++ b/cmd/vbash
@@ -140,14 +140,16 @@
# Check staging flag "-s".
local INSTALL_DIR="${HOME}/.vbash"
- local SEEK_BLESSINGS_URL="https://dev.v.io/auth/google"
- local STAGING=0
+ local IDENTITY_PROVIDER="https://dev.v.io/auth/google"
+ local TAG=""
+ local NS="/(dev.v.io/role/vprod)@ns.dev.v.io:8101"
while getopts ":s" opt; do
case $opt in
s)
INSTALL_DIR="${HOME}/.vbash-staging"
- SEEK_BLESSINGS_URL="https://dev.staging.v.io/auth/google"
- STAGING=1
+ IDENTITY_PROVIDER="https://dev.staging.v.io/auth/google"
+ TAG="\[\e[1;35m\][STAGING] "
+ NS="/(dev.v.io/role/vprod)@ns.dev.staging.v.io:8101"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
@@ -196,12 +198,6 @@
# Use a custom rcfile to optionally get a blessing and also to modify the
# shell prompt to include the default vanadium blessing.
- local TAG=""
- local NS="/(dev.v.io/role/vprod)@ns.dev.v.io:8101"
- if [[ "${STAGING}" == 1 ]]; then
- TAG="\[\e[1;35m\][STAGING] "
- NS="/(dev.v.io/role/vprod)@ns.dev.staging.v.io:8101"
- fi
cat <<EOF > "${INSTALL_DIR}/rcfile"
if [[ Darwin == "$(uname)" ]]; then
if [[ -r /etc/profile ]]; then . /etc/profile; fi
@@ -214,11 +210,12 @@
else
if [[ -f ~/.bashrc ]]; then . ~/.bashrc; fi
fi
-if [[ "${SEEK_BLESSING}" -eq "1" ]]; then
- "${BIN_INSTALL}/principal" seekblessings -from=${SEEK_BLESSINGS_URL}
-fi
export PROMPT_COMMAND='PS1="\u@\h (${TAG}\[\e[1;32m\]\$("${BIN_INSTALL}/principal" dump -s)\[\e[0m\]):\w \$ "'
export V23_NAMESPACE="${NS}"
+export V23_OAUTH_IDENTITY_PROVIDER="${IDENTITY_PROVIDER}"
+if [[ "${SEEK_BLESSING}" -eq "1" ]]; then
+ "${BIN_INSTALL}/principal" seekblessings
+fi
EOF
diff --git a/envvar/envvar.go b/envvar/envvar.go
index e91a566..5d7d810 100644
--- a/envvar/envvar.go
+++ b/envvar/envvar.go
@@ -29,6 +29,10 @@
// I18nCatalogueFiles points to a comma-separated list of i18n
// catalogue files to be loaded at startup.
I18nCatalogueFiles = "V23_I18N_CATALOGUE"
+
+ // OAuthIdentityProvider points to the url of the OAuth identity
+ // provider used by the principal seekblessings command.
+ OAuthIdentityProvider = "V23_OAUTH_IDENTITY_PROVIDER"
)
// NamespaceRoots returns the set of namespace roots to be used by the process,