driftctl/pkg/remote/github/github_team_membership_enum...

46 lines
1.1 KiB
Go
Raw Normal View History

2021-07-02 15:37:52 +00:00
package github
import (
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/github"
)
type GithubTeamMembershipEnumerator struct {
repository GithubRepository
factory resource.ResourceFactory
}
func NewGithubTeamMembershipEnumerator(repo GithubRepository, factory resource.ResourceFactory) *GithubTeamMembershipEnumerator {
return &GithubTeamMembershipEnumerator{
repository: repo,
factory: factory,
}
}
func (g *GithubTeamMembershipEnumerator) SupportedType() resource.ResourceType {
return github.GithubTeamMembershipResourceType
}
func (g *GithubTeamMembershipEnumerator) Enumerate() ([]resource.Resource, error) {
ids, err := g.repository.ListTeamMemberships()
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, string(g.SupportedType()))
}
results := make([]resource.Resource, len(ids))
for _, id := range ids {
results = append(
results,
g.factory.CreateAbstractResource(
string(g.SupportedType()),
id,
map[string]interface{}{},
),
)
}
return results, err
}