gcloud 0.12.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +5 -13
  2. data/lib/gcloud.rb +27 -456
  3. data/lib/gcloud/bigquery.rb +2 -382
  4. data/lib/gcloud/datastore.rb +2 -576
  5. data/lib/gcloud/dns.rb +2 -321
  6. data/lib/gcloud/logging.rb +1 -322
  7. data/lib/gcloud/pubsub.rb +2 -476
  8. data/lib/gcloud/resource_manager.rb +2 -273
  9. data/lib/gcloud/storage.rb +2 -440
  10. data/lib/gcloud/translate.rb +1 -250
  11. data/lib/gcloud/version.rb +2 -2
  12. data/lib/gcloud/vision.rb +1 -501
  13. metadata +36 -332
  14. data/AUTHENTICATION.md +0 -75
  15. data/CHANGELOG.md +0 -382
  16. data/OVERVIEW.md +0 -259
  17. data/lib/gcloud/backoff.rb +0 -150
  18. data/lib/gcloud/bigquery/copy_job.rb +0 -97
  19. data/lib/gcloud/bigquery/credentials.rb +0 -29
  20. data/lib/gcloud/bigquery/data.rb +0 -239
  21. data/lib/gcloud/bigquery/dataset.rb +0 -753
  22. data/lib/gcloud/bigquery/dataset/access.rb +0 -507
  23. data/lib/gcloud/bigquery/dataset/list.rb +0 -169
  24. data/lib/gcloud/bigquery/extract_job.rb +0 -117
  25. data/lib/gcloud/bigquery/insert_response.rb +0 -81
  26. data/lib/gcloud/bigquery/job.rb +0 -299
  27. data/lib/gcloud/bigquery/job/list.rb +0 -172
  28. data/lib/gcloud/bigquery/load_job.rb +0 -202
  29. data/lib/gcloud/bigquery/project.rb +0 -475
  30. data/lib/gcloud/bigquery/query_data.rb +0 -234
  31. data/lib/gcloud/bigquery/query_job.rb +0 -137
  32. data/lib/gcloud/bigquery/schema.rb +0 -359
  33. data/lib/gcloud/bigquery/service.rb +0 -506
  34. data/lib/gcloud/bigquery/table.rb +0 -1141
  35. data/lib/gcloud/bigquery/table/list.rb +0 -180
  36. data/lib/gcloud/bigquery/view.rb +0 -475
  37. data/lib/gcloud/credentials.rb +0 -129
  38. data/lib/gcloud/datastore/commit.rb +0 -148
  39. data/lib/gcloud/datastore/credentials.rb +0 -35
  40. data/lib/gcloud/datastore/cursor.rb +0 -76
  41. data/lib/gcloud/datastore/dataset.rb +0 -660
  42. data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
  43. data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
  44. data/lib/gcloud/datastore/entity.rb +0 -449
  45. data/lib/gcloud/datastore/errors.rb +0 -41
  46. data/lib/gcloud/datastore/gql_query.rb +0 -211
  47. data/lib/gcloud/datastore/grpc_utils.rb +0 -132
  48. data/lib/gcloud/datastore/key.rb +0 -281
  49. data/lib/gcloud/datastore/properties.rb +0 -128
  50. data/lib/gcloud/datastore/query.rb +0 -348
  51. data/lib/gcloud/datastore/service.rb +0 -167
  52. data/lib/gcloud/datastore/transaction.rb +0 -362
  53. data/lib/gcloud/dns/change.rb +0 -158
  54. data/lib/gcloud/dns/change/list.rb +0 -173
  55. data/lib/gcloud/dns/credentials.rb +0 -29
  56. data/lib/gcloud/dns/importer.rb +0 -183
  57. data/lib/gcloud/dns/project.rb +0 -247
  58. data/lib/gcloud/dns/record.rb +0 -170
  59. data/lib/gcloud/dns/record/list.rb +0 -174
  60. data/lib/gcloud/dns/service.rb +0 -167
  61. data/lib/gcloud/dns/zone.rb +0 -759
  62. data/lib/gcloud/dns/zone/list.rb +0 -168
  63. data/lib/gcloud/dns/zone/transaction.rb +0 -176
  64. data/lib/gcloud/errors.rb +0 -206
  65. data/lib/gcloud/gce.rb +0 -56
  66. data/lib/gcloud/grpc_utils.rb +0 -87
  67. data/lib/gcloud/logging/credentials.rb +0 -29
  68. data/lib/gcloud/logging/entry.rb +0 -465
  69. data/lib/gcloud/logging/entry/http_request.rb +0 -141
  70. data/lib/gcloud/logging/entry/list.rb +0 -177
  71. data/lib/gcloud/logging/entry/operation.rb +0 -90
  72. data/lib/gcloud/logging/logger.rb +0 -307
  73. data/lib/gcloud/logging/metric.rb +0 -169
  74. data/lib/gcloud/logging/metric/list.rb +0 -172
  75. data/lib/gcloud/logging/project.rb +0 -642
  76. data/lib/gcloud/logging/resource.rb +0 -84
  77. data/lib/gcloud/logging/resource_descriptor.rb +0 -137
  78. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
  79. data/lib/gcloud/logging/service.rb +0 -267
  80. data/lib/gcloud/logging/sink.rb +0 -227
  81. data/lib/gcloud/logging/sink/list.rb +0 -171
  82. data/lib/gcloud/pubsub/credentials.rb +0 -29
  83. data/lib/gcloud/pubsub/message.rb +0 -94
  84. data/lib/gcloud/pubsub/policy.rb +0 -204
  85. data/lib/gcloud/pubsub/project.rb +0 -482
  86. data/lib/gcloud/pubsub/received_message.rb +0 -160
  87. data/lib/gcloud/pubsub/service.rb +0 -334
  88. data/lib/gcloud/pubsub/subscription.rb +0 -565
  89. data/lib/gcloud/pubsub/subscription/list.rb +0 -208
  90. data/lib/gcloud/pubsub/topic.rb +0 -511
  91. data/lib/gcloud/pubsub/topic/list.rb +0 -174
  92. data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
  93. data/lib/gcloud/resource_manager/credentials.rb +0 -30
  94. data/lib/gcloud/resource_manager/manager.rb +0 -266
  95. data/lib/gcloud/resource_manager/policy.rb +0 -211
  96. data/lib/gcloud/resource_manager/project.rb +0 -484
  97. data/lib/gcloud/resource_manager/project/list.rb +0 -167
  98. data/lib/gcloud/resource_manager/project/updater.rb +0 -130
  99. data/lib/gcloud/resource_manager/service.rb +0 -127
  100. data/lib/gcloud/storage/bucket.rb +0 -775
  101. data/lib/gcloud/storage/bucket/acl.rb +0 -810
  102. data/lib/gcloud/storage/bucket/cors.rb +0 -153
  103. data/lib/gcloud/storage/bucket/list.rb +0 -172
  104. data/lib/gcloud/storage/credentials.rb +0 -29
  105. data/lib/gcloud/storage/errors.rb +0 -65
  106. data/lib/gcloud/storage/file.rb +0 -842
  107. data/lib/gcloud/storage/file/acl.rb +0 -425
  108. data/lib/gcloud/storage/file/list.rb +0 -191
  109. data/lib/gcloud/storage/file/verifier.rb +0 -67
  110. data/lib/gcloud/storage/project.rb +0 -316
  111. data/lib/gcloud/storage/service.rb +0 -347
  112. data/lib/gcloud/translate/api.rb +0 -241
  113. data/lib/gcloud/translate/detection.rb +0 -137
  114. data/lib/gcloud/translate/language.rb +0 -69
  115. data/lib/gcloud/translate/service.rb +0 -80
  116. data/lib/gcloud/translate/translation.rb +0 -112
  117. data/lib/gcloud/vision/annotate.rb +0 -224
  118. data/lib/gcloud/vision/annotation.rb +0 -455
  119. data/lib/gcloud/vision/annotation/entity.rb +0 -234
  120. data/lib/gcloud/vision/annotation/face.rb +0 -1750
  121. data/lib/gcloud/vision/annotation/properties.rb +0 -245
  122. data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
  123. data/lib/gcloud/vision/annotation/text.rb +0 -236
  124. data/lib/gcloud/vision/annotation/vertex.rb +0 -108
  125. data/lib/gcloud/vision/credentials.rb +0 -29
  126. data/lib/gcloud/vision/image.rb +0 -590
  127. data/lib/gcloud/vision/location.rb +0 -115
  128. data/lib/gcloud/vision/project.rb +0 -278
  129. data/lib/gcloud/vision/service.rb +0 -66
  130. data/lib/google/api/annotations.rb +0 -14
  131. data/lib/google/api/http.rb +0 -30
  132. data/lib/google/api/label.rb +0 -24
  133. data/lib/google/api/monitored_resource.rb +0 -25
  134. data/lib/google/datastore/v1beta3/datastore.rb +0 -115
  135. data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
  136. data/lib/google/datastore/v1beta3/entity.rb +0 -63
  137. data/lib/google/datastore/v1beta3/query.rb +0 -128
  138. data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
  139. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
  140. data/lib/google/example/library/v1/library.rb +0 -91
  141. data/lib/google/example/library/v1/library_services.rb +0 -40
  142. data/lib/google/iam/v1/iam_policy.rb +0 -33
  143. data/lib/google/iam/v1/iam_policy_services.rb +0 -30
  144. data/lib/google/iam/v1/policy.rb +0 -25
  145. data/lib/google/logging/type/http_request.rb +0 -28
  146. data/lib/google/logging/type/log_severity.rb +0 -27
  147. data/lib/google/logging/v2/log_entry.rb +0 -44
  148. data/lib/google/logging/v2/logging.rb +0 -56
  149. data/lib/google/logging/v2/logging_config.rb +0 -59
  150. data/lib/google/logging/v2/logging_config_services.rb +0 -32
  151. data/lib/google/logging/v2/logging_metrics.rb +0 -51
  152. data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
  153. data/lib/google/logging/v2/logging_services.rb +0 -31
  154. data/lib/google/longrunning/operations.rb +0 -50
  155. data/lib/google/longrunning/operations_services.rb +0 -29
  156. data/lib/google/protobuf/descriptor.rb +0 -0
  157. data/lib/google/pubsub/v1/pubsub.rb +0 -129
  158. data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
  159. data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
  160. data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
  161. data/lib/google/rpc/code.rb +0 -32
  162. data/lib/google/rpc/error_details.rb +0 -61
  163. data/lib/google/rpc/status.rb +0 -19
  164. data/lib/google/type/color.rb +0 -20
  165. data/lib/google/type/date.rb +0 -18
  166. data/lib/google/type/dayofweek.rb +0 -23
  167. data/lib/google/type/latlng.rb +0 -17
  168. data/lib/google/type/money.rb +0 -18
  169. data/lib/google/type/timeofday.rb +0 -19
