driftctl/pkg/remote/github/github_repository_enumerato...

46 lines
1.1 KiB
Go
Raw Normal View History

2021-07-02 13:55:38 +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 GithubRepositoryEnumerator struct {
repository GithubRepository
factory resource.ResourceFactory
2021-07-02 13:55:38 +00:00
}
func NewGithubRepositoryEnumerator(repo GithubRepository, factory resource.ResourceFactory) *GithubRepositoryEnumerator {
2021-07-02 13:55:38 +00:00
return &GithubRepositoryEnumerator{
repository: repo,
factory: factory,
2021-07-02 13:55:38 +00:00
}
}
func (g *GithubRepositoryEnumerator) SupportedType() resource.ResourceType {
return github.GithubRepositoryResourceType
}
2021-08-09 14:03:04 +00:00
func (g *GithubRepositoryEnumerator) Enumerate() ([]*resource.Resource, error) {
2021-07-02 13:55:38 +00:00
ids, err := g.repository.ListRepositories()
if err != nil {
2021-08-03 10:34:36 +00:00
return nil, remoteerror.NewResourceListingError(err, string(g.SupportedType()))
2021-07-02 13:55:38 +00:00
}
2021-10-27 09:30:47 +00:00
results := make([]*resource.Resource, 0, len(ids))
2021-07-02 13:55:38 +00:00
for _, id := range ids {
results = append(
results,
g.factory.CreateAbstractResource(
string(g.SupportedType()),
id,
map[string]interface{}{},
),
)
}
return results, err
}