Deployment fix for --auto_create_cli_app flag bug (#2921)

* Update .gitignore

* re-add sync-fork.yml

deleted after merge from origin/main

* Update README.md

TEST

* Update README.md

* Update sync-fork.yml

bump ver to 1.8

* updated deploy.py and configuration.py

* cleanup

* formatting

* linter cleanup

* linter cleanup 2

* better logging

* last linter issue

* remove extra app

* Updating getting started docs for config refactor

* Update docs/getting-started.md

Co-authored-by: Noah McGregor Harper <74685766+nharper285@users.noreply.github.com>

* update getting-started.md doc for config refactor

* update getting-started.md doc for config refactor

---------

Co-authored-by: Noah McGregor Harper <74685766+nharper285@users.noreply.github.com>
This commit is contained in:
Adam
2023-03-10 15:26:40 -08:00
committed by GitHub
parent 49543cfa14
commit 1f67494334
3 changed files with 110 additions and 53 deletions

View File

@ -398,36 +398,41 @@ class Client:
(password_id, password) = self.create_password(app["id"])
cli_app = get_application(
app_id=uuid.UUID(self.cli_app_id),
subscription_id=self.get_subscription_id(),
)
try:
cli_app = get_application(
app_id=uuid.UUID(self.cli_app_id),
subscription_id=self.get_subscription_id(),
)
except Exception as err:
cli_app = None
logger.info(
"Could not find the default CLI application under the current "
"subscription."
)
logger.debug(f"Error finding CLI application due to: {err}")
if self.auto_create_cli_app:
logger.info("auto_create_cli_app specified, creating a new CLI application")
app_info = register_application(
"onefuzz-cli",
self.application_name,
OnefuzzAppRole.CliClient,
self.get_subscription_id(),
)
if not cli_app:
if self.auto_create_cli_app:
logger.info(
"Could not find the default CLI application under the current "
"subscription and auto_create specified, creating a new one"
try:
cli_app = get_application(
app_id=app_info.client_id,
subscription_id=self.get_subscription_id(),
)
app_info = register_application(
"onefuzz-cli",
self.application_name,
OnefuzzAppRole.CliClient,
self.get_subscription_id(),
)
self.cli_config = {
"client_id": app_info.client_id,
"authority": self.authority,
}
else:
self.cli_app_id = str(app_info.client_id)
logger.info(f"New CLI app created - cli_app_id : {self.cli_app_id}")
except Exception as err:
logger.error(
"error deploying. could not find specified CLI app registrion."
"use flag --auto_create_cli_app to automatically create CLI registration"
"or specify a correct app id with --cli_app_id."
f"Unable to determine new 'cli_app_id' for new app registration: {err} "
)
sys.exit(1)
else:
if cli_app:
onefuzz_cli_app = cli_app
authorize_application(uuid.UUID(onefuzz_cli_app["appId"]), app["appId"])
@ -467,8 +472,15 @@ class Client:
OnefuzzAppRole.ManagedNode,
)
self.results["client_id"] = app["appId"]
self.results["client_secret"] = password
self.results["client_id"] = app["appId"]
self.results["client_secret"] = password
else:
logger.error(
"error deploying. could not find specified CLI app registrion."
"use flag --auto_create_cli_app to automatically create CLI registration"
"or specify a correct app id with --cli_app_id."
)
sys.exit(1)
def update_existing_app_registration(
self, app: Dict[str, Any], app_roles: List[Dict[str, Any]]
@ -777,7 +789,10 @@ class Client:
config_template = json.load(template_handle)
try:
config = Config(config_template)
if self.auto_create_cli_app:
config = Config(config_template, True)
else:
config = Config(config_template)
self.rules = parse_rules(config)
## Values provided via the CLI will override what's in the config.json
@ -789,8 +804,9 @@ class Client:
self.tenant_domain = config.tenant_domain
if self.multi_tenant_domain == "":
self.multi_tenant_domain = config.multi_tenant_domain
if self.cli_app_id == "":
self.cli_app_id = config.cli_client_id
if not self.cli_app_id:
if not self.auto_create_cli_app:
self.cli_app_id = config.cli_client_id
except Exception as ex:
logging.info(