driftctl/pkg/remote/github/init.go

64 lines
2.5 KiB
Go
Raw Normal View History

2021-02-15 13:24:20 +00:00
package github
import (
2021-12-06 13:29:39 +00:00
"github.com/snyk/driftctl/pkg/alerter"
"github.com/snyk/driftctl/pkg/output"
"github.com/snyk/driftctl/pkg/remote/cache"
"github.com/snyk/driftctl/pkg/remote/common"
"github.com/snyk/driftctl/pkg/resource"
"github.com/snyk/driftctl/pkg/resource/github"
"github.com/snyk/driftctl/pkg/terraform"
2021-02-15 13:24:20 +00:00
)
/**
* Initialize remote (configure credentials, launch tf providers and start gRPC clients)
* Required to use Scanner
*/
2021-05-21 14:09:45 +00:00
func Init(version string, alerter *alerter.Alerter,
2021-05-21 14:09:45 +00:00
providerLibrary *terraform.ProviderLibrary,
2021-06-11 15:10:06 +00:00
remoteLibrary *common.RemoteLibrary,
2021-05-21 14:09:45 +00:00
progress output.Progress,
resourceSchemaRepository *resource.SchemaRepository,
factory resource.ResourceFactory,
configDir string) error {
provider, err := NewGithubTerraformProvider(version, progress, configDir)
2021-02-15 13:24:20 +00:00
if err != nil {
return err
}
err = provider.Init()
if err != nil {
return err
}
repositoryCache := cache.New(100)
repository := NewGithubRepository(provider.GetConfig(), repositoryCache)
2021-05-21 14:09:45 +00:00
deserializer := resource.NewDeserializer(factory)
2021-02-15 13:24:20 +00:00
providerLibrary.AddProvider(terraform.GITHUB, provider)
remoteLibrary.AddEnumerator(NewGithubTeamEnumerator(repository, factory))
2021-07-01 15:11:25 +00:00
remoteLibrary.AddDetailsFetcher(github.GithubTeamResourceType, common.NewGenericDetailsFetcher(github.GithubTeamResourceType, provider, deserializer))
2021-06-30 18:42:02 +00:00
remoteLibrary.AddEnumerator(NewGithubRepositoryEnumerator(repository, factory))
2021-07-02 13:55:38 +00:00
remoteLibrary.AddDetailsFetcher(github.GithubRepositoryResourceType, common.NewGenericDetailsFetcher(github.GithubRepositoryResourceType, provider, deserializer))
2021-07-02 15:50:53 +00:00
remoteLibrary.AddEnumerator(NewGithubMembershipEnumerator(repository, factory))
remoteLibrary.AddDetailsFetcher(github.GithubMembershipResourceType, common.NewGenericDetailsFetcher(github.GithubMembershipResourceType, provider, deserializer))
2021-07-02 15:37:52 +00:00
remoteLibrary.AddEnumerator(NewGithubTeamMembershipEnumerator(repository, factory))
remoteLibrary.AddDetailsFetcher(github.GithubTeamMembershipResourceType, common.NewGenericDetailsFetcher(github.GithubTeamMembershipResourceType, provider, deserializer))
2021-07-01 15:45:19 +00:00
remoteLibrary.AddEnumerator(NewGithubBranchProtectionEnumerator(repository, factory))
remoteLibrary.AddDetailsFetcher(github.GithubBranchProtectionResourceType, common.NewGenericDetailsFetcher(github.GithubBranchProtectionResourceType, provider, deserializer))
2021-02-15 13:24:20 +00:00
2021-09-30 13:32:08 +00:00
err = resourceSchemaRepository.Init(terraform.GITHUB, provider.Version(), provider.Schema())
if err != nil {
return err
}
github.InitResourcesMetadata(resourceSchemaRepository)
2021-03-26 08:44:55 +00:00
2021-02-15 13:24:20 +00:00
return nil
}