go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/client/butler/bootstrap/env.go (about) 1 // Copyright 2016 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package bootstrap handles Butler-side bootstrapping functionality. 16 package bootstrap 17 18 import ( 19 "go.chromium.org/luci/common/system/environ" 20 "go.chromium.org/luci/logdog/client/butlerlib/bootstrap" 21 ) 22 23 // Environment is the set of configuration parameters for the bootstrap. 24 // 25 // NOTE: This is an awful encapsulation violation. We should change the butler 26 // protocol so that opening a new stream has the butler immediately reply with 27 // the externally-visible URL to the stream and stop exporting these envvars 28 // (with the exception of StreamServerURI) entirely. 29 // 30 // NOTE: This should use LUCI_CONTEXT instead of bare envvars. 31 type Environment struct { 32 // CoordinatorHost is the coordinator host name, or empty string if we are 33 // not outputting to a Coordinator. 34 // 35 // HACK: If this starts with file:// clients will treat it as a local 36 // filesystem prefix instead of trying to construct an https URL. If this 37 // starts with file://, Project and Prefix should be empty. 38 CoordinatorHost string 39 40 // Project is the project name. If not empty, this will be exported to 41 // subprocesses. 42 Project string 43 // Prefix is the prefix name. If not empty, this will be exported to 44 // subprocesses. 45 Prefix string 46 // StreamServerURI is the streamserver URI. If not empty, this will be 47 // exported to subprocesses. 48 StreamServerURI string 49 } 50 51 // Augment augments the supplied base environment with LogDog Butler bootstrap 52 // parameters. 53 func (e *Environment) Augment(base environ.Env) { 54 exportIf := func(envKey, v string) { 55 if v != "" { 56 base.Set(envKey, v) 57 } 58 } 59 60 exportIf(bootstrap.EnvCoordinatorHost, e.CoordinatorHost) 61 exportIf(bootstrap.EnvStreamPrefix, e.Prefix) 62 exportIf(bootstrap.EnvStreamProject, e.Project) 63 exportIf(bootstrap.EnvStreamServerPath, e.StreamServerURI) 64 }