Skip to content

Commit

Permalink
Code formatting and ruff, bump version, add changelog entries
Browse files Browse the repository at this point in the history
  • Loading branch information
littleK0i committed Oct 13, 2024
1 parent 8ab14bc commit c2b6043
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.34.0] - 2024-10-13

- Introduced CLI option `--env-prefix-separator` which allows to choose separator for env prefix from one of three pre-defined variants: `__`, `_`, `$`. Default is `__`.
- Implemented `AUTHENTICATION_POLICY` object type. It can be referenced from `ACCOUNT_POLICY` and `USER` configs.
- Reworked `WAREHOUSE` resolver, implemented `resource_constraint` parameter for Snowpark-optimized warehouses.

## [0.33.0] - 2024-10-11

This is a major update to policies, which introduces some breaking changes. [Read more about it](https://docs.snowddl.com/breaking-changes-log/0.33.0-october-2024).
Expand Down
4 changes: 3 additions & 1 deletion snowddl/blueprint/ident.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def _validate_env_prefix(self, val):
)

if val and not val.endswith(("__", "_", "$")):
raise ValueError(f"Env prefix [{val}] in identifier must end with valid separator like [__] double underscore, [_] single underscore or [$] dollar")
raise ValueError(
f"Env prefix [{val}] in identifier must end with valid separator like [__] double underscore, [_] single underscore or [$] dollar"
)

return val.upper()

Expand Down
4 changes: 3 additions & 1 deletion snowddl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def _init_env_prefix(self, env_prefix):
if env_prefix:
# Protects from code trying to use Config object and pass env prefix without separator at the end
if not env_prefix.endswith(("__", "_", "$")):
raise ValueError(f"Env prefix [{env_prefix}] in identifier must end with valid separator like [__] double underscore, [_] single underscore or [$] dollar")
raise ValueError(
f"Env prefix [{env_prefix}] in identifier must end with valid separator like [__] double underscore, [_] single underscore or [$] dollar"
)

return env_prefix

Expand Down
2 changes: 1 addition & 1 deletion snowddl/parser/account_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
NetworkPolicyBlueprint,
NetworkPolicyReference,
ObjectType,
SchemaObjectIdent
SchemaObjectIdent,
)
from snowddl.parser.abc_parser import AbstractParser, ParsedFile

Expand Down
22 changes: 13 additions & 9 deletions snowddl/parser/authentication_policy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from snowddl.blueprint import (
AuthenticationPolicyBlueprint,
Ident,
SchemaObjectIdent,
)
from snowddl.blueprint import AuthenticationPolicyBlueprint, SchemaObjectIdent
from snowddl.parser.abc_parser import AbstractParser, ParsedFile


Expand Down Expand Up @@ -52,19 +48,27 @@

class AuthenticationPolicyParser(AbstractParser):
def load_blueprints(self):
self.parse_schema_object_files("authentication_policy", authentication_policy_json_schema, self.process_authentication_policy)
self.parse_schema_object_files(
"authentication_policy", authentication_policy_json_schema, self.process_authentication_policy
)

def process_authentication_policy(self, f: ParsedFile):
# As of Oct 2024, no easy way around hardcoding defaults
# Cannot distinguish missing value and explicitly set default value
# https://docs.snowflake.com/en/sql-reference/sql/create-authentication-policy
bp = AuthenticationPolicyBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
authentication_methods=self.normalise_params_list(f.params.get("authentication_methods")) if f.params.get("authentication_methods") else ["ALL"],
mfa_authentication_methods=self.normalise_params_list(f.params.get("mfa_authentication_methods")) if f.params.get("mfa_authentication_methods") else ["PASSWORD", "SAML"],
authentication_methods=self.normalise_params_list(f.params.get("authentication_methods"))
if f.params.get("authentication_methods")
else ["ALL"],
mfa_authentication_methods=self.normalise_params_list(f.params.get("mfa_authentication_methods"))
if f.params.get("mfa_authentication_methods")
else ["PASSWORD", "SAML"],
mfa_enrollment=f.params.get("mfa_enrollment").upper() if f.params.get("mfa_enrollment") else "OPTIONAL",
client_types=self.normalise_params_list(f.params.get("client_types")) if f.params.get("client_types") else ["ALL"],
security_integrations=self.normalise_params_list(f.params.get("security_integrations")) if f.params.get("security_integrations") else ["ALL"],
security_integrations=self.normalise_params_list(f.params.get("security_integrations"))
if f.params.get("security_integrations")
else ["ALL"],
comment=f.params.get("comment"),
)

