forked from dbca-wa/it-assets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create management command to manually provision Azure account.
- Loading branch information
Showing
2 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
organisation/management/commands/azure_account_provision.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.core.management.base import BaseCommand | ||
import logging | ||
from organisation.ascender import ascender_user_import | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Manually provision a new Azure account for an Ascender record, optionally ignoring normal creation rules" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--employee-id", | ||
action="store", | ||
required=True, | ||
type=str, | ||
dest="employee_id", | ||
help="Ascender employee no.", | ||
) | ||
parser.add_argument( | ||
"--ignore-job-start-date", | ||
action="store_true", | ||
dest="ignore_job_start_date", | ||
help="Ignore restriction related to job starting date", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
logger = logging.getLogger("organisation") | ||
|
||
logger.info(f"Provisioning Azure user account for Ascender ID {options['employee_id']}") | ||
if "ignore_job_start_date" in options and options["ignore_job_start_date"]: | ||
logger.info("Ignoring job start date restriction") | ||
user = ascender_user_import(options["employee_id"], True) | ||
else: | ||
user = ascender_user_import(options["employee_id"]) | ||
|
||
if user: | ||
logger.info(f"Azure user account for {user.email} provisioned") | ||
else: | ||
logger.warning("Azure user account not provisioned") |