Class: IbmCloudGlobalTagging::GlobalTaggingV1

Inherits:
IBMCloudSdkCore::BaseService
  • Object
show all
Includes:
Concurrent::Async
Defined in:
lib/ibm_cloud_global_tagging/global_tagging_v1.rb

Overview

The global_tagging V1 service.

Constant Summary collapse

DEFAULT_SERVICE_NAME =
"global_tagging"
DEFAULT_SERVICE_URL =
"https://tags.global-search-tagging.cloud.ibm.com"

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ GlobalTaggingV1

Construct a new client for the global_tagging service.

Parameters:

  • args (Hash)

    The args to initialize with

Options Hash (args):

  • service_url (String)

    The base service URL to use when contacting the service. The base service_url may differ between IBM Cloud regions.

  • authenticator (Object)

    The Authenticator instance to be configured for this service.

  • service_name (String)

    The name of the service to configure. Will be used as the key to load any external configuration, if applicable.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ibm_cloud_global_tagging/global_tagging_v1.rb', line 50

def initialize(args = {})
  @__async_initialized__ = false
  defaults = {}
  defaults[:service_url] = DEFAULT_SERVICE_URL
  defaults[:service_name] = DEFAULT_SERVICE_NAME
  defaults[:authenticator] = nil
  user_service_url = args[:service_url] unless args[:service_url].nil?
  args = defaults.merge(args)
  super
  @service_url = user_service_url unless user_service_url.nil?
end

Instance Method Details

#attach_tag(resources: , tag_name: nil, tag_names: nil, account_id: nil, tag_type: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Attach tags. Attaches one or more tags to one or more resources. To attach a ‘user` tag on a