Expand Down
1 change: 0 additions & 1 deletion snowddl/parser/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
SchemaObjectIdent,
build_role_ident,
build_default_namespace_ident,
build_schema_object_ident,
)
from snowddl.parser.abc_parser import AbstractParser, ParsedFile
from snowddl.parser.business_role import business_role_json_schema
Expand Down
22 changes: 13 additions & 9 deletions snowddl/resolver/authentication_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,35 @@ def _create_policy(self, bp: AuthenticationPolicyBlueprint):
"AUTHENTICATION_METHODS = ({authentication_methods})",
{
"authentication_methods": bp.authentication_methods,
}
},
)

query.append_nl(
"MFA_AUTHENTICATION_METHODS = ({mfa_authentication_methods})",
{
"mfa_authentication_methods": bp.mfa_authentication_methods,
}
},
)

query.append_nl(
"MFA_ENROLLMENT = {mfa_enrollment}",
{
"mfa_enrollment": bp.mfa_enrollment,
}
},
)

query.append_nl(
"CLIENT_TYPES = ({client_types})",
{
"client_types": bp.client_types,
}
},
)

query.append_nl(
"SECURITY_INTEGRATIONS = ({security_integrations})",
{
"security_integrations": bp.security_integrations,
}
},
)

query.append_nl(
Expand Down Expand Up @@ -246,15 +246,17 @@ def _apply_policy_refs(self, bp: AuthenticationPolicyBlueprint, skip_existing=Fa
self.engine.execute_unsafe_ddl(
"-- Previous policy must be removed before setting a new policy\n"
"ALTER ACCOUNT UNSET AUTHENTICATION POLICY",
condition=self.engine.settings.execute_authentication_policy and self.engine.settings.execute_account_level_policy,
condition=self.engine.settings.execute_authentication_policy
and self.engine.settings.execute_account_level_policy,
)

self.engine.execute_unsafe_ddl(
"ALTER ACCOUNT SET AUTHENTICATION POLICY {policy_name:i}",
{
"policy_name": bp.full_name,
},
condition=self.engine.settings.execute_authentication_policy and self.engine.settings.execute_account_level_policy,
condition=self.engine.settings.execute_authentication_policy
and self.engine.settings.execute_account_level_policy,
)
else:
# Apply new policy for USER (and other object types in future?)
Expand Down Expand Up @@ -287,7 +289,8 @@ def _apply_policy_refs(self, bp: AuthenticationPolicyBlueprint, skip_existing=Fa
if existing_ref["object_type"] == ObjectType.ACCOUNT.name:
self.engine.execute_unsafe_ddl(
"ALTER ACCOUNT UNSET AUTHENTICATION POLICY",
condition=self.engine.settings.execute_authentication_policy and self.engine.settings.execute_account_level_policy,
condition=self.engine.settings.execute_authentication_policy
and self.engine.settings.execute_account_level_policy,
)
else:
self.engine.execute_unsafe_ddl(
Expand All @@ -310,7 +313,8 @@ def _drop_policy_refs(self, policy_name: SchemaObjectIdent):
if existing_ref["object_type"] == ObjectType.ACCOUNT.name:
self.engine.execute_unsafe_ddl(
"ALTER ACCOUNT UNSET AUTHENTICATION POLICY",
condition=self.engine.settings.execute_authentication_policy and self.engine.settings.execute_account_level_policy,
condition=self.engine.settings.execute_authentication_policy
and self.engine.settings.execute_account_level_policy,
)
else:
self.engine.execute_unsafe_ddl(
Expand Down
2 changes: 1 addition & 1 deletion snowddl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.33.0"
__version__ = "0.34.0"

0 comments on commit c2b6043

Please sign in to comment.