mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
Merge pull request #3202 from ebriand/gcp-validate-project-name
GCP: validate project name
This commit is contained in:
commit
b7119b2ca5
@ -38,6 +38,9 @@ func NewGCPClient(keys, projectName string) (*GCPClient, error) {
|
|||||||
log.Debugf("Connecting to GCP")
|
log.Debugf("Connecting to GCP")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var client *GCPClient
|
var client *GCPClient
|
||||||
|
if projectName == "" {
|
||||||
|
return nil, fmt.Errorf("the project name is not specified")
|
||||||
|
}
|
||||||
if keys != "" {
|
if keys != "" {
|
||||||
log.Debugf("Using Keys %s", keys)
|
log.Debugf("Using Keys %s", keys)
|
||||||
f, err := os.Open(keys)
|
f, err := os.Open(keys)
|
||||||
@ -63,7 +66,7 @@ func NewGCPClient(keys, projectName string) (*GCPClient, error) {
|
|||||||
projectName: projectName,
|
projectName: projectName,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("Using Application Default crednetials")
|
log.Debugf("Using Application Default credentials")
|
||||||
gc, err := google.DefaultClient(
|
gc, err := google.DefaultClient(
|
||||||
ctx,
|
ctx,
|
||||||
storage.DevstorageReadWriteScope,
|
storage.DevstorageReadWriteScope,
|
||||||
|
@ -52,15 +52,15 @@ func pushGcp(args []string) {
|
|||||||
name = filepath.Base(name)
|
name = filepath.Base(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bucket == "" {
|
|
||||||
log.Fatalf("Please specify the bucket to use")
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := NewGCPClient(keys, project)
|
client, err := NewGCPClient(keys, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to connect to GCP: %v", err)
|
log.Fatalf("Unable to connect to GCP: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if bucket == "" {
|
||||||
|
log.Fatalf("Please specify the bucket to use")
|
||||||
|
}
|
||||||
|
|
||||||
err = client.UploadFile(path, name+suffix, bucket, public)
|
err = client.UploadFile(path, name+suffix, bucket, public)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error copying to Google Storage: %v", err)
|
log.Fatalf("Error copying to Google Storage: %v", err)
|
||||||
|
@ -84,7 +84,7 @@ func runGcp(args []string) {
|
|||||||
|
|
||||||
client, err := NewGCPClient(keys, project)
|
client, err := NewGCPClient(keys, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to connect to GCP")
|
log.Fatalf("Unable to connect to GCP: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = client.CreateInstance(*name, image, zone, machine, disks, data, *nestedVirt, true); err != nil {
|
if err = client.CreateInstance(*name, image, zone, machine, disks, data, *nestedVirt, true); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user