Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Add prompt and warning functions to the command compound #1464

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions pkg/jms-sdk-go/model/filter_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,22 @@ type CommandFilterItem struct {
type CommandAction string

const (
ActionReject = "reject"
ActionAccept = "accept"
ActionReview = "review"
ActionWarning = "warning"
ActionUnknown = "Unknown"
ActionReject = "reject"
ActionAccept = "accept"
ActionReview = "review"
ActionWarning = "warning"
ActionNotifyAndWarn = "notify_and_warn"
ActionUnknown = "Unknown"
)

var (
actionPriorityMap = map[CommandAction]int{
ActionReject: 0,
ActionReview: 1,
ActionWarning: 2,
ActionAccept: 3,
ActionUnknown: 4,
ActionReject: 0,
ActionReview: 1,
ActionNotifyAndWarn: 2,
ActionWarning: 3,
ActionAccept: 4,
ActionUnknown: 5,
}
)

Expand Down
40 changes: 35 additions & 5 deletions pkg/proxy/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,24 @@ func (p *Parser) parseInputState(b []byte) []byte {
p.confirmStatus.Status)
return nil
}
waitMsg := lang.T("the reviewers will confirm. continue or not [Y/n]")

WarnWaitMsg := lang.T("Need to send command alert, do you want to continue [Y/N]")
if p.confirmStatus.InQuery() && p.getCurrentCmdStatusLevel() == model.WarningLevel {
switch strings.ToLower(string(b)) {
case "y":
p.confirmStatus.SetStatus(StatusNone)
p.userOutputChan <- []byte("\n")
case "n":
p.confirmStatus.SetStatus(StatusNone)
p.srvOutputChan <- []byte("\r\n")
return p.breakInputPacket()
default:
p.srvOutputChan <- []byte("\r\n" + WarnWaitMsg)
}
return nil
}

confirmWaitMsg := lang.T("the reviewers will confirm. continue or not [Y/n]")
if p.confirmStatus.InQuery() {
switch strings.ToLower(string(b)) {
case "y":
Expand Down Expand Up @@ -305,7 +322,7 @@ func (p *Parser) parseInputState(b []byte) []byte {
p.srvOutputChan <- []byte("\r\n")
return p.breakInputPacket()
default:
p.srvOutputChan <- []byte("\r\n" + waitMsg)
p.srvOutputChan <- []byte("\r\n" + confirmWaitMsg)
}
return nil
}
Expand Down Expand Up @@ -334,12 +351,19 @@ func (p *Parser) parseInputState(b []byte) []byte {
p.confirmStatus.SetCmd(p.command)
p.confirmStatus.SetData(string(b))
p.confirmStatus.ResetCtx()
p.srvOutputChan <- []byte("\r\n" + waitMsg)
p.srvOutputChan <- []byte("\r\n" + confirmWaitMsg)
return nil
case model.ActionWarning:
p.setCurrentCmdFilterRule(rule)
p.setCurrentCmdStatusLevel(model.WarningLevel)
logger.Debugf("Session %s: command %s match warning rule", p.id, p.command)
case model.ActionNotifyAndWarn:
p.confirmStatus.SetStatus(StatusQuery)
p.setCurrentCmdFilterRule(rule)
p.setCurrentCmdStatusLevel(model.WarningLevel)
logger.Debugf("Session %s: command %s match notify and warn rule", p.id, p.command)
p.srvOutputChan <- []byte("\r\n" + WarnWaitMsg)
return nil
default:
}
}
Expand All @@ -364,11 +388,17 @@ func (p *Parser) parseInputState(b []byte) []byte {
p.confirmStatus.SetCmd(p.command)
p.confirmStatus.SetData(string(b))
p.confirmStatus.ResetCtx()
p.srvOutputChan <- []byte("\r\n" + waitMsg)
p.srvOutputChan <- []byte("\r\n" + confirmWaitMsg)
return nil
case model.ActionWarning:
p.setCurrentCmdFilterRule(rule)
p.setCurrentCmdStatusLevel(model.WarningLevel)
case model.ActionNotifyAndWarn:
p.confirmStatus.SetStatus(StatusQuery)
p.setCurrentCmdFilterRule(rule)
p.setCurrentCmdStatusLevel(model.WarningLevel)
p.srvOutputChan <- []byte("\r\n" + WarnWaitMsg)
return nil
default:
}
}
Expand Down Expand Up @@ -536,7 +566,7 @@ func (p *Parser) IsMatchCommandRule(command string) (CommandRule,
rule := p.cmdFilterACLs[i]
item, allowed, cmd := rule.Match(command)
switch allowed {
case model.ActionAccept, model.ActionWarning:
case model.ActionAccept, model.ActionWarning, model.ActionNotifyAndWarn:
return CommandRule{Acl: &rule, Item: &item}, cmd, true
case model.ActionReview, model.ActionReject:
return CommandRule{Acl: &rule, Item: &item}, cmd, true
Expand Down
Loading