Skip to content

Commit c723f07

Browse files
yoavcloudayman-sigma
authored andcommitted
Add support for Snowflake account privileges (apache#1666)
1 parent 2855089 commit c723f07

File tree

5 files changed

+651
-71
lines changed

5 files changed

+651
-71
lines changed

src/ast/mod.rs

Lines changed: 266 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5471,29 +5471,107 @@ impl fmt::Display for FetchDirection {
54715471
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
54725472
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
54735473
pub enum Action {
5474+
AddSearchOptimization,
5475+
Apply {
5476+
apply_type: ActionApplyType,
5477+
},
5478+
ApplyBudget,
5479+
AttachListing,
5480+
AttachPolicy,
5481+
Audit,
5482+
BindServiceEndpoint,
54745483
Connect,
5475-
Create,
5484+
Create {
5485+
obj_type: Option<ActionCreateObjectType>,
5486+
},
54765487
Delete,
5477-
Execute,
5478-
Insert { columns: Option<Vec<Ident>> },
5479-
References { columns: Option<Vec<Ident>> },
5480-
Select { columns: Option<Vec<Ident>> },
5488+
EvolveSchema,
5489+
Execute {
5490+
obj_type: Option<ActionExecuteObjectType>,
5491+
},
5492+
Failover,
5493+
ImportedPrivileges,
5494+
ImportShare,
5495+
Insert {
5496+
columns: Option<Vec<Ident>>,
5497+
},
5498+
Manage {
5499+
manage_type: ActionManageType,
5500+
},
5501+
ManageReleases,
5502+
ManageVersions,
5503+
Modify {
5504+
modify_type: ActionModifyType,
5505+
},
5506+
Monitor {
5507+
monitor_type: ActionMonitorType,
5508+
},
5509+
Operate,
5510+
OverrideShareRestrictions,
5511+
Ownership,
5512+
PurchaseDataExchangeListing,
5513+
Read,
5514+
ReadSession,
5515+
References {
5516+
columns: Option<Vec<Ident>>,
5517+
},
5518+
Replicate,
5519+
ResolveAll,
5520+
Select {
5521+
columns: Option<Vec<Ident>>,
5522+
},
54815523
Temporary,
54825524
Trigger,
54835525
Truncate,
5484-
Update { columns: Option<Vec<Ident>> },
5526+
Update {
5527+
columns: Option<Vec<Ident>>,
5528+
},
54855529
Usage,
54865530
}
54875531

54885532
impl fmt::Display for Action {
54895533
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54905534
match self {
5535+
Action::AddSearchOptimization => f.write_str("ADD SEARCH OPTIMIZATION")?,
5536+
Action::Apply { apply_type } => write!(f, "APPLY {apply_type}")?,
5537+
Action::ApplyBudget => f.write_str("APPLY BUDGET")?,
5538+
Action::AttachListing => f.write_str("ATTACH LISTING")?,
5539+
Action::AttachPolicy => f.write_str("ATTACH POLICY")?,
5540+
Action::Audit => f.write_str("AUDIT")?,
5541+
Action::BindServiceEndpoint => f.write_str("BIND SERVICE ENDPOINT")?,
54915542
Action::Connect => f.write_str("CONNECT")?,
5492-
Action::Create => f.write_str("CREATE")?,
5543+
Action::Create { obj_type } => {
5544+
f.write_str("CREATE")?;
5545+
if let Some(obj_type) = obj_type {
5546+
write!(f, " {obj_type}")?
5547+
}
5548+
}
54935549
Action::Delete => f.write_str("DELETE")?,
5494-
Action::Execute => f.write_str("EXECUTE")?,
5550+
Action::EvolveSchema => f.write_str("EVOLVE SCHEMA")?,
5551+
Action::Execute { obj_type } => {
5552+
f.write_str("EXECUTE")?;
5553+
if let Some(obj_type) = obj_type {
5554+
write!(f, " {obj_type}")?
5555+
}
5556+
}
5557+
Action::Failover => f.write_str("FAILOVER")?,
5558+
Action::ImportedPrivileges => f.write_str("IMPORTED PRIVILEGES")?,
5559+
Action::ImportShare => f.write_str("IMPORT SHARE")?,
54955560
Action::Insert { .. } => f.write_str("INSERT")?,
5561+
Action::Manage { manage_type } => write!(f, "MANAGE {manage_type}")?,
5562+
Action::ManageReleases => f.write_str("MANAGE RELEASES")?,
5563+
Action::ManageVersions => f.write_str("MANAGE VERSIONS")?,
5564+
Action::Modify { modify_type } => write!(f, "MODIFY {modify_type}")?,
5565+
Action::Monitor { monitor_type } => write!(f, "MONITOR {monitor_type}")?,
5566+
Action::Operate => f.write_str("OPERATE")?,
5567+
Action::OverrideShareRestrictions => f.write_str("OVERRIDE SHARE RESTRICTIONS")?,
5568+
Action::Ownership => f.write_str("OWNERSHIP")?,
5569+
Action::PurchaseDataExchangeListing => f.write_str("PURCHASE DATA EXCHANGE LISTING")?,
5570+
Action::Read => f.write_str("READ")?,
5571+
Action::ReadSession => f.write_str("READ SESSION")?,
54965572
Action::References { .. } => f.write_str("REFERENCES")?,
5573+
Action::Replicate => f.write_str("REPLICATE")?,
5574+
Action::ResolveAll => f.write_str("RESOLVE ALL")?,
54975575
Action::Select { .. } => f.write_str("SELECT")?,
54985576
Action::Temporary => f.write_str("TEMPORARY")?,
54995577
Action::Trigger => f.write_str("TRIGGER")?,
@@ -5516,6 +5594,186 @@ impl fmt::Display for Action {
55165594
}
55175595
}
55185596

5597+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5598+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5599+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5600+
/// See <https://docs.snowflake.com/en/sql-reference/sql/grant-privilege>
5601+
/// under `globalPrivileges` in the `CREATE` privilege.
5602+
pub enum ActionCreateObjectType {
5603+
Account,
5604+
Application,
5605+
ApplicationPackage,
5606+
ComputePool,
5607+
DataExchangeListing,
5608+
Database,
5609+
ExternalVolume,
5610+
FailoverGroup,
5611+
Integration,
5612+
NetworkPolicy,
5613+
OrganiationListing,
5614+
ReplicationGroup,
5615+
Role,
5616+
Share,
5617+
User,
5618+
Warehouse,
5619+
}
5620+
5621+
impl fmt::Display for ActionCreateObjectType {
5622+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5623+
match self {
5624+
ActionCreateObjectType::Account => write!(f, "ACCOUNT"),
5625+
ActionCreateObjectType::Application => write!(f, "APPLICATION"),
5626+
ActionCreateObjectType::ApplicationPackage => write!(f, "APPLICATION PACKAGE"),
5627+
ActionCreateObjectType::ComputePool => write!(f, "COMPUTE POOL"),
5628+
ActionCreateObjectType::DataExchangeListing => write!(f, "DATA EXCHANGE LISTING"),
5629+
ActionCreateObjectType::Database => write!(f, "DATABASE"),
5630+
ActionCreateObjectType::ExternalVolume => write!(f, "EXTERNAL VOLUME"),
5631+
ActionCreateObjectType::FailoverGroup => write!(f, "FAILOVER GROUP"),
5632+
ActionCreateObjectType::Integration => write!(f, "INTEGRATION"),
5633+
ActionCreateObjectType::NetworkPolicy => write!(f, "NETWORK POLICY"),
5634+
ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
5635+
ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
5636+
ActionCreateObjectType::Role => write!(f, "ROLE"),
5637+
ActionCreateObjectType::Share => write!(f, "SHARE"),
5638+
ActionCreateObjectType::User => write!(f, "USER"),
5639+
ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
5640+
}
5641+
}
5642+
}
5643+
5644+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5645+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5646+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5647+
/// See <https://docs.snowflake.com/en/sql-reference/sql/grant-privilege>
5648+
/// under `globalPrivileges` in the `APPLY` privilege.
5649+
pub enum ActionApplyType {
5650+
AggregationPolicy,
5651+
AuthenticationPolicy,
5652+
JoinPolicy,
5653+
MaskingPolicy,
5654+
PackagesPolicy,
5655+
PasswordPolicy,
5656+
ProjectionPolicy,
5657+
RowAccessPolicy,
5658+
SessionPolicy,
5659+
Tag,
5660+
}
5661+
5662+
impl fmt::Display for ActionApplyType {
5663+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5664+
match self {
5665+
ActionApplyType::AggregationPolicy => write!(f, "AGGREGATION POLICY"),
5666+
ActionApplyType::AuthenticationPolicy => write!(f, "AUTHENTICATION POLICY"),
5667+
ActionApplyType::JoinPolicy => write!(f, "JOIN POLICY"),
5668+
ActionApplyType::MaskingPolicy => write!(f, "MASKING POLICY"),
5669+
ActionApplyType::PackagesPolicy => write!(f, "PACKAGES POLICY"),
5670+
ActionApplyType::PasswordPolicy => write!(f, "PASSWORD POLICY"),
5671+
ActionApplyType::ProjectionPolicy => write!(f, "PROJECTION POLICY"),
5672+
ActionApplyType::RowAccessPolicy => write!(f, "ROW ACCESS POLICY"),
5673+
ActionApplyType::SessionPolicy => write!(f, "SESSION POLICY"),
5674+
ActionApplyType::Tag => write!(f, "TAG"),
5675+
}
5676+
}
5677+
}
5678+
5679+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5680+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5681+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5682+
/// See <https://docs.snowflake.com/en/sql-reference/sql/grant-privilege>
5683+
/// under `globalPrivileges` in the `EXECUTE` privilege.
5684+
pub enum ActionExecuteObjectType {
5685+
Alert,
5686+
DataMetricFunction,
5687+
ManagedAlert,
5688+
ManagedTask,
5689+
Task,
5690+
}
5691+
5692+
impl fmt::Display for ActionExecuteObjectType {
5693+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5694+
match self {
5695+
ActionExecuteObjectType::Alert => write!(f, "ALERT"),
5696+
ActionExecuteObjectType::DataMetricFunction => write!(f, "DATA METRIC FUNCTION"),
5697+
ActionExecuteObjectType::ManagedAlert => write!(f, "MANAGED ALERT"),
5698+
ActionExecuteObjectType::ManagedTask => write!(f, "MANAGED TASK"),
5699+
ActionExecuteObjectType::Task => write!(f, "TASK"),
5700+
}
5701+
}
5702+
}
5703+
5704+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5705+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5706+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5707+
/// See <https://docs.snowflake.com/en/sql-reference/sql/grant-privilege>
5708+
/// under `globalPrivileges` in the `MANAGE` privilege.
5709+
pub enum ActionManageType {
5710+
AccountSupportCases,
5711+
EventSharing,
5712+
Grants,
5713+
ListingAutoFulfillment,
5714+
OrganizationSupportCases,
5715+
UserSupportCases,
5716+
Warehouses,
5717+
}
5718+
5719+
impl fmt::Display for ActionManageType {
5720+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5721+
match self {
5722+
ActionManageType::AccountSupportCases => write!(f, "ACCOUNT SUPPORT CASES"),
5723+
ActionManageType::EventSharing => write!(f, "EVENT SHARING"),
5724+
ActionManageType::Grants => write!(f, "GRANTS"),
5725+
ActionManageType::ListingAutoFulfillment => write!(f, "LISTING AUTO FULFILLMENT"),
5726+
ActionManageType::OrganizationSupportCases => write!(f, "ORGANIZATION SUPPORT CASES"),
5727+
ActionManageType::UserSupportCases => write!(f, "USER SUPPORT CASES"),
5728+
ActionManageType::Warehouses => write!(f, "WAREHOUSES"),
5729+
}
5730+
}
5731+
}
5732+
5733+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5734+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5735+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5736+
/// See <https://docs.snowflake.com/en/sql-reference/sql/grant-privilege>
5737+
/// under `globalPrivileges` in the `MODIFY` privilege.
5738+
pub enum ActionModifyType {
5739+
LogLevel,
5740+
TraceLevel,
5741+
SessionLogLevel,
5742+
SessionTraceLevel,
5743+
}
5744+
5745+
impl fmt::Display for ActionModifyType {
5746+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5747+
match self {
5748+
ActionModifyType::LogLevel => write!(f, "LOG LEVEL"),
5749+
ActionModifyType::TraceLevel => write!(f, "TRACE LEVEL"),
5750+
ActionModifyType::SessionLogLevel => write!(f, "SESSION LOG LEVEL"),
5751+
ActionModifyType::SessionTraceLevel => write!(f, "SESSION TRACE LEVEL"),
5752+
}
5753+
}
5754+
}
5755+
5756+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5757+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5758+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5759+
/// See <https://docs.snowflake.com/en/sql-reference/sql/grant-privilege>
5760+
/// under `globalPrivileges` in the `MONITOR` privilege.
5761+
pub enum ActionMonitorType {
5762+
Execution,
5763+
Security,
5764+
Usage,
5765+
}
5766+
5767+
impl fmt::Display for ActionMonitorType {
5768+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5769+
match self {
5770+
ActionMonitorType::Execution => write!(f, "EXECUTION"),
5771+
ActionMonitorType::Security => write!(f, "SECURITY"),
5772+
ActionMonitorType::Usage => write!(f, "USAGE"),
5773+
}
5774+
}
5775+
}
5776+
55195777
/// The principal that receives the privileges
55205778
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
55215779
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

0 commit comments

Comments
 (0)