Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from sptramer/pep8
Browse files Browse the repository at this point in the history
Run PEP8 on content
  • Loading branch information
lmazuel authored Jun 27, 2019
2 parents 32e203d + b122b46 commit 27e342b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

# KeyVault

KV_NAME = HAIKUNATOR.haikunate() # Random name to avoid collision executing this sample
# Random name to avoid collision executing this sample
KV_NAME = HAIKUNATOR.haikunate()

# This default Certificate creation policy. This is the same policy that:
# - Is pre-configured in the Portal when you choose "Generate" in the Certificates tab
Expand Down Expand Up @@ -95,7 +96,7 @@ def run_example():
#
subscription_id = os.environ.get(
'AZURE_SUBSCRIPTION_ID',
'11111111-1111-1111-1111-111111111111') # your Azure Subscription Id
'11111111-1111-1111-1111-111111111111') # your Azure Subscription Id
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
Expand Down Expand Up @@ -185,7 +186,7 @@ def run_example():
certificate_as_secret = kv_client.get_secret(
vault.properties.vault_uri,
certificate_name,
"" # Latest version
"" # Latest version
)
print_item(certificate_as_secret)

Expand Down Expand Up @@ -252,6 +253,7 @@ def run_example():
delete_async_operation.wait()
print("\nDeleted: {}".format(GROUP_NAME))


def print_item(group):
"""Print a ResourceGroup instance."""
if hasattr(group, 'name'):
Expand All @@ -261,13 +263,15 @@ def print_item(group):
print("\tLocation: {}".format(group.location))
print_properties(getattr(group, 'properties', None))


def print_properties(props):
"""Print a ResourceGroup propertyies instance."""
if props and hasattr(props, 'provisioning_state'):
print("\tProperties:")
print("\t\tProvisioning State: {}".format(props.provisioning_state))
print("\n\n")


def resolve_service_principal(identifier):
"""Get an object_id from a client_id.
"""
Expand All @@ -282,13 +286,15 @@ def resolve_service_principal(identifier):
os.environ['AZURE_TENANT_ID']
)

result = list(graphrbac_client.service_principals.list(filter="servicePrincipalNames/any(c:c eq '{}')".format(identifier)))
result = list(graphrbac_client.service_principals.list(
filter="servicePrincipalNames/any(c:c eq '{}')".format(identifier)))
if result:
return result[0].object_id
raise RuntimeError("Unable to get object_id from client_id")

###### Network creation, not specific to MSI scenario ######


def create_virtual_network(network_client):
"""Usual VNet creation.
"""
Expand All @@ -315,6 +321,7 @@ def create_virtual_network(network_client):
SUBNET_NAME,
)


def create_public_ip(network_client):
"""Usual PublicIP creation.
"""
Expand All @@ -329,6 +336,7 @@ def create_public_ip(network_client):
)
return pip_poller.result()


def create_network_interface(network_client, subnet, public_ip):
"""Usual create NIC.
"""
Expand All @@ -352,18 +360,21 @@ def create_network_interface(network_client, subnet, public_ip):

###### VM creation, not specific to this scenario ######


def get_hardware_profile():
return {
'vm_size': 'standard_a0'
}


def get_network_profile(network_interface_id):
return {
'network_interfaces': [{
'id': network_interface_id,
}],
}


def get_storage_profile():
return {
'image_reference': {
Expand All @@ -374,5 +385,6 @@ def get_storage_profile():
}
}


if __name__ == "__main__":
run_example()

0 comments on commit 27e342b

Please sign in to comment.