@@ -1,174 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
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
-
16
- require "delegate"
17
-
18
- module Gcloud
19
- module Pubsub
20
- class Topic
21
- ##
22
- # Topic::List is a special case Array with additional values.
23
- class List < DelegateClass(::Array)
24
- ##
25
- # If not empty, indicates that there are more topics
26
- # that match the request and this value should be passed to
27
- # the next {Gcloud::Pubsub::Project#topics} to continue.
28
- attr_accessor :token
29
-
30
- ##
31
- # @private Create a new Topic::List with an array of values.
32
- def initialize arr = []
33
- super arr
34
- end
35
-
36
- ##
37
- # Whether there a next page of topics.
38
- #
39
- # @return [Boolean]
40
- #
41
- # @example
42
- # require "gcloud"
43
- #
44
- # gcloud = Gcloud.new
45
- # pubsub = gcloud.pubsub
46
- #
47
- # topics = pubsub.topics
48
- # if topics.next?
49
- # next_topics = topics.next
50
- # end
51
- #
52
- def next?
53
- !token.nil?
54
- end
55
-
56
- ##
57
- # Retrieve the next page of topics.
58
- #
59
- # @return [Topic::List]
60
- #
61
- # @example
62
- # require "gcloud"
63
- #
64
- # gcloud = Gcloud.new
65
- # pubsub = gcloud.pubsub
66
- #
67
- # topics = pubsub.topics
68
- # if topics.next?
69
- # next_topics = topics.next
70
- # end
71
- #
72
- def next
73
- return nil unless next?
74
- ensure_service!
75
- options = { token: token, max: @max }
76
- grpc = @service.list_topics options
77
- self.class.from_grpc grpc, @service, @max
78
- end
79
-
80
- ##
81
- # Retrieves all topics by repeatedly loading {#next} until {#next?}
82
- # returns `false`. Calls the given block once for each topic, which is
83
- # passed as the parameter.
84
- #
85
- # An Enumerator is returned if no block is given.
86
- #
87
- # This method may make several API calls until all topics are retrieved.
88
- # Be sure to use as narrow a search criteria as possible. Please use
89
- # with caution.
90
- #
91
- # @param [Integer] request_limit The upper limit of API requests to make
92
- # to load all topics. Default is no limit.
93
- # @yield [topic] The block for accessing each topic.
94
- # @yieldparam [Topic] topic The topic object.
95
- #
96
- # @return [Enumerator]
97
- #
98
- # @example Iterating each topic by passing a block:
99
- # require "gcloud"
100
- #
101
- # gcloud = Gcloud.new
102
- # pubsub = gcloud.pubsub
103
- #
104
- # topics = pubsub.topics
105
- # topics.all do |topic|
106
- # puts topic.name
107
- # end
108
- #
109
- # @example Using the enumerator by not passing a block:
110
- # require "gcloud"
111
- #
112
- # gcloud = Gcloud.new
113
- # pubsub = gcloud.pubsub
114
- #
115
- # topics = pubsub.topics
116
- # all_names = topics.all.map do |topic|
117
- # topic.name
118
- # end
119
- #
120
- # @example Limit the number of API calls made:
121
- # require "gcloud"
122
- #
123
- # gcloud = Gcloud.new
124
- # pubsub = gcloud.pubsub
125
- #
126
- # topics = pubsub.topics
127
- # topics.all(request_limit: 10) do |topic|
128
- # puts topic.name
129
- # end
130
- #
131
- def all request_limit: nil
132
- request_limit = request_limit.to_i if request_limit
133
- unless block_given?
134
- return enum_for(:all, request_limit: request_limit)
135
- end
136
- results = self
137
- loop do
138
- results.each { |r| yield r }
139
- if request_limit
140
- request_limit -= 1
141
- break if request_limit < 0
142
- end
143
- break unless results.next?
144
- results = results.next
145
- end
146
- end
147
-
148
- ##
149
- # @private New Topic::List from a Google::Pubsub::V1::ListTopicsResponse
150
- # object.
151
- def self.from_grpc grpc_list, service, max = nil
152
- topics = new(Array(grpc_list.topics).map do |grpc|
153
- Topic.from_grpc grpc, service
154
- end)
155
- token = grpc_list.next_page_token
156
- token = nil if token == ""
157
- topics.instance_variable_set "@token", token
158
- topics.instance_variable_set "@service", service
159
- topics.instance_variable_set "@max", max
160
- topics
161
- end
162
-
163
- protected
164
-
165
- ##
166
- # @private Raise an error unless an active connection to the service is
167
- # available.
168
- def ensure_service!
169
- fail "Must have active connection to service" unless @service
170
- end
171
- end
172
- end
173
- end
174
- end
@@ -1,85 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
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
-
16
- module Gcloud
17
- module Pubsub
18
- class Topic
19
- ##
20
- # Topic Publisher object used to publish multiple messages at once.
21
- #
22
- # @example
23
- # require "gcloud"
24
- #
25
- # gcloud = Gcloud.new
26
- # pubsub = gcloud.pubsub
27
- #
28
- # topic = pubsub.topic "my-topic"
29
- # msgs = topic.publish do |t|
30
- # t.publish "new-message-1", foo: :bar
31
- # t.publish "new-message-2", foo: :baz
32
- # t.publish "new-message-3", foo: :bif
33
- # end
34
- class Publisher
35
- ##
36
- # @private The messages to publish
37
- attr_reader :messages
38
-
39
- ##
40
- # @private Create a new instance of the object.
41
- def initialize data = nil, attributes = {}
42
- @messages = []
43
- @mode = :batch
44
- return if data.nil?
45
- @mode = :single
46
- publish data, attributes
47
- end
48
-
49
- ##
50
- # Add multiple messages to the topic.
51
- # All messages added will be published at once.
52
- # See {Gcloud::Pubsub::Topic#publish}
53
- def publish data, attributes = {}
54
- # Convert IO-ish objects to strings
55
- if data.respond_to?(:read) && data.respond_to?(:rewind)
56
- data.rewind
57
- data = data.read
58
- end
59
- # Convert data to encoded byte array to match the protobuf definition
60
- data = String(data).force_encoding("ASCII-8BIT")
61
- # Convert attributes to strings to match the protobuf definition
62
- attributes = Hash[attributes.map { |k, v| [String(k), String(v)] }]
63
- @messages << [data, attributes]
64
- end
65
-
66
- ##
67
- # @private Create Message objects with message ids.
68
- def to_gcloud_messages message_ids
69
- msgs = @messages.zip(Array(message_ids)).map do |arr, id|
70
- Message.from_grpc(
71
- Google::Pubsub::V1::PubsubMessage.new(
72
- data: arr[0], attributes: arr[1], message_id: id))
73
- end
74
- # Return just one Message if a single publish,
75
- # otherwise return the array of Messages.
76
- if @mode == :single && msgs.count <= 1
77
- msgs.first
78
- else
79
- msgs
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,30 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
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
-
16
- require "gcloud/credentials"
17
-
18
- module Gcloud
19
- module ResourceManager
20
- ##
21
- # @private Represents the Oauth2 signing logic for Resource Manager.
22
- class Credentials < Gcloud::Credentials
23
- SCOPE = ["https://www.googleapis.com/auth/cloud-platform"]
24
- PATH_ENV_VARS = %w(RESOURCE_MANAGER_KEYFILE
25
- GCLOUD_KEYFILE GOOGLE_CLOUD_KEYFILE)
26
- JSON_ENV_VARS = %w(RESOURCE_MANAGER_KEYFILE_JSON GCLOUD_KEYFILE_JSON
27
- GOOGLE_CLOUD_KEYFILE_JSON)
28
- end
29
- end
30
- end
@@ -1,266 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
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
-
16
- require "gcloud/errors"
17
- require "gcloud/resource_manager/credentials"
18
- require "gcloud/resource_manager/service"
19
- require "gcloud/resource_manager/project"
20
-
21
- module Gcloud
22
- module ResourceManager
23
- ##
24
- # # Manager
25
- #
26
- # Provides methods for creating, retrieving, and updating projects.
27
- #
28
- # @example
29
- # require "gcloud"
30
- #
31
- # gcloud = Gcloud.new
32
- # resource_manager = gcloud.resource_manager
33
- # resource_manager.projects.each do |project|
34
- # puts projects.project_id
35
- # end
36
- #
37
- # See {Gcloud#resource_manager}
38
- class Manager
39
- ##
40
- # @private The Service object.
41
- attr_accessor :service
42
-
43
- ##
44
- # @private Creates a new Service instance.
45
- #
46
- # See {Gcloud.resource_manager}
47
- def initialize service
48
- @service = service
49
- end
50
-
51
- ##
52
- # Retrieves the projects that are visible to the user and satisfy the
53
- # specified filter. This method returns projects in an unspecified order.
54
- # New projects do not necessarily appear at the end of the list.
55
- #
56
- # @param [String] filter An expression for filtering the results of the
57
- # request. Filter rules are case insensitive.
58
- #
59
- # The fields eligible for filtering are:
60
- #
61
- # * `name`
62
- # * `id`
63
- # * `labels.key` - where `key` is the name of a label
64
- #
65
- # Some examples of using labels as filters:
66
- #
67
- # * `name:*` - The project has a name.
68
- # * `name:Howl` - The project's name is Howl or howl.
69
- # * `name:HOWL` - Equivalent to above.
70
- # * `NAME:howl` - Equivalent to above.
71
- # * `labels.color:*` - The project has the label color.
72
- # * `labels.color:red` - The project's label color has the value red.
73
- # * <code>labels.color:red labels.size:big</code> - The project's label
74
- # color has the value red and its label size has the value big.
75
- # @param [String] token A previously-returned page token representing part
76
- # of the larger set of results to view.
77
- # @param [Integer] max Maximum number of projects to return.
78
- #
79
- # @return [Array<Gcloud::ResourceManager::Project>] (See
80
- # {Gcloud::ResourceManager::Project::List})
81
- #
82
- # @example
83
- # require "gcloud"
84
- #
85
- # gcloud = Gcloud.new
86
- # resource_manager = gcloud.resource_manager
87
- # projects = resource_manager.projects
88
- #
89
- # projects.each do |project|
90
- # puts project.project_id
91
- # end
92
- #
93
- # @example Projects can be filtered using the `filter` option:
94
- # require "gcloud"
95
- #
96
- # gcloud = Gcloud.new
97
- # resource_manager = gcloud.resource_manager
98
- # projects = resource_manager.projects filter: "labels.env:production"
99
- #
100
- # projects.each do |project|
101
- # puts project.project_id
102
- # end
103
- #
104
- # @example Retrieve all projects: (See {Project::List#all})
105
- # require "gcloud"
106
- #
107
- # gcloud = Gcloud.new
108
- # resource_manager = gcloud.resource_manager
109
- # projects = resource_manager.projects
110
- #
111
- # projects.all do |project|
112
- # puts project.project_id
113
- # end
114
- #
115
- def projects filter: nil, token: nil, max: nil
116
- gapi = service.list_project filter: filter, token: token, max: max
117
- Project::List.from_gapi gapi, self, filter, max
118
- end
119
-
120
- ##
121
- # Retrieves the project identified by the specified `project_id`.
122
- #
123
- # @param [String] project_id The ID of the project.
124
- #
125
- # @return [Gcloud::ResourceManager::Project, nil] Returns `nil` if the
126
- # project does not exist
127
- #
128
- # @example
129
- # require "gcloud"
130
- #
131
- # gcloud = Gcloud.new
132
- # resource_manager = gcloud.resource_manager
133
- # project = resource_manager.project "tokyo-rain-123"
134
- # project.project_id #=> "tokyo-rain-123"
135
- #
136
- def project project_id
137
- gapi = service.get_project project_id
138
- Project.from_gapi gapi, service
139
- rescue NotFoundError
140
- nil
141
- end
142
-
143
- ##
144
- # Creates a project resource.
145
- #
146
- # Initially, the project resource is owned by its creator exclusively. The
147
- # creator can later grant permission to others to read or update the
148
- # project.
149
- #
150
- # Several APIs are activated automatically for the project, including
151
- # Google Cloud Storage.
152
- #
153
- # @param [String] project_id The unique, user-assigned ID of the project.
154
- # It must be 6 to 30 lowercase letters, digits, or hyphens. It must
155
- # start with a letter. Trailing hyphens are prohibited.
156
- # @param [String] name The user-assigned name of the project. This field
157
- # is optional and can remain unset.
158
- #
159
- # Allowed characters are: lowercase and uppercase letters, numbers,
160
- # hyphen, single-quote, double-quote, space, and exclamation point.
161
- # @param [Hash] labels The labels associated with this project.
162
- #
163
- # Label keys must be between 1 and 63 characters long and must conform
164
- # to the following regular expression:
165
- # <code>[a-z]([-a-z0-9]*[a-z0-9])?</code>.
166
- #
167
- # Label values must be between 0 and 63 characters long and must conform
168
- # to the regular expression <code>([a-z]([-a-z0-9]*[a-z0-9])?)?</code>.
169
- #
170
- # No more than 256 labels can be associated with a given resource.
171
- #
172
- # @return [Gcloud::ResourceManager::Project]
173
- #
174
- # @example
175
- # require "gcloud"
176
- #
177
- # gcloud = Gcloud.new
178
- # resource_manager = gcloud.resource_manager
179
- # project = resource_manager.create_project "tokyo-rain-123"
180
- #
181
- # @example A project can also be created with a `name` and `labels`:
182
- # require "gcloud"
183
- #
184
- # gcloud = Gcloud.new
185
- # resource_manager = gcloud.resource_manager
186
- # project = resource_manager.create_project "tokyo-rain-123",
187
- # name: "Todos Development",
188
- # labels: {env: :development}
189
- #
190
- def create_project project_id, name: nil, labels: nil
191
- gapi = service.create_project project_id, name, labels
192
- Project.from_gapi gapi, service
193
- end
194
-
195
- ##
196
- # Marks the project for deletion. This method will only affect the project
197
- # if the following criteria are met:
198
- #
199
- # * The project does not have a billing account associated with it.
200
- # * The project has a lifecycle state of `ACTIVE`.
201
- # * This method changes the project's lifecycle state from `ACTIVE` to
202
- # `DELETE_REQUESTED`. The deletion starts at an unspecified time, at
203
- # which point the lifecycle state changes to `DELETE_IN_PROGRESS`.
204
- #
205
- # Until the deletion completes, you can check the lifecycle state by
206
- # retrieving the project with Manager#project. The project remains visible
207
- # to Manager#project and Manager#projects, but cannot be updated.
208
- #
209
- # After the deletion completes, the project is not retrievable by the
210
- # Manager#project and Manager#projects methods.
211
- #
212
- # The caller must have modify permissions for this project.
213
- #
214
- # @param [String] project_id The ID of the project.
215
- #
216
- # @example
217
- # require "gcloud"
218
- #
219
- # gcloud = Gcloud.new
220
- # resource_manager = gcloud.resource_manager
221
- # resource_manager.delete "tokyo-rain-123"
222
- #
223
- def delete project_id
224
- service.delete_project project_id
225
- true
226
- end
227
-
228
- ##
229
- # Restores the project. You can only use this method for a project that
230
- # has a lifecycle state of `DELETE_REQUESTED`. After deletion starts, as
231
- # indicated by a lifecycle state of `DELETE_IN_PROGRESS`, the project
232
- # cannot be restored.
233
- #
234
- # The caller must have modify permissions for this project.
235
- #
236
- # @param [String] project_id The ID of the project.
237
- #
238
- # @example
239
- # require "gcloud"
240
- #
241
- # gcloud = Gcloud.new
242
- # resource_manager = gcloud.resource_manager
243
- # resource_manager.undelete "tokyo-rain-123"
244
- #
245
- def undelete project_id
246
- service.undelete_project project_id
247
- true
248
- end
249
-
250
- protected
251
-
252
- ##
253
- # Create an options hash from the projects parameters.
254
- def list_projects_options filter, options
255
- # Handle only sending in options
256
- if filter.is_a?(::Hash) && options.empty?
257
- options = filter
258
- filter = nil
259
- end
260
- # Give named parameter priority
261
- options[:filter] = filter || options[:filter]
262
- options
263
- end
264
- end
265
- end
266
- end