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
|
|
|
|
2021-06-03 09:43:15 +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,
|
2021-06-14 16:25:35 +00:00
|
|
|
factory resource.ResourceFactory,
|
|
|
|
configDir string) error {
|
2021-06-12 14:17:23 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-06-04 14:10:00 +00:00
|
|
|
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)
|
|
|
|
|
2021-07-05 13:33:42 +00:00
|
|
|
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
|
|
|
|
2021-07-05 13:33:42 +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())
|
2021-06-09 15:28:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-05-07 15:57:31 +00:00
|
|
|
github.InitResourcesMetadata(resourceSchemaRepository)
|
2021-03-26 08:44:55 +00:00
|
|
|
|
2021-02-15 13:24:20 +00:00
|
|
|
return nil
|
|
|
|
}
|