Extend AAD password creation timeout and optionally log said password
@@ -89,7 +89,6 @@ FUNC_TOOLS_ERROR = (
logger = logging.getLogger("deploy")
-
def gen_guid():
return str(uuid.uuid4())
@@ -112,6 +111,7 @@ class Client:
create_registration,
migrations,
export_appinsights: bool,
+ log_service_principal: bool,
):
self.resource_group = resource_group
self.arm_template = arm_template
@@ -133,6 +133,7 @@ class Client:
}
self.migrations = migrations
self.export_appinsights = export_appinsights
+ self.log_service_principal = log_service_principal
machine = platform.machine()
system = platform.system()
@@ -219,13 +220,15 @@ class Client:
# Work-around the race condition where the app is created but passwords cannot
# be created yet.
count = 0
+ wait = 5
+ timeout_seconds = 60
while True:
- time.sleep(5)
+ time.sleep(wait)
count += 1
try:
return add_application_password(object_id)
except CLIError as err:
- if count > 5:
+ if count > timeout_seconds/wait:
raise err
logger.info("creating password failed, trying again")
@@ -327,6 +330,9 @@ class Client:
self.results["client_secret"] = password
# Log `client_secret` for consumption by CI.
+ if self.log_service_principal:
+ logger.info("client_id: %s client_secret: %s", app.app_id, password)
+ else:
logger.debug("client_id: %s client_secret: %s", app.app_id, password)
def deploy_template(self):
@@ -706,10 +712,9 @@ def main():
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument(
"--create_pool_registration",
- default=False,
- type=bool,
+ action="store_true",
help="Create an application registration and/or generate a "
- "password for the pool agent (default: False)",
+ "password for the pool agent",
)
parser.add_argument(
"--apply_migrations",
@@ -723,6 +728,11 @@ def main():
action="store_true",
help="enable appinsight log export",
)
+ parser.add_argument(
+ "--log_service_principal",
+ action="store_true",
+ help="display service prinipal with info log level",
+ )
args = parser.parse_args()
if shutil.which("func") is None:
@@ -745,6 +755,7 @@ def main():
args.create_pool_registration,
args.apply_migrations,
args.export_appinsights,
+ args.log_service_principal,
)
if args.verbose:
level = logging.DEBUG
