Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[QD-597] Impl MySql Statements & QsiSensitiveData
- Loading branch information
Showing
39 changed files
with
930 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Qsi.Analyzers; | ||
using Qsi.Analyzers.Action; | ||
using Qsi.Analyzers.Context; | ||
using Qsi.Data; | ||
using Qsi.Engines; | ||
using Qsi.Extensions; | ||
using Qsi.MySql.Tree; | ||
using Qsi.Tree; | ||
|
||
namespace Qsi.MySql.Analyzers; | ||
|
||
public class MySqlActionAnalyzer : QsiActionAnalyzer | ||
{ | ||
public MySqlActionAnalyzer(QsiEngine engine) : base(engine) | ||
{ | ||
} | ||
|
||
protected override async ValueTask<IQsiAnalysisResult[]> ExecuteDataUpdateAction(IAnalyzerContext context, IQsiDataUpdateActionNode action) | ||
{ | ||
IQsiAnalysisResult[] result = await base.ExecuteDataUpdateAction(context, action); | ||
|
||
if (result.FirstOrDefault() is { } firstResult && | ||
action.Target is IQsiDerivedTableNode { Where: { } whereExpr }) | ||
{ | ||
IEnumerable<IQsiExpressionNode> nodes = action.SetValues | ||
.Select(values => values.Value) | ||
.Append(whereExpr.Expression); | ||
|
||
AddSensitiveData(firstResult.SensitiveDataCollection, nodes); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected override async ValueTask<IQsiAnalysisResult[]> ExecuteDataDeleteAction(IAnalyzerContext context, IQsiDataDeleteActionNode action) | ||
{ | ||
IQsiAnalysisResult[] result = await base.ExecuteDataDeleteAction(context, action); | ||
|
||
if (result.FirstOrDefault() is { } firstResult && | ||
action.Target is IQsiDerivedTableNode { Where: { } whereExpr }) | ||
{ | ||
AddSensitiveData(firstResult.SensitiveDataCollection, whereExpr.Expression); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected override QsiVariableSetActionResult ResolveVariableSet(IAnalyzerContext context, IQsiVariableSetItemNode node) | ||
{ | ||
var result = base.ResolveVariableSet(context, node); | ||
|
||
if (result.Name.Value is "PASSWORD") | ||
result.SensitiveDataCollection.Add(CreateSensitiveData(QsiSensitiveDataType.Password, node.Expression)); | ||
|
||
return result; | ||
} | ||
|
||
protected override QsiUserInfo ResolveUser(IAnalyzerContext context, IQsiUserNode node, QsiSensitiveDataCollection dataCollection) | ||
{ | ||
var result = base.ResolveUser(context, node, dataCollection); | ||
|
||
if (node.Password is { }) | ||
dataCollection.Add(CreateSensitiveData(QsiSensitiveDataType.Password, node.Password)); | ||
|
||
return result; | ||
} | ||
|
||
private void AddSensitiveData(QsiSensitiveDataCollection collection, IEnumerable<IQsiExpressionNode> nodes) | ||
{ | ||
AddSensitiveData(collection, nodes.ToArray()); | ||
} | ||
|
||
private void AddSensitiveData(QsiSensitiveDataCollection collection, params IQsiExpressionNode[] nodes) | ||
{ | ||
IEnumerable<QsiSensitiveData> sensitiveDatas = nodes | ||
.SelectMany(n => n.Flatten()) | ||
.Select(e => (e, MySqlTree.SensitiveType[e])) | ||
.Where(e => e.Item2 is not QsiSensitiveDataType.None) | ||
.Select(e => CreateSensitiveData(e.Item2, e.e)); | ||
|
||
collection.AddRange(sensitiveDatas); | ||
} | ||
|
||
protected override QsiSensitiveData CreateSensitiveData(QsiSensitiveDataType dataType, IQsiTreeNode node) | ||
{ | ||
return new QsiSensitiveData(dataType, MySqlTree.Span[node]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.