Added code to Azure SDK calls to be cloud agnostic

This commit is contained in:
Matthew Garrett 2024-04-21 22:30:55 -07:00
Родитель 3e312ab1d5
Коммит 405bb77557
3 изменённых файлов: 42 добавлений и 9 удалений

Просмотреть файл

@ -35,7 +35,7 @@ To do so, run the following Docker commands from the root directory of the proje
```shell
# App Services Container
docker build --rm --no-cache -t <Repository Name>/ipam:latest -f ./Dockerfile .
docker build --rm --no-cache -t <Repository Name>/ipam:latest -f ./Dockerfile.deb .
docker push <Repository Name>/ipam:latest
# Function Container
@ -60,7 +60,7 @@ Next, use the following commands to update the Azure IPAM containers within your
```shell
# App Services Container
az acr build -r <ACR Name> -t ipam:latest -f ./Dockerfile .
az acr build -r <ACR Name> -t ipam:latest -f ./Dockerfile.deb .
# Function Container
az acr build -r <ACR Name> -t ipamfunc:latest -f ./Dockerfile.func .

Просмотреть файл

@ -290,14 +290,22 @@ async def get_vmss_interfaces_sdk_helper(credentials, vmss, list):
await network_client.close()
async def get_factory_map_sdk(credentials):
SUB_QUERY = "Resources | where type =~ 'Microsoft.DataFactory/factories' | project id, name, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId"
DF_QUERY = "Resources | where type =~ 'Microsoft.DataFactory/factories' | project id, name, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId"
data_factory_map = {}
resource_graph_client = ResourceGraphClient(credentials)
azure_arm_url = 'https://{}'.format(globals.AZURE_ARM_URL)
azure_arm_scope = '{}/.default'.format(azure_arm_url)
resource_graph_client = ResourceGraphClient(
credential=credentials,
base_url=azure_arm_url,
credential_scopes=[azure_arm_scope],
transport=globals.SHARED_TRANSPORT
)
query = QueryRequest(
query=SUB_QUERY,
query=DF_QUERY,
options=QueryRequestOptions(
result_format=ResultFormat.object_array
)
@ -317,8 +325,17 @@ async def get_factory_map_sdk(credentials):
async def get_factory_endpoints_sdk(credentials, factory_map):
factory_list = []
azure_arm_url = 'https://{}'.format(globals.AZURE_ARM_URL)
azure_arm_scope = '{}/.default'.format(azure_arm_url)
for subscription in factory_map.keys():
data_factory_client = DataFactoryManagementClient(credentials, subscription)
data_factory_client = DataFactoryManagementClient(
credential=credentials,
subscription_id=subscription,
base_url=azure_arm_url,
credential_scopes=[azure_arm_scope],
transport=globals.SHARED_TRANSPORT
)
for factory in factory_map[subscription]:
async for poll in data_factory_client.private_end_point_connections.list_by_factory(factory['resource_group'], factory['name']):

Просмотреть файл

@ -104,7 +104,12 @@ async def get_obo_token(assertion):
azure_arm_url = 'https://{}/user_impersonation'.format(globals.AZURE_ARM_URL)
credential = OnBehalfOfCredential(globals.TENANT_ID, globals.CLIENT_ID, client_secret=globals.CLIENT_SECRET, user_assertion=assertion)
credential = OnBehalfOfCredential(
tenant_id=globals.TENANT_ID,
client_id=globals.CLIENT_ID,
client_secret=globals.CLIENT_SECRET,
user_assertion=assertion
)
obo_token = await credential.get_token(azure_arm_url)
await credential.close()
@ -113,14 +118,25 @@ async def get_obo_token(assertion):
async def get_client_credentials():
"""DOCSTRING"""
credential = ClientSecretCredential(globals.TENANT_ID, globals.CLIENT_ID, globals.CLIENT_SECRET, authority=globals.AUTHORITY_HOST)
credential = ClientSecretCredential(
tenant_id=globals.TENANT_ID,
client_id=globals.CLIENT_ID,
client_secret=globals.CLIENT_SECRET,
authority=globals.AUTHORITY_HOST
)
return credential
async def get_obo_credentials(assertion):
"""DOCSTRING"""
credential = OnBehalfOfCredential(globals.TENANT_ID, globals.CLIENT_ID, client_secret=globals.CLIENT_SECRET, user_assertion=assertion, authority=globals.AUTHORITY_HOST)
credential = OnBehalfOfCredential(
tenant_id=globals.TENANT_ID,
client_id=globals.CLIENT_ID,
client_secret=globals.CLIENT_SECRET,
user_assertion=assertion,
authority=globals.AUTHORITY_HOST
)
return credential