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

Change the Provider's FetchProperty/FetchAllProperties interface methods to look up by Properties, not just a name #4266

Merged
merged 1 commit into from
Aug 26, 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
4 changes: 2 additions & 2 deletions internal/providers/dockerhub/dockerhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ func (d *dockerHubImageLister) ListImages(ctx context.Context) ([]string, error)
// FetchAllProperties implements the provider interface
// TODO: Implement this
func (_ *dockerHubImageLister) FetchAllProperties(
_ context.Context, _ string, _ minderv1.Entity) (*properties.Properties, error) {
_ context.Context, _ *properties.Properties, _ minderv1.Entity) (*properties.Properties, error) {
return nil, nil
}

// FetchProperty implements the provider interface
// TODO: Implement this
func (_ *dockerHubImageLister) FetchProperty(
_ context.Context, _ string, _ minderv1.Entity, _ string) (*properties.Property, error) {
_ context.Context, _ *properties.Properties, _ minderv1.Entity, _ string) (*properties.Property, error) {
return nil, nil
}

Expand Down
6 changes: 4 additions & 2 deletions internal/providers/github/ghcr/ghcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ func (g *ImageLister) ListImages(ctx context.Context) ([]string, error) {

// FetchAllProperties implements the provider interface
// TODO: Implement this
func (_ *ImageLister) FetchAllProperties(_ context.Context, _ string, _ minderv1.Entity) (*properties.Properties, error) {
func (_ *ImageLister) FetchAllProperties(
_ context.Context, _ *properties.Properties, _ minderv1.Entity) (*properties.Properties, error) {
return nil, nil
}

// FetchProperty implements the provider interface
// TODO: Implement this
func (_ *ImageLister) FetchProperty(_ context.Context, _ string, _ minderv1.Entity, _ string) (*properties.Property, error) {
func (_ *ImageLister) FetchProperty(
_ context.Context, _ *properties.Properties, _ minderv1.Entity, _ string) (*properties.Property, error) {
return nil, nil
}

Expand Down
112 changes: 56 additions & 56 deletions internal/providers/github/mock/github.go

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions internal/providers/github/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,17 @@ func getRepoWrapper(ctx context.Context, ghCli *GitHub, name string) (map[string

// FetchProperty fetches a single property for the given entity
func (c *GitHub) FetchProperty(
ctx context.Context, name string, entType minderv1.Entity, key string,
ctx context.Context, getByProps *properties.Properties, entType minderv1.Entity, key string,
) (*properties.Property, error) {
pf := newPropertyFetcher(c, entType)

// TODO: right now github only supports fetching by name, but we could add support for more
// properties to e.g. get-repo-by-id if the upstream REST API supports that
name, err := getByProps.GetProperty(properties.PropertyName).AsString()
if err != nil {
return nil, err
}

for _, po := range pf.propertyOrigins {
for _, k := range po.keys {
if k == key {
Expand All @@ -163,12 +170,19 @@ func (c *GitHub) FetchProperty(

// FetchAllProperties fetches all properties for the given entity
func (c *GitHub) FetchAllProperties(
ctx context.Context, name string, entType minderv1.Entity,
ctx context.Context, getByProps *properties.Properties, entType minderv1.Entity,
) (*properties.Properties, error) {
pf := newPropertyFetcher(c, entType)

result := make(map[string]any)

// TODO: right now github only supports fetching by name, but we could add support for more
// properties to e.g. get-repo-by-id if the upstream REST API supports that
name, err := getByProps.GetProperty(properties.PropertyName).AsString()
if err != nil {
return nil, err
}

for _, po := range pf.propertyOrigins {
props, err := po.wrapper(ctx, pf.ghCli, name)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions internal/providers/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ func (c *gitlabClient) GetCredential() provifv1.GitLabCredential {

// FetchAllProperties implements the provider interface
// TODO: Implement this
func (_ *gitlabClient) FetchAllProperties(_ context.Context, _ string, _ minderv1.Entity) (*properties.Properties, error) {
func (_ *gitlabClient) FetchAllProperties(
_ context.Context, _ *properties.Properties, _ minderv1.Entity) (*properties.Properties, error) {
return nil, nil
}

// FetchProperty implements the provider interface
// TODO: Implement this
func (_ *gitlabClient) FetchProperty(_ context.Context, _ string, _ minderv1.Entity, _ string) (*properties.Property, error) {
func (_ *gitlabClient) FetchProperty(
_ context.Context, _ *properties.Properties, _ minderv1.Entity, _ string) (*properties.Property, error) {
return nil, nil
}

Expand Down
48 changes: 24 additions & 24 deletions internal/providers/selectors/mock/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/providers/selectors/selector_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ func (m *fullProvider) PullRequestToSelectorEntity(_ context.Context, pr *minder
return pullRequestToSelectorEntity(m.t, m.name, m.class, pr)
}

func (_ *fullProvider) FetchAllProperties(_ context.Context, _ string, _ minderv1.Entity) (*properties.Properties, error) {
func (_ *fullProvider) FetchAllProperties(_ context.Context, _ *properties.Properties, _ minderv1.Entity) (*properties.Properties, error) {
return nil, nil
}

func (_ *fullProvider) FetchProperty(_ context.Context, _ string, _ minderv1.Entity, _ string) (*properties.Property, error) {
func (_ *fullProvider) FetchProperty(_ context.Context, _ *properties.Properties, _ minderv1.Entity, _ string) (*properties.Property, error) {
return nil, nil
}

Expand Down Expand Up @@ -158,11 +158,11 @@ func (_ *repoOnlyProvider) CanImplement(_ minderv1.ProviderType) bool {
return true
}

func (_ *repoOnlyProvider) FetchAllProperties(_ context.Context, _ string, _ minderv1.Entity) (*properties.Properties, error) {
func (_ *repoOnlyProvider) FetchAllProperties(_ context.Context, _ *properties.Properties, _ minderv1.Entity) (*properties.Properties, error) {
return nil, nil
}

func (_ *repoOnlyProvider) FetchProperty(_ context.Context, _ string, _ minderv1.Entity, _ string) (*properties.Property, error) {
func (_ *repoOnlyProvider) FetchProperty(_ context.Context, _ *properties.Properties, _ minderv1.Entity, _ string) (*properties.Property, error) {
return nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/providers/testproviders/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func (_ *GitProvider) CanImplement(trait minderv1.ProviderType) bool {

// FetchAllProperties implements the Provider interface
func (_ *GitProvider) FetchAllProperties(
_ context.Context, _ string, _ minderv1.Entity) (*properties.Properties, error) {
_ context.Context, _ *properties.Properties, _ minderv1.Entity) (*properties.Properties, error) {
return nil, nil
}

// FetchProperty implements the Provider interface
func (_ *GitProvider) FetchProperty(
_ context.Context, _ string, _ minderv1.Entity, _ string) (*properties.Property, error) {
_ context.Context, _ *properties.Properties, _ minderv1.Entity, _ string) (*properties.Property, error) {
return nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/providers/testproviders/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func (_ *RESTProvider) CanImplement(trait minderv1.ProviderType) bool {

// FetchAllProperties implements the Provider interface
func (_ *RESTProvider) FetchAllProperties(
_ context.Context, _ string, _ minderv1.Entity) (*properties.Properties, error) {
_ context.Context, _ *properties.Properties, _ minderv1.Entity) (*properties.Properties, error) {
return nil, nil
}

// FetchProperty implements the Provider interface
func (_ *RESTProvider) FetchProperty(
_ context.Context, _ string, _ minderv1.Entity, _ string) (*properties.Property, error) {
_ context.Context, _ *properties.Properties, _ minderv1.Entity, _ string) (*properties.Property, error) {
return nil, nil
}

Expand Down
9 changes: 8 additions & 1 deletion internal/repositories/github/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ func (r *repositoryService) CreateRepository(
return nil, fmt.Errorf("error instantiating properties client: %w", err)
}

fetchByProps, err := properties.NewProperties(map[string]any{
properties.PropertyName: fmt.Sprintf("%s/%s", repoOwner, repoName),
})
if err != nil {
return nil, fmt.Errorf("error creating properties: %w", err)
}

repoProperties, err := propClient.FetchAllProperties(
ctx,
fmt.Sprintf("%s/%s", repoOwner, repoName),
fetchByProps,
pb.Entity_ENTITY_REPOSITORIES)
if err != nil {
return nil, fmt.Errorf("error fetching properties for repository: %w", err)
Expand Down
6 changes: 4 additions & 2 deletions pkg/providers/v1/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ type Provider interface {
CanImplement(trait minderv1.ProviderType) bool

// FetchAllProperties fetches all properties for the given entity
FetchAllProperties(ctx context.Context, name string, entType minderv1.Entity) (*properties.Properties, error)
FetchAllProperties(
ctx context.Context, getByProps *properties.Properties, entType minderv1.Entity) (*properties.Properties, error)
// FetchProperty fetches a single property for the given entity
FetchProperty(ctx context.Context, name string, entType minderv1.Entity, key string) (*properties.Property, error)
FetchProperty(
ctx context.Context, getByProps *properties.Properties, entType minderv1.Entity, key string) (*properties.Property, error)
// GetEntityName forms an entity name from the given properties
// The name is used to identify the entity within minder and is how
// it will be stored in the database.
Expand Down
Loading