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 {
|
2021-07-05 13:33:42 +00:00
|
|
|
repository GithubRepository
|
|
|
|
factory resource.ResourceFactory
|
2021-07-02 13:55:38 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 13:33:42 +00:00
|
|
|
func NewGithubRepositoryEnumerator(repo GithubRepository, factory resource.ResourceFactory) *GithubRepositoryEnumerator {
|
2021-07-02 13:55:38 +00:00
|
|
|
return &GithubRepositoryEnumerator{
|
2021-07-05 13:33:42 +00:00
|
|
|
repository: repo,
|
|
|
|
factory: factory,
|
2021-07-02 13:55:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GithubRepositoryEnumerator) SupportedType() resource.ResourceType {
|
|
|
|
return github.GithubRepositoryResourceType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GithubRepositoryEnumerator) Enumerate() ([]resource.Resource, error) {
|
|
|
|
ids, err := g.repository.ListRepositories()
|
|
|
|
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
|
|
|
|
}
|