-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Adding a Scope to the running of the rule engine (#723)
The scope will allow for users to call the engine directly will be able to add information to the condition context. Providers are still responsible for restricting based on that condition context. Working off of @jmle awesome work to get the file paths respected in providers Signed-off-by: Shawn Hurley <[email protected]>
- Loading branch information
1 parent
87e0f72
commit aa82226
Showing
10 changed files
with
261 additions
and
32 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package engine | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-logr/logr" | ||
) | ||
|
||
const TemplateContextPathScopeKey = "konveyor.io/path-scope" | ||
|
||
// Scopes apply to individual calls to the providers and will add inforamtion to the ConditionContext | ||
// To apply the scope. It is the responsiblity of the provider to use these correctly. | ||
type Scope interface { | ||
Name() string | ||
// For now this is the only place that we are considering adding a scope | ||
// in the future, we could scope other things | ||
AddToContext(*ConditionContext) error | ||
} | ||
|
||
type scopeWrapper struct { | ||
scopes []Scope | ||
} | ||
|
||
func (s *scopeWrapper) Name() string { | ||
name := "" | ||
for i, s := range s.scopes { | ||
if i == 0 { | ||
name = s.Name() | ||
|
||
} else { | ||
name = fmt.Sprintf("%s -- %s", name, s.Name()) | ||
} | ||
} | ||
return name | ||
} | ||
|
||
func (s *scopeWrapper) AddToContext(conditionCTX *ConditionContext) error { | ||
for _, s := range s.scopes { | ||
err := s.AddToContext(conditionCTX) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
var _ Scope = &scopeWrapper{} | ||
|
||
func NewScope(scopes ...Scope) Scope { | ||
return &scopeWrapper{scopes: scopes} | ||
} | ||
|
||
type includedPathScope struct { | ||
log logr.Logger | ||
paths []string | ||
} | ||
|
||
var _ Scope = &includedPathScope{} | ||
|
||
func (i *includedPathScope) Name() string { | ||
return "IncludedPathScope" | ||
} | ||
|
||
// This will only update conditionCTX if filepaths is not set. | ||
func (i *includedPathScope) AddToContext(conditionCTX *ConditionContext) error { | ||
// If any chain template has the filepaths set, only use those. | ||
for k, chainTemplate := range conditionCTX.Template { | ||
if chainTemplate.Filepaths != nil && len(chainTemplate.Filepaths) > 0 { | ||
i.log.V(5).Info("includedPathScope not used because filepath set", "filepaths", chainTemplate.Filepaths, "key", k) | ||
return nil | ||
} | ||
} | ||
|
||
// if no As clauses have filepaths, then assume we need to add the special cased filepath for scopes here | ||
conditionCTX.Template[TemplateContextPathScopeKey] = ChainTemplate{ | ||
Filepaths: i.paths, | ||
Extras: nil, | ||
} | ||
return nil | ||
|
||
} | ||
|
||
func IncludedPathsScope(paths []string, log logr.Logger) Scope { | ||
return &includedPathScope{ | ||
paths: paths, | ||
log: log, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.20 as go-builder | ||
FROM golang:1.21 as go-builder | ||
|
||
copy / /analyzer-lsp | ||
|
||
|
Oops, something went wrong.