blob: fe171e77ab8e0f820e99c71ca0c78140de2bb230 [file] [log] [blame]
/*
Copyright 2013 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package creds provides credentials for working with GWT build infrastructure.
package creds
import (
"encoding/json"
"flag"
"os"
"sync"
)
var credsFile = flag.String("creds", os.Getenv("HOME")+"/.gwtcreds", "path to GWT creds file")
var creds struct {
GerritUsername string
GerritPassword string
JenkinsToken string
}
func load() {
f, err := os.Open(*credsFile)
if err != nil {
panic(err)
}
defer f.Close()
if err = json.NewDecoder(f).Decode(&creds); err != nil {
panic(err)
}
}
var once sync.Once
// GerritBasicAuth returns the username and password for calling Gerrit REST API
// as Jenkins.
func GerritBasicAuth() (string, string) {
once.Do(load)
return creds.GerritUsername, creds.GerritPassword
}
// JenkinsAuthToken returns the Jenkins auth token for triggering Jenkins builds.
func JenkinsAuthToken() string {
once.Do(load)
return creds.JenkinsToken
}