github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/builder/googlecompute/client_secrets.go (about)

     1  package googlecompute
     2  
     3  import (
     4  	"encoding/json"
     5  	"io/ioutil"
     6  )
     7  
     8  // clientSecrets represents the client secrets of a GCE service account.
     9  type clientSecrets struct {
    10  	Web struct {
    11  		AuthURI     string `json:"auth_uri"`
    12  		ClientEmail string `json:"client_email"`
    13  		ClientId    string `json:"client_id"`
    14  		TokenURI    string `json:"token_uri"`
    15  	}
    16  }
    17  
    18  // loadClientSecrets loads the GCE client secrets file identified by path.
    19  func loadClientSecrets(path string) (*clientSecrets, error) {
    20  	var cs *clientSecrets
    21  	secretBytes, err := ioutil.ReadFile(path)
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	err = json.Unmarshal(secretBytes, &cs)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	return cs, nil
    32  }