-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path_client_factory.py
More file actions
52 lines (35 loc) · 2.04 KB
/
_client_factory.py
File metadata and controls
52 lines (35 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long
# pylint: disable=protected-access
from azext_partnercenter._headers import add_user_agent_header
def get_api_client(cli_ctx, *_):
"""Gets an instance of an sdk client"""
# subscription_id = cli_ctx.data['subscription_id']
from azure.cli.core._profile import Profile
profile = Profile(cli_ctx=cli_ctx)
# subscription = profile.get_subscription(subscription_id)
creds, _, _ = profile.get_raw_token(resource="https://api.partner.microsoft.com")
from azext_partnercenter.vendored_sdks.v1.partnercenter.api_client import ApiClient
api_client = ApiClient()
api_client.configuration.access_token = creds[1]
# set authorixation header to the raw token credentials fetched
api_client.set_default_header("Authorization", creds[0] + " " + creds[1])
api_client.set_default_header("If-Match", "*")
add_user_agent_header(api_client.set_default_header)
return api_client
def get_api_client_for_graph(cli_ctx, *_):
"""Gets an instance of a Product Ingestion client"""
from azure.cli.core._profile import Profile
profile = Profile(cli_ctx=cli_ctx)
from ._product_ingestion_api_client import ProductIngestionApiClientConfiguration, ProductIngestionApiClient
creds, _, _ = profile.get_raw_token(resource=ProductIngestionApiClientConfiguration.server_resource)
api_client = ProductIngestionApiClient()
api_client.configuration.access_token = creds[1]
# set authorixation header to the raw token credentials fetched
api_client.set_default_header("Authorization", creds[0] + " " + creds[1])
api_client.set_default_header("If-Match", "*")
add_user_agent_header(api_client.set_default_header)
return api_client