resource, you must have the access listed in the [Granting users access to tag
resources](https://cloud.ibm.com/docs/account?topic=account-access) documentation.
To attach a `service` tag, you must be an authorized service. If that is the case,
then you can attach a `service` tag with your registered `prefix` to any resource
in any account. The account ID must be set through the `account_id` query
parameter.

Parameters:

  • resources (Array[Resource]) (defaults to: )

    List of resources on which the tag or tags should be attached.

  • tag_name (String) (defaults to: nil)

    The name of the tag to attach.

  • tag_names (Array[String]) (defaults to: nil)

    An array of tag names to attach.

  • account_id (String) (defaults to: nil)

    The ID of the billing account where the resources to be tagged lives. It is a required parameter if ‘tag_type` is set to `service`. Otherwise, it is inferred from the authorization IAM token.

  • tag_type (String) (defaults to: nil)

    The type of the tag. Supported values are ‘user` and `service`. `service` is not supported if `providers` is set to `ims`.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/ibm_cloud_global_tagging/global_tagging_v1.rb', line 221

def attach_tag(resources:, tag_name: nil, tag_names: nil, account_id: nil, tag_type: nil)
  raise ArgumentError.new("resources must be provided") if resources.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("global_tagging", "V1", "attach_tag")
  headers.merge!(sdk_headers)

  params = {
    "account_id" => ,
    "tag_type" => tag_type
  }

  data = {
    "resources" => resources,
    "tag_name" => tag_name,
    "tag_names" => tag_names
  }

  method_url = "/v3/tags/attach"

  response = request(
    method: "POST",
    url: method_url,
    headers: headers,
    params: params,
    json: data,
    accept_json: true
  )
  response
end

#delete_tag(tag_name: , providers: nil, account_id: nil, tag_type: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Delete an unused tag. Delete an existing tag. A tag can be deleted only if it is not attached to any

resource.

Parameters:

  • tag_name (String) (defaults to: )

    The name of tag to be deleted.

  • providers (Array[String]) (defaults to: nil)

    Select a provider. Supported values are ‘ghost` and `ims`. To delete tag both in GhoST in IMS, use `ghost,ims`.

  • account_id (String) (defaults to: nil)

    The ID of the billing account to delete the tag for. It is a required parameter if ‘tag_type` is set to `service`, otherwise it is inferred from the authorization IAM token.

  • tag_type (String) (defaults to: nil)

    The type of the tag. Supported values are ‘user` and `service`. `service` is not supported for `providers=ims`.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/ibm_cloud_global_tagging/global_tagging_v1.rb', line 175

def delete_tag(tag_name:, providers: nil, account_id: nil, tag_type: nil)
  raise ArgumentError.new("tag_name must be provided") if tag_name.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("global_tagging", "V1", "delete_tag")
  headers.merge!(sdk_headers)
  providers *= "," unless providers.nil?

  params = {
    "providers" => providers,
    "account_id" => ,
    "tag_type" => tag_type
  }

  method_url = "/v3/tags/%s" % [ERB::Util.url_encode(tag_name)]

  response = request(
    method: "DELETE",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#delete_tag_all(providers: nil, account_id: nil, tag_type: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Delete all unused tags. Delete the tags that are not attached to any resource.

Parameters:

  • providers (String) (defaults to: nil)

    Select a provider. Supported values are ‘ghost` and `ims`.

  • account_id (String) (defaults to: nil)

    The ID of the billing account to delete the tags for. If it is not set, then it is taken from the authorization token. It is a required parameter if ‘tag_type` is set to `service`.

  • tag_type (String) (defaults to: nil)

    The type of the tag. Supported values are ‘user` and `service`. `service` is not supported if the `providers` parameter is set to `ims`.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ibm_cloud_global_tagging/global_tagging_v1.rb', line 137

def delete_tag_all(providers: nil, account_id: nil, tag_type: nil)
  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("global_tagging", "V1", "delete_tag_all")
  headers.merge!(sdk_headers)

  params = {
    "providers" => providers,
    "account_id" => ,
    "tag_type" => tag_type
  }

  method_url = "/v3/tags"

  response = request(
    method: "DELETE",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end

#detach_tag(resources: , tag_name: nil, tag_names: nil, account_id: nil, tag_type: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Detach tags. Detaches one or more tags from one or more resources. To detach a ‘user` tag on a

resource you must have the permissions listed in the [Granting users access to tag
resources](https://cloud.ibm.com/docs/account?topic=account-access) documentation.
To detach a `service` tag you must be an authorized Service. If that is the case,
then you can detach a `service` tag with your registered `prefix` from any
resource in any account. The account ID must be set through the `account_id` query
parameter.

Parameters:

  • resources (Array[Resource]) (defaults to: )

    List of resources on which the tag or tags should be detached.

  • tag_name (String) (defaults to: nil)

    The name of the tag to detach.

  • tag_names (Array[String]) (defaults to: nil)

    An array of tag names to detach.

  • account_id (String) (defaults to: nil)

    The ID of the billing account where the resources to be un-tagged lives. It is a required parameter if ‘tag_type` is set to `service`, otherwise it is inferred from the authorization IAM token.

  • tag_type (String) (defaults to: nil)

    The type of the tag. Supported values are ‘user` and `service`. `service` is not supported for `providers=ims`.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.

Raises:

  • (ArgumentError)


272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/ibm_cloud_global_tagging/global_tagging_v1.rb', line 272

def detach_tag(resources:, tag_name: nil, tag_names: nil, account_id: nil, tag_type: nil)
  raise ArgumentError.new("resources must be provided") if resources.nil?

  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("global_tagging", "V1", "detach_tag")
  headers.merge!(sdk_headers)

  params = {
    "account_id" => ,
    "tag_type" => tag_type
  }

  data = {
    "resources" => resources,
    "tag_name" => tag_name,
    "tag_names" => tag_names
  }

  method_url = "/v3/tags/detach"

  response = request(
    method: "POST",
    url: method_url,
    headers: headers,
    params: params,
    json: data,
    accept_json: true
  )
  response
end

#list_tags(account_id: nil, tag_type: nil, full_data: nil, providers: nil, attached_to: nil, offset: nil, limit: nil, timeout: nil, order_by_name: nil, attached_only: nil) ⇒ IBMCloudSdkCore::DetailedResponse

Get all tags. Lists all tags in a billing account. Use the ‘attached_to` parameter to return the

list of tags attached to the specified resource.

Parameters:

  • account_id (String) (defaults to: nil)

    The ID of the billing account to list the tags for. If it is not set, then it is taken from the authorization token. This parameter is required if ‘tag_type` is set to `service`.

  • tag_type (String) (defaults to: nil)

    The type of the tag you want to list. Supported values are ‘user` and `service`.

  • full_data (Boolean) (defaults to: nil)

    If set to ‘true`, this query returns the provider, `ghost`, `ims` or `ghost,ims`, where the tag exists and the number of attached resources.

  • providers (Array[String]) (defaults to: nil)

    Select a provider. Supported values are ‘ghost` and `ims`. To list GhoST tags and infrastructure tags use `ghost,ims`. `service` tags can only be attached to GhoST onboarded resources, so you don’t need to set this parameter when listing ‘service` tags.

  • attached_to (String) (defaults to: nil)

    If you want to return only the list of tags attached to a specified resource, pass the ID of the resource on this parameter. For GhoST onboarded resources, the resource ID is the CRN; for IMS resources, it is the IMS ID. When using this parameter, you must specify the appropriate provider (‘ims` or `ghost`).

  • offset (Fixnum) (defaults to: nil)

    The offset is the index of the item from which you want to start returning data from.

  • limit (Fixnum) (defaults to: nil)

    The number of tags to return.

  • timeout (Fixnum) (defaults to: nil)

    The search timeout bounds the search request to be executed within the specified time value. It returns the hits accumulated until time runs out.

  • order_by_name (String) (defaults to: nil)

    Order the output by tag name.

  • attached_only (Boolean) (defaults to: nil)

    Filter on attached tags. If ‘true`, it returns only tags that are attached to one or more resources. If `false`, it returns all tags.

Returns:

  • (IBMCloudSdkCore::DetailedResponse)

    A ‘IBMCloudSdkCore::DetailedResponse` object representing the response.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ibm_cloud_global_tagging/global_tagging_v1.rb', line 94

def list_tags(account_id: nil, tag_type: nil, full_data: nil, providers: nil, attached_to: nil, offset: nil, limit: nil, timeout: nil, order_by_name: nil, attached_only: nil)
  headers = {
  }
  sdk_headers = Common.new.get_sdk_headers("global_tagging", "V1", "list_tags")
  headers.merge!(sdk_headers)
  providers *= "," unless providers.nil?

  params = {
    "account_id" => ,
    "tag_type" => tag_type,
    "full_data" => full_data,
    "providers" => providers,
    "attached_to" => attached_to,
    "offset" => offset,
    "limit" => limit,
    "timeout" => timeout,
    "order_by_name" => order_by_name,
    "attached_only" => attached_only
  }

  method_url = "/v3/tags"

  response = request(
    method: "GET",
    url: method_url,
    headers: headers,
    params: params,
    accept_json: true
  )
  response
end