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

Implement getParameter method for SQLite #2985

Merged
merged 16 commits into from
Jul 11, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
chilagrow committed Jul 6, 2023
commit 4c35b3f0f9b217c2f73f6d1c74cee6de71b2065c
56 changes: 27 additions & 29 deletions internal/handlers/common/getparameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ func MsgGetParameter(_ context.Context, msg *wire.OpMsg, l *zap.Logger) (*wire.O
return nil, lazyerrors.Error(err)
}

showDetails, allParameters, err := extractParam(document)
showDetails, allParameters, err := extractGetParameter(document)
if err != nil {
return nil, lazyerrors.Error(err)
}

Ignored(document, l, "comment")

resDB := must.NotFail(types.NewDocument(
// parameters are alphabetical order
parameters := must.NotFail(types.NewDocument(
// to add a new parameter, fill template and place it in the alphabetical order position
//"<name>", must.NotFail(types.NewDocument(
// "value", <value>,
// "settableAtRuntime", <bool>,
// "settableAtStartup", <bool>,
//)),
"authenticationMechanisms", must.NotFail(types.NewDocument(
"value", must.NotFail(types.NewArray("PLAIN")),
"settableAtRuntime", false,
Expand All @@ -65,20 +70,12 @@ func MsgGetParameter(_ context.Context, msg *wire.OpMsg, l *zap.Logger) (*wire.O
"settableAtRuntime", true,
"settableAtStartup", true,
)),
// to add a new parameter, fill template and place it in the alphabetical order position
//"<name>", must.NotFail(types.NewDocument(
// "value", <value>,
// "settableAtRuntime", <bool>,
// "settableAtStartup", <bool>,
//)),
// parameters are alphabetically ordered
))

resDoc := resDB
if !showDetails || !allParameters {
resDoc, err = selectUnit(document, resDB, showDetails, allParameters)
if err != nil {
return nil, lazyerrors.Error(err)
}
resDoc, err := selectParameters(document, parameters, showDetails, allParameters)
if err != nil {
return nil, lazyerrors.Error(err)
}

if resDoc.Len() < 1 {
Expand All @@ -99,11 +96,11 @@ func MsgGetParameter(_ context.Context, msg *wire.OpMsg, l *zap.Logger) (*wire.O
return &reply, nil
}

// selectUnit is makes a selection of requested parameters.
func selectUnit(document, resDB *types.Document, showDetails, allParameters bool) (resDoc *types.Document, err error) {
// selectParameters makes a selection of requested parameters.
func selectParameters(document, parameters *types.Document, showDetails, allParameters bool) (resDoc *types.Document, err error) {
resDoc = must.NotFail(types.NewDocument())

iter := resDB.Iterator()
iter := parameters.Iterator()
defer iter.Close()

for {
Expand All @@ -130,32 +127,33 @@ func selectUnit(document, resDB *types.Document, showDetails, allParameters bool
return resDoc, nil
}

// extractParam is getting parameters showDetails & allParameters from the request.
func extractParam(document *types.Document) (showDetails, allParameters bool, err error) {
getPrm, err := document.Get("getParameter")
if err != nil {
// extractGetParameter retrieves showDetails & allParameters options set on the getParameter value of the document.
func extractGetParameter(document *types.Document) (showDetails, allParameters bool, err error) {
v, _ := document.Get("getParameter")
if v == nil {
return false, false, lazyerrors.Error(err)
}

if param, ok := getPrm.(*types.Document); ok {
if v, _ := param.Get("showDetails"); v != nil {
if v == "*" {
allParameters = true
return
}

if param, ok := v.(*types.Document); ok {
if v, _ = param.Get("showDetails"); v != nil {
showDetails, err = commonparams.GetBoolOptionalParam("showDetails", v)
if err != nil {
return false, false, lazyerrors.Error(err)
}
}

if v, _ := param.Get("allParameters"); v != nil {
if v, _ = param.Get("allParameters"); v != nil {
allParameters, err = commonparams.GetBoolOptionalParam("allParameters", v)
if err != nil {
return false, false, lazyerrors.Error(err)
}
}
}

if getPrm == "*" {
allParameters = true
}

return showDetails, allParameters, nil
}