go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/hardcoded/chromeinfra/chromeinfra.go (about)

     1  // Copyright 2017 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 chromeinfra contains hardcoded values related to Chrome Infra.
    16  //
    17  // It is supposed to be imported only by leaf 'main' packages of various
    18  // binaries. All non-main packages must not hardcode any environment related
    19  // values and must accept them as parameters passed from 'main'.
    20  package chromeinfra
    21  
    22  import (
    23  	"fmt"
    24  	"os"
    25  	"path/filepath"
    26  	"sync"
    27  
    28  	homedir "github.com/mitchellh/go-homedir"
    29  	"go.chromium.org/luci/auth"
    30  )
    31  
    32  // TODO(vadimsh): Move the rest of hardcoded stuff here:
    33  //  * tsmon config file: "/etc/chrome-infra/ts-mon.json"
    34  //  * tsmon secrets dir: same as SecretsDir below.
    35  //  * tsmon network detection regexp: `^([\w-]*?-[acm]|master)(\d+)a?$`
    36  
    37  const (
    38  	// BuildbucketHost is the hostname of the Buildbucket service to connect to
    39  	// by default.
    40  	BuildbucketHost = "cr-buildbucket.appspot.com"
    41  
    42  	// CIPDServiceURL is URL of a CIPD backend to connect to by default.
    43  	CIPDServiceURL = "https://chrome-infra-packages.appspot.com"
    44  
    45  	// ConfigServiceHost is the default host of LUCI config service.
    46  	ConfigServiceHost = "config.luci.app"
    47  
    48  	// LogDogHost is the default host of the production LogDog service in Chrome
    49  	// Operations.
    50  	LogDogHost = "logs.chromium.org"
    51  
    52  	// LogDogHostAppSpot is the ".appspot.com" host equivalent of LogDogHost.
    53  	LogDogHostAppSpot = "luci-logdog.appspot.com"
    54  
    55  	// LogDogDevHost is the default host of the development LogDog service in
    56  	// Chrome Operations.
    57  	LogDogDevHost = "luci-logdog-dev.appspot.com"
    58  
    59  	// MachineDatabaseHost is the URL of the Machine Database.
    60  	MachineDatabaseHost = "machine-db.appspot.com"
    61  
    62  	// MachineDatabaseDevHost is the URL of the Machine Database dev instance.
    63  	MachineDatabaseDevHost = "machine-db-dev.appspot.com"
    64  
    65  	// MiloHost is the hostname of the production Milo service.
    66  	MiloHost = "luci-milo.appspot.com"
    67  
    68  	// MiloDevHost is the hostname of the development Milo service.
    69  	MiloDevHost = "luci-milo-dev.appspot.com"
    70  
    71  	// UFSProdHost is the URL of the ufs service.
    72  	UFSProdHost = "ufs.api.cr.dev"
    73  
    74  	// UFSStagingHost is the URL of the staging ufs service.
    75  	UFSStagingHost = "staging.ufs.api.cr.dev"
    76  
    77  	// ResultDBHost is the hostname of the production ResultDB service.
    78  	ResultDBHost = "results.api.cr.dev"
    79  
    80  	// ResultDBStagingHost is the hostname of the staging ResultDB service.
    81  	ResultDBStagingHost = "staging.results.api.cr.dev"
    82  
    83  	// TestSpannerInstance is the name of the Spanner instance used for testing.
    84  	TestSpannerInstance = "projects/chops-spanner-testing/instances/testing"
    85  
    86  	// TokenServerHost is the default host to use in auth.Options.TokenServerHost.
    87  	TokenServerHost = "luci-token-server.appspot.com"
    88  
    89  	// TokenServerDevHost is the host of the LUCI Token Server dev instance.
    90  	TokenServerDevHost = "luci-token-server-dev.appspot.com"
    91  
    92  	// LoginSessionsHost is the host to use for CLI login UI by default.
    93  	LoginSessionsHost = "ci.chromium.org"
    94  
    95  	// RPCExplorerClientID is the default client ID used by RPC Explorer.
    96  	RPCExplorerClientID = "446450136466-e77v49thuh5dculh78gumq3oncqe28m3.apps.googleusercontent.com"
    97  )
    98  
    99  // DefaultAuthOptions returns auth.Options struct prefilled with chrome-infra
   100  // defaults.
   101  func DefaultAuthOptions() auth.Options {
   102  	return auth.Options{
   103  		TokenServerHost:   TokenServerHost,
   104  		SecretsDir:        SecretsDir(),
   105  		LoginSessionsHost: LoginSessionsHost,
   106  		ClientID:          "446450136466-mj75ourhccki9fffaq8bc1e50di315po.apps.googleusercontent.com",
   107  		ClientSecret:      "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",
   108  	}
   109  }
   110  
   111  // SetDefaultAuthOptions sets the chromeinfra defaults on `opts`, returning the
   112  // updated Options.
   113  func SetDefaultAuthOptions(opts auth.Options) auth.Options {
   114  	dflts := DefaultAuthOptions()
   115  	ret := opts
   116  	ret.TokenServerHost = TokenServerHost
   117  	ret.ClientID = dflts.ClientID
   118  	ret.ClientSecret = dflts.ClientSecret
   119  	ret.LoginSessionsHost = dflts.LoginSessionsHost
   120  	ret.SecretsDir = dflts.SecretsDir
   121  	return ret
   122  }
   123  
   124  var secrets struct {
   125  	once sync.Once
   126  	val  string
   127  }
   128  
   129  // SecretsDir returns an absolute path to a directory (in $HOME) to keep secret
   130  // files in (e.g. OAuth refresh tokens) or an empty string if $HOME can't be
   131  // determined (happens in some degenerate cases, it just disables auth token
   132  // cache).
   133  func SecretsDir() string {
   134  	secrets.once.Do(func() {
   135  		home, err := homedir.Dir()
   136  		if err != nil {
   137  			fmt.Fprintf(os.Stderr, "Can't resolve $HOME: %s", err)
   138  		} else {
   139  			secrets.val = filepath.Join(home, ".config", "chrome_infra", "auth")
   140  		}
   141  	})
   142  	return secrets.val
   143  }