knife-google 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99ff46ae852794142abaae910482f89dd799b057
4
- data.tar.gz: 2e76ef1b04265a9271a7664a2cd9488eb74c357b
3
+ metadata.gz: c84f9e43200cfc6b1555609603026d09b38810a0
4
+ data.tar.gz: 9f6abcc11414666ce8a37b8fa2ffc5c1dcd177c5
5
5
  SHA512:
6
- metadata.gz: 98d48fa470acd31b44a668c15ea2a35026bf87a047ee3ac6faf415556fc379a3d22ca687c1ca317727d0df9d45c48688b38c8ef66cfabdcf10fab4e5c19cfd2e
7
- data.tar.gz: 3731acd0adf71b71771a36568d452e8bf817cb9b69d30fbcfd7fb16487f3ead978bff21f627e7a594fd20086c1f999fe0de4fd20fb54103fcd99cb56ec8115e2
6
+ metadata.gz: e72acb4b9f20c123a7da556700216f9c21d4469623585c9a5d9f9266160c5c21e1f9aaf3a57777a3c715973d156dd65ad675a3b355edd99424314221ac673afa
7
+ data.tar.gz: 817ef80036e1a6dce5a2a8400a54d54b2caa2f3c102cc60665427c0509dacaf2186f493c503681c3c0a50d7aeffc1e22a12e6a4f3208fe14a0573e10f14f2b65
@@ -1,5 +1,9 @@
1
1
  # knife-google Change Log
2
2
 
