Skip to content

Commit ee7d447

Browse files
feat: add new account management v4 api
1 parent b9c87e6 commit ee7d447

2 files changed

Lines changed: 222 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# -*- coding: utf-8 -*-
2+
# (C) Copyright IBM Corp. 2021, 2022.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
"""
18+
Examples for AccountManagementV4
19+
"""
20+
21+
import os
22+
import pytest
23+
from ibm_cloud_sdk_core import ApiException, read_external_sources
24+
from ibm_platform_services.account_management_v4 import *
25+
26+
#
27+
# This file provides an example of how to use the Account Management service.
28+
#
29+
# The following configuration properties are assumed to be defined:
30+
#
31+
# ACCOUNT_MANAGEMENT_URL=<service url>
32+
# ACCOUNT_MANAGEMENT_AUTHTYPE=iam
33+
# ACCOUNT_MANAGEMENT_AUTH_URL=<IAM token service URL - omit this if using the production environment>
34+
# ACCOUNT_MANAGEMENT_APIKEY=<IAM apikey>
35+
# ACCOUNT_MANAGEMENT_ACCOUNT_ID=<account ID>
36+
37+
# These configuration properties can be exported as environment variables, or stored
38+
# in a configuration file and then:
39+
# export IBM_CREDENTIALS_FILE=<name of configuration file>
40+
#
41+
42+
config_file = 'account_management.env'
43+
44+
account_management_service = None
45+
46+
47+
config = None
48+
49+
account_id = None
50+
51+
##############################################################################
52+
# Start of Examples for Service: AccountManagementV4
53+
##############################################################################
54+
# region
55+
class TestAccountManagementV4Examples:
56+
"""
57+
Example Test Class for AccountManagementV4
58+
"""
59+
60+
@classmethod
61+
def setup_class(cls):
62+
global account_management_service
63+
if os.path.exists(config_file):
64+
os.environ['IBM_CREDENTIALS_FILE'] = config_file
65+
# begin-common
66+
67+
account_management_service = AccountManagementV4.new_instance(
68+
service_name='ACCOUNT_MANAGEMENT',
69+
)
70+
# end-common
71+
assert account_management_service is not None
72+
73+
# Load the configuration
74+
global config
75+
config = read_external_sources(AccountManagementV4.DEFAULT_SERVICE_NAME)
76+
77+
global account_id
78+
account_id = config['ACCOUNT_ID']
79+
print('Setup complete.')
80+
81+
needscredentials = pytest.mark.skipif(
82+
not os.path.exists(config_file), reason="External configuration not available, skipping..."
83+
)
84+
85+
@needscredentials
86+
def test_get_account_info_example(self):
87+
"""
88+
test_get_account_info_example
89+
"""
90+
assert account_id is not None
91+
92+
try:
93+
print('\nget_account_info() result:')
94+
# begin-get_account_info
95+
96+
account_info = account_management_service.get_account_info(
97+
account_id=account_id,
98+
).get_result()
99+
100+
print(json.dumps(account_info, indent=2))
101+
102+
# end-get_account_info
103+
104+
except ApiException as e:
105+
pytest.fail(str(e))
106+
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# coding: utf-8
2+
3+
# (C) Copyright IBM Corp. 2026.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# IBM OpenAPI SDK Code Generator Version: 3.70.0-7df966bf-20230419-195904
18+
19+
"""
20+
Manage the lifecycle of your users using Account Management APIs.
21+
22+
API Version: 1.0
23+
"""
24+
25+
from typing import Dict, List
26+
import json
27+
28+
from ibm_cloud_sdk_core import BaseService, DetailedResponse, get_query_param
29+
from ibm_cloud_sdk_core.authenticators.authenticator import Authenticator
30+
from ibm_cloud_sdk_core.get_authenticator import get_authenticator_from_environment
31+
from ibm_cloud_sdk_core.utils import convert_model
32+
33+
from .common import get_sdk_headers
34+
35+
class AccountManagementV4(BaseService):
36+
"""The Account Management V4 service."""
37+
38+
DEFAULT_SERVICE_URL = 'https://accounts.cloud.ibm.com'
39+
DEFAULT_SERVICE_NAME = 'account_management'
40+
41+
@classmethod
42+
def new_instance(
43+
cls,
44+
service_name: str = DEFAULT_SERVICE_NAME,
45+
) -> 'AccountManagementV4':
46+
"""
47+
Return a new client for the account management service using the specified
48+
parameters and external configuration.
49+
"""
50+
authenticator = get_authenticator_from_environment(service_name)
51+
service = cls(authenticator)
52+
service.configure_service(service_name)
53+
return service
54+
55+
def __init__(
56+
self,
57+
authenticator: Authenticator = None,
58+
) -> None:
59+
"""
60+
Construct a new client for the Account Management service.
61+
62+
:param Authenticator authenticator: The authenticator specifies the authentication mechanism.
63+
Get up to date information from https://github.com/IBM/python-sdk-core/blob/main/README.md
64+
about initializing the authenticator of your choice.
65+
"""
66+
BaseService.__init__(self, service_url=self.DEFAULT_SERVICE_URL, authenticator=authenticator)
67+
68+
#########################
69+
# Accounts
70+
#########################
71+
def get_account_info(
72+
self,
73+
account_id: str,
74+
**kwargs,
75+
) -> DetailedResponse:
76+
"""
77+
Get account info.
78+
79+
Retrieve an account info by the account id in your account. You can use the
80+
IAM service token or an account user token for authorization. To use this method, the
81+
requesting user or service ID must have at least the viewer, editor, or
82+
administrator role on the Account management service.
83+
84+
:param str account_id: The account ID of the specified account.
85+
:param dict headers: A `dict` containing the request headers
86+
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
87+
:rtype: DetailedResponse with `dict` result representing a `accountInfo` object
88+
"""
89+
90+
if not account_id:
91+
raise ValueError('account_id must be provided')
92+
headers = {}
93+
sdk_headers = get_sdk_headers(
94+
service_name=self.DEFAULT_SERVICE_NAME,
95+
service_version='V4',
96+
operation_id='get_account_info',
97+
)
98+
headers.update(sdk_headers)
99+
100+
if 'headers' in kwargs:
101+
headers.update(kwargs.get('headers'))
102+
del kwargs['headers']
103+
headers['Accept'] = 'application/json'
104+
105+
path_param_keys = ['account_id']
106+
path_param_values = self.encode_path_vars(account_id)
107+
path_param_dict = dict(zip(path_param_keys, path_param_values))
108+
url = '/v4/accounts/{account_id}'.format(**path_param_dict)
109+
request = self.prepare_request(
110+
method='GET',
111+
url=url,
112+
headers=headers,
113+
)
114+
115+
response = self.send(request, **kwargs)
116+
return response

0 commit comments

Comments
 (0)