github.com/coreos/mantle@v0.13.0/cmd/plume/plume.go (about)

     1  // Copyright 2014 CoreOS, Inc.
     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 main
    16  
    17  import (
    18  	"io/ioutil"
    19  	"net/http"
    20  
    21  	"github.com/coreos/pkg/capnslog"
    22  	"github.com/spf13/cobra"
    23  
    24  	"github.com/coreos/mantle/auth"
    25  	"github.com/coreos/mantle/cli"
    26  )
    27  
    28  var (
    29  	plog = capnslog.NewPackageLogger("github.com/coreos/mantle", "plume")
    30  	root = &cobra.Command{
    31  		Use:   "plume [command]",
    32  		Short: "The CoreOS release utility",
    33  	}
    34  
    35  	gceJSONKeyFile string
    36  )
    37  
    38  func init() {
    39  	root.PersistentFlags().StringVar(&gceJSONKeyFile, "gce-json-key", "", "use a JSON key for authentication")
    40  }
    41  
    42  func getGoogleClient() (*http.Client, error) {
    43  	if gceJSONKeyFile != "" {
    44  		if b, err := ioutil.ReadFile(gceJSONKeyFile); err == nil {
    45  			return auth.GoogleClientFromJSONKey(b)
    46  		} else {
    47  			return nil, err
    48  		}
    49  	}
    50  	return auth.GoogleClient()
    51  }
    52  
    53  func main() {
    54  	cli.Execute(root)
    55  }