-
Notifications
You must be signed in to change notification settings - Fork 43
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 CanImplement
method for providers
#3115
Changes from all commits
3243da5
297c995
bc03b54
51d7d67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2024 Stacklok, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package db | ||
|
||
import ( | ||
"slices" | ||
"strings" | ||
|
||
"github.com/sqlc-dev/pqtype" | ||
) | ||
|
||
// This file contains domain-level methods for db structs | ||
|
||
// CanImplement returns true if the provider implements the given type. | ||
func (p *Provider) CanImplement(impl ProviderType) bool { | ||
return slices.Contains(p.Implements, impl) | ||
} | ||
|
||
// ProfileRow is an interface row in the profiles table | ||
type ProfileRow interface { | ||
GetProfile() Profile | ||
GetEntityProfile() NullEntities | ||
GetContextualRules() pqtype.NullRawMessage | ||
} | ||
|
||
// GetProfile returns the profile | ||
func (r ListProfilesByProjectIDAndLabelRow) GetProfile() Profile { | ||
return r.Profile | ||
} | ||
|
||
// GetEntityProfile returns the entity profile | ||
func (r ListProfilesByProjectIDAndLabelRow) GetEntityProfile() NullEntities { | ||
return r.ProfilesWithEntityProfile.Entity | ||
} | ||
|
||
// GetContextualRules returns the contextual rules | ||
func (r ListProfilesByProjectIDAndLabelRow) GetContextualRules() pqtype.NullRawMessage { | ||
return r.ProfilesWithEntityProfile.ContextualRules | ||
} | ||
|
||
// GetProfile returns the profile | ||
func (r ListProfilesByProjectIDRow) GetProfile() Profile { | ||
return r.Profile | ||
} | ||
|
||
// GetEntityProfile returns the entity profile | ||
func (r ListProfilesByProjectIDRow) GetEntityProfile() NullEntities { | ||
return r.ProfilesWithEntityProfile.Entity | ||
} | ||
|
||
// GetContextualRules returns the contextual rules | ||
func (r ListProfilesByProjectIDRow) GetContextualRules() pqtype.NullRawMessage { | ||
return r.ProfilesWithEntityProfile.ContextualRules | ||
} | ||
|
||
// LabelsFromFilter parses the filter string and populates the IncludeLabels and ExcludeLabels fields | ||
func (lp *ListProfilesByProjectIDAndLabelParams) LabelsFromFilter(filter string) { | ||
// otherwise Split would have returned a slice with one empty string | ||
if filter == "" { | ||
return | ||
} | ||
|
||
for _, label := range strings.Split(filter, ",") { | ||
switch { | ||
case label == "*": | ||
lp.IncludeLabels = append(lp.IncludeLabels, label) | ||
case strings.HasPrefix(label, "!"): | ||
// if the label starts with a "!", it is a negative filter, add it to the negative list | ||
lp.ExcludeLabels = append(lp.ExcludeLabels, label[1:]) | ||
default: | ||
lp.IncludeLabels = append(lp.IncludeLabels, label) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,7 +128,7 @@ func NewProviderBuilder( | |
|
||
// Implements returns true if the provider implements the given type. | ||
func (pb *ProviderBuilder) Implements(impl db.ProviderType) bool { | ||
return slices.Contains(pb.p.Implements, impl) | ||
return pb.p.CanImplement(impl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have decided to leave this method for now. When my |
||
} | ||
|
||
// GetName returns the name of the provider instance as defined in the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved across from
store.go
- I think it's best to separate out these domain-level methods and data types