本文整理汇总了Golang中go/skia/org/infra/go/metadata.ProjectGet函数的典型用法代码示例。如果您正苦于以下问题:Golang ProjectGet函数的具体用法?Golang ProjectGet怎么用?Golang ProjectGet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ProjectGet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getOAuthClient
// getOAuthClient returns an oauth client.
func getOAuthClient(cacheFilePath string) *http.Client {
var client *http.Client
var err error
if *doOauth || *local {
if *local {
// Load client secrets file. The client_secret.json file must come from
// project id: 470362608618, which is whitelisted for access to
// gs://chromium-skia-gm.
client, err = auth.NewClientWithTransport(true, cacheFilePath, *clientSecretFile, nil, auth.SCOPE_READ_ONLY)
if err != nil {
glog.Fatalf("Failed to auth: (Did you download the client_secret.json file from the project with ID: google.com:chrome-skia #470362608618 ?) %s", err)
}
} else {
// Load client id and secret from metadata.
clientId := metadata.Must(metadata.ProjectGet(metadata.CHROMIUM_SKIA_GM_CLIENT_ID))
clientSecret := metadata.Must(metadata.ProjectGet(metadata.CHROMIUM_SKIA_GM_CLIENT_SECRET))
client, err = auth.NewClientFromIdAndSecret(clientId, clientSecret, cacheFilePath, auth.SCOPE_READ_ONLY)
if err != nil {
glog.Fatalf("Failed to auth: %s", err)
}
}
}
return client
}
示例2: main
// Run the BugChomper server.
func main() {
common.InitWithMetrics("bug_chomper", graphiteServer)
v, err := skiaversion.GetVersion()
if err != nil {
glog.Fatal(err)
}
glog.Infof("Version %s, built at %s", v.Commit, v.Date)
loadTemplates()
if *testing {
*useMetadata = false
}
serverURL := "https://" + *host
if *testing {
serverURL = "http://" + *host + *port
}
// By default use a set of credentials setup for localhost access.
var cookieSalt = "notverysecret"
var clientID = "31977622648-1873k0c1e5edaka4adpv1ppvhr5id3qm.apps.googleusercontent.com"
var clientSecret = "cw0IosPu4yjaG2KWmppj2guj"
var redirectURL = serverURL + "/oauth2callback/"
if *useMetadata {
cookieSalt = metadata.Must(metadata.ProjectGet(metadata.COOKIESALT))
clientID = metadata.Must(metadata.ProjectGet(metadata.CLIENT_ID))
clientSecret = metadata.Must(metadata.ProjectGet(metadata.CLIENT_SECRET))
}
login.Init(clientID, clientSecret, redirectURL, cookieSalt, strings.Join(issue_tracker.OAUTH_SCOPE, " "), login.DEFAULT_DOMAIN_WHITELIST, false)
runServer(serverURL)
}
示例3: main
func main() {
common.InitWithMetrics("push", graphiteServer)
Init()
// By default use a set of credentials setup for localhost access.
var cookieSalt = "notverysecret"
var clientID = "31977622648-1873k0c1e5edaka4adpv1ppvhr5id3qm.apps.googleusercontent.com"
var clientSecret = "cw0IosPu4yjaG2KWmppj2guj"
var redirectURL = fmt.Sprintf("http://localhost%s/oauth2callback/", *port)
if !*local {
cookieSalt = metadata.Must(metadata.ProjectGet(metadata.COOKIESALT))
clientID = metadata.Must(metadata.ProjectGet(metadata.CLIENT_ID))
clientSecret = metadata.Must(metadata.ProjectGet(metadata.CLIENT_SECRET))
redirectURL = "https://push.skia.org/oauth2callback/"
}
login.Init(clientID, clientSecret, redirectURL, cookieSalt, login.DEFAULT_SCOPE, login.DEFAULT_DOMAIN_WHITELIST, *local)
r := mux.NewRouter()
r.PathPrefix("/res/").HandlerFunc(util.MakeResourceHandler(*resourcesDir))
r.HandleFunc("/", mainHandler)
r.HandleFunc("/_/change", changeHandler)
r.HandleFunc("/_/state", stateHandler)
r.HandleFunc("/_/status", statusHandler)
r.HandleFunc("/loginstatus/", login.StatusHandler)
r.HandleFunc("/logout/", login.LogoutHandler)
r.HandleFunc("/oauth2callback/", login.OAuth2CallbackHandler)
http.Handle("/", util.LoggingGzipRequestResponse(r))
glog.Infoln("Ready to serve.")
glog.Fatal(http.ListenAndServe(*port, nil))
}
示例4: AttemptLoadCertFromMetadata
func AttemptLoadCertFromMetadata() {
if *certChainFile == "" {
// Try loading from GCE project level metadata.
certChainContents, err := metadata.ProjectGet("ca_cert_chain")
if err != nil {
glog.Errorf("Failed to load ca_cert_chain from metadata: %s", err)
return
}
keyContents, err := metadata.ProjectGet("ca_key")
if err != nil {
glog.Errorf("Failed to load ca_key from metadata: %s", err)
return
}
fullCertChainFilename := filepath.Join(*workDir, CA_CERT_CHAIN_FILENAME)
fullKeyFilename := filepath.Join(*workDir, CA_KEY_FILENAME)
if err := ioutil.WriteFile(fullCertChainFilename, []byte(certChainContents), 0600); err != nil {
glog.Errorf("Failed to write %s: %s", fullCertChainFilename, err)
return
}
if err := ioutil.WriteFile(fullKeyFilename, []byte(keyContents), 0600); err != nil {
glog.Errorf("Failed to write %s: %s", fullKeyFilename, err)
return
}
*keyFile = fullKeyFilename
*certChainFile = fullCertChainFilename
glog.Infof("SUCCESS: Loaded cert from metadata.")
}
}
示例5: NewClientFromFlagsAndMetadata
// NewClientFromFlagsAndMetadata returns a Client with credentials obtained
// from a combination of flags and metadata, depending on whether the program
// is running in local mode.
func NewClientFromFlagsAndMetadata(local bool) (*Client, error) {
if !local {
userMeta, err := metadata.ProjectGet(metadata.INFLUXDB_NAME)
if err != nil {
return nil, err
}
passMeta, err := metadata.ProjectGet(metadata.INFLUXDB_PASSWORD)
if err != nil {
return nil, err
}
*user = userMeta
*password = passMeta
}
return NewClientFromFlags()
}
示例6: tryLoadingFromMetadata
// tryLoadingFromMetadata tries to load the cookie salt, client id, and client
// secret from GCE project level metadata. If it fails then it returns the salt
// it was passed and the client id and secret are the empty string.
//
// Returns salt, clientID, clientSecret.
func tryLoadingFromMetadata() (string, string, string) {
cookieSalt, err := metadata.ProjectGet(metadata.COOKIESALT)
if err != nil {
return DEFAULT_COOKIE_SALT, "", ""
}
clientID, err := metadata.ProjectGet(metadata.CLIENT_ID)
if err != nil {
return DEFAULT_COOKIE_SALT, "", ""
}
clientSecret, err := metadata.ProjectGet(metadata.CLIENT_SECRET)
if err != nil {
return DEFAULT_COOKIE_SALT, "", ""
}
return cookieSalt, clientID, clientSecret
}
示例7: monitorIssueTracker
// monitorIssueTracker reads the counts for all the types of issues in the skia
// issue tracker (code.google.com/p/skia) and stuffs the counts into Graphite.
func monitorIssueTracker() {
c := &http.Client{
Transport: &http.Transport{
Dial: dialTimeout,
},
}
if *useMetadata {
*apikey = metadata.Must(metadata.ProjectGet(metadata.APIKEY))
}
// Create a new metrics registry for the issue tracker metrics.
addr, err := net.ResolveTCPAddr("tcp", *graphiteServer)
if err != nil {
glog.Fatalln("Failed to resolve the Graphite server: ", err)
}
issueRegistry := metrics.NewRegistry()
go graphite.Graphite(issueRegistry, common.SAMPLE_PERIOD, "issues", addr)
// IssueStatus has all the info we need to capture and record a single issue status. I.e. capture
// the count of all issues with a status of "New".
type IssueStatus struct {
Name string
Metric metrics.Gauge
URL string
}
allIssueStatusLabels := []string{
"New", "Accepted", "Unconfirmed", "Started", "Fixed", "Verified", "Invalid", "WontFix", "Done", "Available", "Assigned",
}
issueStatus := []*IssueStatus{}
for _, issueName := range allIssueStatusLabels {
issueStatus = append(issueStatus, &IssueStatus{
Name: issueName,
Metric: metrics.NewRegisteredGauge(strings.ToLower(issueName), issueRegistry),
URL: "https://www.googleapis.com/projecthosting/v2/projects/skia/issues?fields=totalResults&key=" + *apikey + "&status=" + issueName,
})
}
liveness := imetrics.NewLiveness("issue-tracker")
for _ = range time.Tick(ISSUE_TRACKER_PERIOD) {
for _, issue := range issueStatus {
resp, err := c.Get(issue.URL)
jsonResp := map[string]int64{}
dec := json.NewDecoder(resp.Body)
if err := dec.Decode(&jsonResp); err != nil {
glog.Warningf("Failed to decode JSON response: %s", err)
util.Close(resp.Body)
continue
}
issue.Metric.Update(jsonResp["totalResults"])
glog.Infof("Num Issues: %s - %d", issue.Name, jsonResp["totalResults"])
if err == nil && resp.Body != nil {
util.Close(resp.Body)
}
}
liveness.Update()
}
}
示例8: InitRequestSaltFromMetadata
// InitRequestSaltFromMetadata reads requestSalt from project metadata and returns any error
// encountered. Should be called once at startup.
func InitRequestSaltFromMetadata() error {
saltBase64, err := metadata.ProjectGet(metadata.WEBHOOK_REQUEST_SALT)
if err != nil {
return err
}
if err := setRequestSaltFromBase64([]byte(saltBase64)); err != nil {
return fmt.Errorf("Could not decode salt from %s: %s", metadata.WEBHOOK_REQUEST_SALT, err)
}
return nil
}
示例9: main
func main() {
defer common.LogPanic()
common.InitWithMetrics("mathserv", graphiteServer)
Init()
// By default use a set of credentials setup for localhost access.
var cookieSalt = "notverysecret"
var clientID = "952643138919-5a692pfevie766aiog15io45kjpsh33v.apps.googleusercontent.com"
var clientSecret = "QQfqRYU1ELkds90ku8xlIGl1"
var redirectURL = fmt.Sprintf("http://localhost%s/oauth2callback/", *port)
if !*local {
cookieSalt = metadata.Must(metadata.ProjectGet(metadata.COOKIESALT))
clientID = metadata.Must(metadata.ProjectGet(metadata.CLIENT_ID))
clientSecret = metadata.Must(metadata.ProjectGet(metadata.CLIENT_SECRET))
redirectURL = "https://mathinate.com/oauth2callback/"
}
login.Init(clientID, clientSecret, redirectURL, cookieSalt, login.DEFAULT_SCOPE, "", *local)
r := mux.NewRouter()
r.PathPrefix("/res/").HandlerFunc(util.MakeResourceHandler(*resourcesDir))
r.HandleFunc("/", mainHandler)
r.HandleFunc("/loginstatus/", login.StatusHandler)
r.HandleFunc("/logout/", login.LogoutHandler)
r.HandleFunc("/oauth2callback/", login.OAuth2CallbackHandler)
http.Handle("/", util.LoggingGzipRequestResponse(r))
AttemptLoadCertFromMetadata()
glog.Infoln("Ready to serve.")
if *certChainFile != "" {
glog.Infof("Serving TLS")
go func() {
redir := mux.NewRouter()
redir.HandleFunc("/", redirHandler)
glog.Fatal(http.ListenAndServe(*httpPort, redir))
}()
glog.Fatal(http.ListenAndServeTLS(*port, *certChainFile, *keyFile, nil))
} else {
glog.Infof("Only serving HTTP")
glog.Fatal(http.ListenAndServe(*port, nil))
}
}
示例10: apiKeyFromFlag
// apiKeyFromFlag returns the key that it was passed if the key isn't empty,
// otherwise it tries to fetch the key from the metadata server.
//
// Returns the API Key, or "" if it failed to fetch the key from the metadata
// server.
func apiKeyFromFlag(apiKeyFlag string) string {
apiKey := apiKeyFlag
// If apiKey isn't passed in then read it from the metadata server.
if apiKey == "" {
var err error
if apiKey, err = metadata.ProjectGet(metadata.APIKEY); err != nil {
glog.Errorf("Retrieving API Key failed: %s", err)
return ""
}
}
return apiKey
}
示例11: main
func main() {
flag.Parse()
Init()
// Set up login
var cookieSalt = "notverysecret"
var clientID = "31977622648-ubjke2f3staq6ouas64r31h8f8tcbiqp.apps.googleusercontent.com"
var clientSecret = "rK-kRY71CXmcg0v9I9KIgWci"
var useRedirectURL = fmt.Sprintf("http://localhost%s/oauth2callback/", config.Config.FrontEnd.Port)
if !config.Config.Common.Local {
cookieSalt = metadata.Must(metadata.ProjectGet(metadata.COOKIESALT))
clientID = metadata.Must(metadata.ProjectGet(metadata.CLIENT_ID))
clientSecret = metadata.Must(metadata.ProjectGet(metadata.CLIENT_SECRET))
useRedirectURL = config.Config.FrontEnd.RedirectURL
}
login.Init(clientID, clientSecret, useRedirectURL, cookieSalt, login.DEFAULT_SCOPE, login.DEFAULT_DOMAIN_WHITELIST, config.Config.Common.Local)
// Set up the login related resources.
router.HandleFunc(OAUTH2_CALLBACK_PATH, login.OAuth2CallbackHandler)
router.HandleFunc("/loginstatus/", login.StatusHandler)
router.HandleFunc("/logout/", login.LogoutHandler)
router.HandleFunc("/", mainHandler)
router.HandleFunc("/failed", mainHandler)
router.HandleFunc("/passed", mainHandler)
router.PathPrefix("/res/").HandlerFunc(makeResourceHandler())
jsonRouter := router.PathPrefix("/_").Subrouter()
jsonRouter.HandleFunc("/list", fuzzListHandler).Name("fuzzListHandler")
rootHandler := util.LoggingGzipRequestResponse(router)
if config.Config.FrontEnd.ForceLogin {
rootHandler = login.ForceAuth(rootHandler, OAUTH2_CALLBACK_PATH)
}
http.Handle("/", rootHandler)
glog.Fatal(http.ListenAndServe(config.Config.FrontEnd.Port, nil))
}
示例12: GetPasswordFromMetadata
// GetPasswordFromMetadata retrieve the password from metadata and sets the Password field.
func (c *DatabaseConfig) GetPasswordFromMetadata() error {
if err := c.validate(); err != nil {
return err
}
key := ""
if c.User == USER_RW {
key = metadata.DATABASE_RW_PASSWORD
} else if c.User == USER_ROOT {
key = metadata.DATABASE_ROOT_PASSWORD
}
if key == "" {
return fmt.Errorf("Unknown user %s; could not obtain password from metadata.", c.User)
}
password, err := metadata.ProjectGet(key)
if err != nil {
return fmt.Errorf("Failed to find metadata.")
}
c.Password = password
return nil
}
示例13: NewJWTServiceAccountClient
// NewJWTServiceAccountClient creates a new http.Client that is loaded by first
// attempting to load the JWT JSON Service Account data from GCE Project Level
// metadata, and if that fails falls back to loading the data from a local
// file.
//
// metadataname - The name of the GCE project level metadata key that holds the JWT JSON. If empty a default is used.
// filename - The name of the local file that holds the JWT JSON. If empty a default is used.
// transport - A transport. If nil then a default is used.
func NewJWTServiceAccountClient(metadataname, filename string, transport http.RoundTripper, scopes ...string) (*http.Client, error) {
if metadataname == "" {
metadataname = metadata.JWT_SERVICE_ACCOUNT
}
if filename == "" {
filename = DEFAULT_JWT_FILENAME
}
var body []byte
jwt, err := metadata.ProjectGet(metadataname)
if err != nil {
body, err = ioutil.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("Couldn't find JWT via metadata or in a local file.")
}
} else {
body = []byte(jwt)
}
if transport == nil {
transport = util.NewBackOffTransport()
}
jwtConfig, err := google.JWTConfigFromJSON(body, scopes...)
if err != nil {
return nil, err
}
tokenClient := &http.Client{
Transport: transport,
Timeout: util.REQUEST_TIMEOUT,
}
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, tokenClient)
return &http.Client{
Transport: &oauth2.Transport{
Source: jwtConfig.TokenSource(ctx),
Base: transport,
},
Timeout: util.REQUEST_TIMEOUT,
}, nil
}
示例14: main
func main() {
defer common.LogPanic()
// Setup flags.
influxdb.SetupFlags()
common.InitWithMetrics("status", graphiteServer)
v, err := skiaversion.GetVersion()
if err != nil {
glog.Fatal(err)
}
glog.Infof("Version %s, built at %s", v.Commit, v.Date)
Init()
if *testing {
*useMetadata = false
}
serverURL := "https://" + *host
if *testing {
serverURL = "http://" + *host + *port
}
// Create buildbot remote DB.
db, err = buildbot.NewRemoteDB(*buildbotDbHost)
if err != nil {
glog.Fatal(err)
}
// Setup InfluxDB client.
dbClient, err = influxdb.NewClientFromFlagsAndMetadata(*testing)
if err != nil {
glog.Fatal(err)
}
// By default use a set of credentials setup for localhost access.
var cookieSalt = "notverysecret"
var clientID = "31977622648-1873k0c1e5edaka4adpv1ppvhr5id3qm.apps.googleusercontent.com"
var clientSecret = "cw0IosPu4yjaG2KWmppj2guj"
var redirectURL = serverURL + "/oauth2callback/"
if *useMetadata {
cookieSalt = metadata.Must(metadata.ProjectGet(metadata.COOKIESALT))
clientID = metadata.Must(metadata.ProjectGet(metadata.CLIENT_ID))
clientSecret = metadata.Must(metadata.ProjectGet(metadata.CLIENT_SECRET))
}
login.Init(clientID, clientSecret, redirectURL, cookieSalt, login.DEFAULT_SCOPE, login.DEFAULT_DOMAIN_WHITELIST, false)
// Check out source code.
skiaRepo, err := gitinfo.CloneOrUpdate("https://skia.googlesource.com/skia.git", path.Join(*workdir, "skia"), true)
if err != nil {
glog.Fatalf("Failed to check out Skia: %v", err)
}
infraRepoPath := path.Join(*workdir, "infra")
infraRepo, err := gitinfo.CloneOrUpdate("https://skia.googlesource.com/buildbot.git", infraRepoPath, true)
if err != nil {
glog.Fatalf("Failed to checkout Infra: %v", err)
}
glog.Info("CloneOrUpdate complete")
// Create the commit caches.
commitCaches = map[string]*commit_cache.CommitCache{}
skiaCache, err := commit_cache.New(skiaRepo, path.Join(*workdir, "commit_cache.gob"), DEFAULT_COMMITS_TO_LOAD, db)
if err != nil {
glog.Fatalf("Failed to create commit cache: %v", err)
}
commitCaches[SKIA_REPO] = skiaCache
infraCache, err := commit_cache.New(infraRepo, path.Join(*workdir, "commit_cache_infra.gob"), DEFAULT_COMMITS_TO_LOAD, db)
if err != nil {
glog.Fatalf("Failed to create commit cache: %v", err)
}
commitCaches[INFRA_REPO] = infraCache
glog.Info("commit_cache complete")
// Load Perf and Gold data in a loop.
perfStatus, err = dbClient.Int64PollingStatus("select value from \"alerting.new.value\" where app='skiaperf' and host='skia-perf' order by time desc limit 1", time.Minute)
if err != nil {
glog.Fatalf("Failed to create polling Perf status: %v", err)
}
goldGMStatus, err = dbClient.Int64PollingStatus(fmt.Sprintf(GOLD_STATUS_QUERY_TMPL, "gm"), time.Minute)
if err != nil {
glog.Fatalf("Failed to create polling Gold status: %v", err)
}
goldImageStatus, err = dbClient.Int64PollingStatus(fmt.Sprintf(GOLD_STATUS_QUERY_TMPL, "image"), time.Minute)
if err != nil {
glog.Fatalf("Failed to create polling Gold status: %v", err)
}
// Load slave_hosts_cfg and device cfgs in a loop.
slaveHosts, err = buildbot.SlaveHostsCfgPoller(infraRepoPath)
if err != nil {
glog.Fatal(err)
}
androidDevices, err = device_cfg.AndroidDeviceCfgPoller(*workdir)
if err != nil {
glog.Fatal(err)
}
sshDevices, err = device_cfg.SSHDeviceCfgPoller(*workdir)
if err != nil {
glog.Fatal(err)
//.........这里部分代码省略.........
示例15: main
func main() {
// Setup DB flags.
dbConf := db.DBConfigFromFlags()
common.InitWithMetrics("skiaperf", graphiteServer)
Init()
if !*local {
if err := dbConf.GetPasswordFromMetadata(); err != nil {
glog.Fatal(err)
}
}
if err := dbConf.InitDB(); err != nil {
glog.Fatal(err)
}
stats.Start(nanoTileStore, git)
alerting.Start(nanoTileStore, *apikey)
// By default use a set of credentials setup for localhost access.
var cookieSalt = "notverysecret"
var clientID = "31977622648-1873k0c1e5edaka4adpv1ppvhr5id3qm.apps.googleusercontent.com"
var clientSecret = "cw0IosPu4yjaG2KWmppj2guj"
var redirectURL = fmt.Sprintf("http://localhost%s/oauth2callback/", *port)
if !*local {
cookieSalt = metadata.Must(metadata.ProjectGet(metadata.COOKIESALT))
clientID = metadata.Must(metadata.ProjectGet(metadata.CLIENT_ID))
clientSecret = metadata.Must(metadata.ProjectGet(metadata.CLIENT_SECRET))
redirectURL = "https://perf.skia.org/oauth2callback/"
}
login.Init(clientID, clientSecret, redirectURL, cookieSalt, login.DEFAULT_SCOPE, login.DEFAULT_DOMAIN_WHITELIST, *local)
glog.Infoln("Begin loading data.")
// Resources are served directly.
router := mux.NewRouter()
router.PathPrefix("/res/").HandlerFunc(makeResourceHandler())
router.HandleFunc("/", mainHandler)
router.HandleFunc("/shortcuts/", shortcutHandler)
router.PathPrefix("/tiles/").HandlerFunc(tileHandler)
router.PathPrefix("/single/").HandlerFunc(singleHandler)
router.PathPrefix("/query/").HandlerFunc(queryHandler)
router.HandleFunc("/commits/", commitsHandler)
router.HandleFunc("/shortcommits/", shortCommitsHandler)
router.HandleFunc("/trybots/", trybotHandler)
router.HandleFunc("/clusters/", clustersHandler)
router.HandleFunc("/clustering/", clusteringHandler)
router.PathPrefix("/cl/").HandlerFunc(clHandler)
router.PathPrefix("/activitylog/").HandlerFunc(activityHandler)
router.HandleFunc("/alerts/", alertsHandler)
router.HandleFunc("/alerting/", alertingHandler)
router.HandleFunc("/alert_reset/", alertResetHandler)
router.HandleFunc("/annotate/", annotate.Handler)
router.HandleFunc("/compare/", compareHandler)
router.HandleFunc("/calc/", calcHandler)
router.HandleFunc("/help/", helpHandler)
router.HandleFunc("/oauth2callback/", login.OAuth2CallbackHandler)
router.HandleFunc("/logout/", login.LogoutHandler)
router.HandleFunc("/loginstatus/", login.StatusHandler)
http.Handle("/", util.LoggingGzipRequestResponse(router))
glog.Infoln("Ready to serve.")
glog.Fatal(http.ListenAndServe(*port, nil))
}