Skip to content

Commit 4e4f88c

Browse files
committed
Code review comments and missing option
1 parent cfa1572 commit 4e4f88c

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/ast/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10578,6 +10578,7 @@ impl fmt::Display for CreateUser {
1057810578
pub struct AlterUser {
1057910579
pub if_exists: bool,
1058010580
pub name: Ident,
10581+
/// The following fields are Snowflake-specific: <https://docs.snowflake.com/en/sql-reference/sql/alter-user#syntax>
1058110582
pub rename_to: Option<Ident>,
1058210583
pub reset_password: bool,
1058310584
pub abort_all_queries: bool,
@@ -10587,6 +10588,7 @@ pub struct AlterUser {
1058710588
pub set_default_mfa_method: Option<MfaMethodKind>,
1058810589
pub remove_mfa_method: Option<MfaMethodKind>,
1058910590
pub modify_mfa_method: Option<AlterUserModifyMfaMethod>,
10591+
pub add_mfa_method_otp: Option<AlterUserAddMfaMethodOtp>,
1059010592
pub set_policy: Option<AlterUserSetPolicy>,
1059110593
pub unset_policy: Option<UserPolicyKind>,
1059210594
pub set_tag: KeyValueOptions,
@@ -10617,6 +10619,16 @@ pub struct AlterUserRemoveRoleDelegation {
1061710619
pub integration: Ident,
1061810620
}
1061910621

10622+
/// ```sql
10623+
/// ADD MFA METHOD OTP [ COUNT = number ]
10624+
/// ```
10625+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10626+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10627+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10628+
pub struct AlterUserAddMfaMethodOtp {
10629+
pub count: Option<Value>,
10630+
}
10631+
1062010632
/// ```sql
1062110633
/// ALTER USER [ IF EXISTS ] [ <name> ] MODIFY MFA METHOD <mfa_method> SET COMMENT = '<string>'
1062210634
/// ```
@@ -10731,6 +10743,12 @@ impl fmt::Display for AlterUser {
1073110743
value::escape_single_quote_string(comment)
1073210744
)?;
1073310745
}
10746+
if let Some(add_mfa_method_otp) = &self.add_mfa_method_otp {
10747+
write!(f, " ADD MFA METHOD OTP")?;
10748+
if let Some(count) = &add_mfa_method_otp.count {
10749+
write!(f, " COUNT = {count}")?;
10750+
}
10751+
}
1073410752
if let Some(policy) = &self.set_policy {
1073510753
let policy_kind = &policy.policy_kind;
1073610754
let name = &policy.policy;

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ define_keywords!(
692692
ORDINALITY,
693693
ORGANIZATION,
694694
OTHER,
695+
OTP,
695696
OUT,
696697
OUTER,
697698
OUTPUT,

src/parser/alter.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use crate::{
2020
ast::{
2121
helpers::key_value_options::{KeyValueOptions, KeyValueOptionsDelimiter},
2222
AlterConnectorOwner, AlterPolicyOperation, AlterRoleOperation, AlterUser,
23-
AlterUserAddRoleDelegation, AlterUserModifyMfaMethod, AlterUserRemoveRoleDelegation,
24-
AlterUserSetPolicy, Expr, MfaMethodKind, Password, ResetConfig, RoleOption, SetConfigValue,
25-
Statement, UserPolicyKind,
23+
AlterUserAddMfaMethodOtp, AlterUserAddRoleDelegation, AlterUserModifyMfaMethod,
24+
AlterUserRemoveRoleDelegation, AlterUserSetPolicy, Expr, MfaMethodKind, Password,
25+
ResetConfig, RoleOption, SetConfigValue, Statement, UserPolicyKind,
2626
},
2727
dialect::{MsSqlDialect, PostgreSqlDialect},
2828
keywords::Keyword,
@@ -213,6 +213,18 @@ impl Parser<'_> {
213213
} else {
214214
None
215215
};
216+
let add_mfa_method_otp =
217+
if self.parse_keywords(&[Keyword::ADD, Keyword::MFA, Keyword::METHOD, Keyword::OTP]) {
218+
let count = if self.parse_keyword(Keyword::COUNT) {
219+
self.expect_token(&Token::Eq)?;
220+
Some(self.parse_value()?.into())
221+
} else {
222+
None
223+
};
224+
Some(AlterUserAddMfaMethodOtp { count })
225+
} else {
226+
None
227+
};
216228
let set_policy =
217229
if self.parse_keywords(&[Keyword::SET, Keyword::AUTHENTICATION, Keyword::POLICY]) {
218230
Some(AlterUserSetPolicy {
@@ -292,6 +304,7 @@ impl Parser<'_> {
292304
set_default_mfa_method,
293305
remove_mfa_method,
294306
modify_mfa_method,
307+
add_mfa_method_otp,
295308
set_policy,
296309
unset_policy,
297310
set_tag,

tests/sqlparser_common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17306,6 +17306,9 @@ fn test_parse_alter_user() {
1730617306
}
1730717307
_ => unreachable!(),
1730817308
}
17309+
verified_stmt("ALTER USER u1 ADD MFA METHOD OTP");
17310+
verified_stmt("ALTER USER u1 ADD MFA METHOD OTP COUNT = 8");
17311+
1730917312
let stmt = verified_stmt("ALTER USER u1 SET AUTHENTICATION POLICY p1");
1731017313
match stmt {
1731117314
Statement::AlterUser(alter) => {

0 commit comments

Comments
 (0)