driftctl/pkg/remote/github/init.go

69 lines
2.5 KiB
Go
Raw Normal View History

2021-02-15 13:24:20 +00:00
package github
import (
"github.com/cloudskiff/driftctl/pkg/alerter"
"github.com/cloudskiff/driftctl/pkg/output"
"github.com/cloudskiff/driftctl/pkg/remote/cache"
2021-06-11 15:10:06 +00:00
"github.com/cloudskiff/driftctl/pkg/remote/common"
2021-02-15 13:24:20 +00:00
"github.com/cloudskiff/driftctl/pkg/resource"
2021-03-26 08:44:55 +00:00
"github.com/cloudskiff/driftctl/pkg/resource/github"
2021-02-15 13:24:20 +00:00
"github.com/cloudskiff/driftctl/pkg/terraform"
)
const RemoteGithubTerraform = "github+tf"
/**
* 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,
supplierLibrary *resource.SupplierLibrary,
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 {
if version == "" {
version = "4.4.0"
}
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)
2021-06-30 18:42:02 +00:00
remoteLibrary.AddEnumerator(NewGithubTeamEnumerator(repository, factory, provider.Config))
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-02 13:55:38 +00:00
remoteLibrary.AddEnumerator(NewGithubRepositoryEnumerator(repository, factory, provider.Config))
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-05-21 14:09:45 +00:00
supplierLibrary.AddSupplier(NewGithubBranchProtectionSupplier(provider, repository, deserializer))
2021-02-15 13:24:20 +00:00
err = resourceSchemaRepository.Init(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
}