3
+ ## v2.1.0 (2016-03-04
4
+ * [pr#99](https://github.com/chef/knife-google/pull/99) Support service account scope aliases, similar to the gcloud SDK
5
+ * [pr#101](https://github.com/chef/knife-google/pull/101) Set the application name and version on the API object for proper user-agent formatting
6
+
3
7
  ## v2.0.0 (2016-03-01)
4
8
  * [pr#94](https://github.com/chef/knife-google/pull/94) Full rewrite using knife-cloud, newer Google API client library, Windows instance support, and better user feedback.
5
9
 
data/README.md CHANGED
@@ -4,9 +4,16 @@
4
4
  [![Build Status](https://travis-ci.org/chef/knife-google.svg?branch=master)](https://travis-ci.org/chef/knife-google)
5
5
  [![Dependency Status](https://gemnasium.com/chef/knife-google.svg)](https://gemnasium.com/chef/knife-google)
6
6
 
7
- A plugin for Chef's [knife](https://docs.chef.io/knife.html) tool to create and manage
8
- [Google Compute Engine](https://cloud.google.com/products/compute-engine)
9
- resources.
7
+ ## Overview
8
+
9
+ This is the official Chef [Knife](http://docs.chef.io/knife.html) plugin for
10
+ [Google Compute Engine](https://cloud.google.com/products/compute-engine).
11
+ This plugin gives knife the ability to create, bootstrap, and manage
12
+ Google Compute Engine (GCE) instances.
13
+
14
+ ## Compatibility
15
+
16
+ This plugin has been tested with Chef 12.x and uses the [Google API Ruby Client](https://github.com/google/google-api-ruby-client).
10
17
 
11
18
  # Getting Started
12
19
 
@@ -37,7 +44,7 @@ gem "knife-google", "~> 2.0"
37
44
  Before getting started with this plugin, you must first create a
38
45
  [Google Cloud Platform](https://cloud.google.com/) (GCP) "project" and add the
39
46
  Google Compute Engine service to your project. While GCP has many other services,
40
- such as App Enging and Cloud Storage, this plugin only provides an integration with
47
+ such as App Engine and Cloud Storage, this plugin only provides an integration with
41
48
  Google Compute Engine (GCE).
42
49
 
43
50
  ## Authentication and Authorization
@@ -51,11 +58,13 @@ Google Cloud API. The auth library expects that there is a JSON credentials file
51
58
  The easiest way to create this is to download and install the [Google Cloud SDK](https://cloud.google.com/sdk/) and run the
52
59
  `gcloud auth login` command which will create the credentials file for you.
53
60
 
54
- If you already have a file you'd like to use that is in a different location, set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable with the full path to that file
61
+ If you already have a file you'd like to use that is in a different location, set the
62
+ `GOOGLE_APPLICATION_CREDENTIALS` environment variable with the full path to that file.
55
63
 
56
64
  ## Configuration
57
65
 
58
- All knife-google commands require a project name and zone name to be supplied. You can supply these on the command line:
66
+ All knife-google commands require a project name, and most commands require zone name to be supplied.
67
+ You can supply these on the command line:
59
68
 
60
69
  ```sh
61
70
  knife google server list --gce-project my-test-project --gce-zone us-east1-b
@@ -72,7 +81,18 @@ knife[:gce_zone] = 'us-east1-b'
72
81
 
73
82
  In order to Linux bootstrap nodes, you will first need to ensure your SSH
74
83
  keys are set up correctly. Ensure your SSH public key is properly entered
75
- into your project's Metadata tab in the GCP Console.
84
+ into your project's Metadata tab in the GCP Console. GCE will add your key
85
+ to the appropriate user's `~/.ssh/authorized_keys` file when Chef first
86
+ connects to perform the bootstrap process.
87
+
88
+ * If you don't have one, create a key using `ssh-keygen`
89
+ * Log in to the GCP console, select your project, go to Compute Engine, and go to the Metadata tab.
90
+ * Select the "SSH Keys" tab.
91
+ * Add a new item, and paste in your public key.
92
+ * Note: to change the username automatically detected for the key, prefix your key with the username
93
+ you plan to use as the `--ssh-user` when creating a server. For example, if you plan to connect
94
+ as "chefuser", your key should look like: `chefuser:ssh-rsa AAAAB3N...`
95
+ * Click "Save".
76
96
 
77
97
  You can find [more information on configuring SSH keys](https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys) in
78
98
  the Google Compute Engine documentation.
@@ -136,6 +156,9 @@ None.
136
156
 
137
157
  Display all regions available to the currently-configured project, what each region's status is, and what zones exist in each region.
138
158
 
159
+ Regions are collections of zones. For additional information on regions, please
160
+ refer to the [GCE documentation](https://cloud.google.com/compute/docs/zones).
161
+
139
162
  ### Parameters
140
163
 
141
164
  None.
@@ -150,7 +173,12 @@ None.
150
173
 
151
174
  ## knife google server create INSTANCE_NAME
152
175
 
153
- Create a GCE server instance and bootstrap it with Chef.
176
+ Create a GCE server instance and bootstrap it with Chef. You must supply an instance name,
177
+ a machine type, and an image to use.
178
+
179
+ For a Linux instance, Chef will connect to the instance over SSH based on the `--ssh-user`
180
+ parameter. This user must have SSH keys configured properly in the project's metadata.
181
+ See the [SSH Keys](#ssh-keys) section for more information.
154
182
 
155
183
  ### Parameters
156
184
 
@@ -171,7 +199,7 @@ Create a GCE server instance and bootstrap it with Chef.
171
199
  * **--[no-]gce-can-ip-forward**: If true, the instance will be allowed to perform network forwarding. Defaults to false.
172
200
  * **--gce-tags**: A comma-separated list of tag values to add to the instance.
173
201
  * **--gce-metadata**: A comma-separated list of key=value pairs to be added to the instance metadata. Example: `--gce-metadata mykey=myvalue,yourkey=yourvalue`
174
- * **--gce-service-account-scopes**: A comma-separated list of account scopes for this instance. View a list of scoped by running `gcloud compute instances create --help` and searching for the documentation for the `--scopes` parameter. You must supply the full URI (i.e. "https://www.googleapis.com/auth/devstorage.full_control") or the final part of the URI (i.e. "devstorage.full_control"). Alias names (i.e. "storage-rw") are not permitted.
202
+ * **--gce-service-account-scopes**: A comma-separated list of account scopes for this instance. View a list of scoped by running `gcloud compute instances create --help` and searching for the documentation for the `--scopes` parameter. You must supply the full URI (i.e. "https://www.googleapis.com/auth/devstorage.full_control"), the final part of the URI (i.e. "devstorage.full_control"), or the gcloud alias name (i.e. "storage-rw"). See the output of `gcloud compute instances create --help` for a full list of scopes.
175
203
  * **--gce-service-account-name**: the service account name to use when adding service account scopes. This usually looks like an email address and can be created in the Permissions tab of the Google Cloud Console. Defaults to "default"
176
204
  * **--gce-use-private-ip**: If true, Chef will attempt to bootstrap the device using the private IP rather than the public IP. Defaulst to false.
177
205
  * **--gce-public-ip**: The type of public IP to associate with this instance. If "ephemeral", an ephemeral IP will be assigned. If "none", no public IP will be assigned. If a specific IP address is provided, knife-google will attempt to attach that specific IP address to the instance. Default is "ephemeral".
@@ -187,7 +215,11 @@ knife google server create test-instance-1 --gce-image centos-7-v20160219 --gce-
187
215
 
188
216
  ## knife google server delete INSTANCE_NAME [INSTANCE_NAME]
189
217
 
190
- Deletes one or more GCE server instance. Additionally, if requested, the client and node object for the given instance will be deleted off of the Chef Server as well.
218
+ Deletes one or more GCE server instance. Additionally, if requested, the client and node object
219
+ for the given instance will be deleted off of the Chef Server as well.
220
+
221
+ The boot disk will be deleted as well unless `--no-gce-boot-disk-autodelete` was specified during
222
+ the server creation.
191
223
 
192
224
  ### Parameters
193
225
 
@@ -204,6 +236,8 @@ knife google server delete my-instance-1 my-instance-2 --purge
204
236
 
205
237
  Display the instances in the currently-configured project and zone, their statuses, machine types, IP addresses, and network.
206
238
 
239
+ This command will display all instances in the project/zone, even if they weren't created with knife-google.
240
+
207
241
  ### Parameters
208
242
 
209
243
  None.
@@ -219,6 +253,9 @@ Display information about a single GCE instance, including its status, machine t
219
253
  ## knife google zone list
220
254
 
221
255
  List all available zones in the currently-configured project and what each zone's status is.
256
+ A zone is an isolated location within a region that is independent of other
257
+ zones in the same region. For additional information on zones, please refer
258
+ to the [GCE documentation](https://cloud.google.com/compute/docs/zones).
222
259
 
223
260
  ### Parameters
224
261
 
@@ -22,6 +22,7 @@ require "chef/knife/cloud/helpers"
22
22
  require "chef/knife/cloud/google_service_helpers"
23
23
  require "google/apis/compute_v1"
24
24
  require "ipaddr"
25
+ require "knife-google/version"
25
26
 
26
27
  class Chef::Knife::Cloud
27
28
  class GoogleService < Service
@@ -29,6 +30,28 @@ class Chef::Knife::Cloud
29
30
 
30
31
  attr_reader :project, :zone, :wait_time, :refresh_rate, :max_pages, :max_page_size
31
32
 
33
+ SCOPE_ALIAS_MAP = {
34
+ "bigquery" => "bigquery",
35
+ "cloud-platform" => "cloud-platform",
36
+ "compute-ro" => "compute.readonly",
37
+ "compute-rw" => "compute",
38
+ "datastore" => "datastore",
39
+ "logging-write" => "logging.write",
40
+ "monitoring" => "monitoring",
41
+ "monitoring-write" => "monitoring.write",
42
+ "service-control" => "servicecontrol",
43
+ "service-management" => "service.management",
44
+ "sql" => "sqlservice",
45
+ "sql-admin" => "sqlservice.admin",
46
+ "storage-full" => "devstorage.full_control",
47
+ "storage-ro" => "devstorage.read_only",
48
+ "storage-rw" => "devstorage.read_write",
49
+ "taskqueue" => "taskqueue",
50
+ "useraccounts-ro" => "cloud.useraccounts.readonly",
51
+ "useraccounts-rw" => "cloud.useraccounts",
52
+ "userinfo-email" => "userinfo.email",
53
+ }
54
+
32
55
  def initialize(options = {})
33
56
  @project = options[:project]
34
57
  @zone = options[:zone]
@@ -43,6 +66,10 @@ class Chef::Knife::Cloud
43
66
 
44
67
  @connection = Google::Apis::ComputeV1::ComputeService.new
45
68
  @connection.authorization = authorization
69
+ @connection.client_options = Google::Apis::ClientOptions.new.tap do |opts|
70
+ opts.application_name = "knife-google"
71
+ opts.application_version = Knife::Google::VERSION
72
+ end
46
73
 
47
74
  @connection
48
75
  end
@@ -341,11 +368,20 @@ class Chef::Knife::Cloud
341
368
 
342
369
  service_account = Google::Apis::ComputeV1::ServiceAccount.new
343
370
  service_account.email = options[:service_account_name]
344
- service_account.scopes = options[:service_account_scopes].map { |scope| "https://www.googleapis.com/auth/#{scope}" unless scope.start_with?("https://www.googleapis.com/auth/") }
371
+ service_account.scopes = options[:service_account_scopes].map { |scope| service_account_scope_url(scope) }
345
372
 
346
373
  Array(service_account)
347
374
  end
348
375
 
376
+ def service_account_scope_url(scope)
377
+ return scope if scope.start_with?("https://www.googleapis.com/auth/")
378
+ "https://www.googleapis.com/auth/#{translate_scope_alias(scope)}"
379
+ end
380
+
381
+ def translate_scope_alias(scope_alias)
382
+ SCOPE_ALIAS_MAP.fetch(scope_alias, scope_alias)
383
+ end
384
+
349
385
  def instance_tags_for(tags)
350
386
  return if tags.nil? || tags.empty?
351
387
 
@@ -14,7 +14,7 @@
14
14
  #
15
15
  module Knife
16
16
  module Google
17
- VERSION = "2.0.0".freeze
17
+ VERSION = "2.1.0".freeze
18
18
  MAJOR, MINOR, TINY = VERSION.split(".")
19
19
  end
20
20
  end
@@ -67,10 +67,19 @@ describe Chef::Knife::Cloud::GoogleService do
67
67
  describe '#connection' do
68
68
  it "returns a properly configured ComputeService" do
69
69
  compute_service = double("compute_service")
70
+ client_options = double("client_options")
71
+
70
72
  allow(service).to receive(:connection).and_call_original
73
+
74
+ expect(Google::Apis::ClientOptions).to receive(:new).and_return(client_options)
75
+ expect(client_options).to receive(:application_name=).with("knife-google")
76
+ expect(client_options).to receive(:application_version=).with(Knife::Google::VERSION)
77
+
71
78
  expect(Google::Apis::ComputeV1::ComputeService).to receive(:new).and_return(compute_service)
72
79
  expect(service).to receive(:authorization).and_return("authorization_object")
73
80
  expect(compute_service).to receive(:authorization=).with("authorization_object")
81
+ expect(compute_service).to receive(:client_options=).with(client_options)
82
+
74
83
  expect(service.connection).to eq(compute_service)
75
84
  end
76
85
  end
@@ -594,6 +603,8 @@ describe Chef::Knife::Cloud::GoogleService do
594
603
 
595
604
  expect(Google::Apis::ComputeV1::ServiceAccount).to receive(:new).and_return(service_account)
596
605
  expect(service_account).to receive(:email=).with("account_name")
606
+ expect(service).to receive(:service_account_scope_url).with("scope1").and_return("https://www.googleapis.com/auth/scope1")
607
+ expect(service).to receive(:service_account_scope_url).with("scope2").and_return("https://www.googleapis.com/auth/scope2")
597
608
  expect(service_account).to receive(:scopes=).with([
598
609
  "https://www.googleapis.com/auth/scope1",
599
610
  "https://www.googleapis.com/auth/scope2",
@@ -603,6 +614,28 @@ describe Chef::Knife::Cloud::GoogleService do
603
614
  end
604
615
  end
605
616
 
617
+ describe '#service_account_scope_url' do
618
+ it "returns the passed-in scope if it already looks like a scope URL" do
619
+ scope = "https://www.googleapis.com/auth/fake_scope"
620
+ expect(service.service_account_scope_url(scope)).to eq(scope)
621
+ end
622
+
623
+ it "returns a properly-formatted scope URL if a short-name or alias is provided" do
624
+ expect(service).to receive(:translate_scope_alias).with("scope_alias").and_return("real_scope")
625
+ expect(service.service_account_scope_url("scope_alias")).to eq("https://www.googleapis.com/auth/real_scope")
626
+ end
627
+ end
628
+
629
+ describe '#translate_scope_alias' do
630
+ it "returns a scope for a given alias" do
631
+ expect(service.translate_scope_alias("storage-rw")).to eq("devstorage.read_write")
632
+ end
633
+
634
+ it "returns the passed-in scope alias if nothing matches in the alias map" do
635
+ expect(service.translate_scope_alias("fake_scope")).to eq("fake_scope")
636
+ end
637
+ end
638
+
606
639
  describe '#instance_tags_for' do
607
640
  it "returns nil if tags is nil" do
608
641
  expect(service.instance_tags_for(nil)).to eq(nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-google
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chiraq Jog
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2016-03-01 00:00:00.000000000 Z
16
+ date: 2016-03-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: chef