Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def org_import(config, username_or_alias, org_name):
org_config = {"username": username_or_alias}
scratch_org_config = ScratchOrgConfig(org_config, org_name)
scratch_org_config.config["created"] = True
info = scratch_org_config.scratch_info
scratch_org_config.config["days"] = calculate_org_days(info)
scratch_org_config.config["date_created"] = parse_api_datetime(info["created_date"])
config.keychain.set_org(scratch_org_config)
click.echo(
"Imported scratch org: {org_id}, username: {username}".format(
**scratch_org_config.scratch_info
)
def set_org(self, org_config):
org_json = json.dumps(org_config.config, cls=DjangoJSONEncoder)
try:
org = Org.objects.get(repo=self.build.repo, name=org_config.name)
org.json = org_json
except Org.DoesNotExist:
org = Org(name=org_config.name, json=org_json, repo=self.build.repo)
org.scratch = isinstance(org_config, ScratchOrgConfig)
if not org.scratch:
org.save()
self.project_config, "orgs__scratch__{}".format(config_name)
)
if days is not None:
# Allow override of scratch config's default days
scratch_config["days"] = days
else:
# Use scratch config days or default of 1 day
scratch_config.setdefault("days", 1)
scratch_config["set_password"] = bool(set_password)
scratch_config["scratch"] = True
scratch_config.setdefault("namespaced", False)
scratch_config["config_name"] = config_name
scratch_config["sfdx_alias"] = "{}__{}".format(
self.project_config.project__name, org_name
)
org_config = ScratchOrgConfig(scratch_config, org_name)
self.set_org(org_config)
def _load_orgs(self):
for key, value in self._get_env():
if key.startswith(self.org_var_prefix):
org_config = json.loads(value)
org_name = key[len(self.org_var_prefix) :].lower()
if org_config.get("scratch"):
self.orgs[org_name] = ScratchOrgConfig(json.loads(value), org_name)
else:
self.orgs[org_name] = OrgConfig(json.loads(value), org_name)
def _get_org_config(self):
org_config = json.loads(self.json)
org_config["date_created"] = parse_datetime(org_config["date_created"])
return ScratchOrgConfig(org_config, self.org.name)
def _get_env(self):
env = super(SFDXOrgTask, self)._get_env()
if not isinstance(self.org_config, ScratchOrgConfig):
# For non-scratch keychain orgs, pass the access token via env var
env["SFDX_INSTANCE_URL"] = self.org_config.instance_url
env["SFDX_USERNAME"] = self.org_config.access_token
return env
def _construct_config(self, config_class, args):
if args[0].get("scratch"):
config_class = ScratchOrgConfig
return config_class(*args)