2021-02-15 13:24:20 +00:00
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/alerter"
|
2021-03-15 17:30:18 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/output"
|
2021-06-04 14:10:00 +00:00
|
|
|
"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
|
|
|
|
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,
|
|
|
|
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,
|
2021-06-14 16:25:35 +00:00
|
|
|
factory resource.ResourceFactory,
|
|
|
|
configDir string) error {
|
2021-06-09 15:28:40 +00:00
|
|
|
if version == "" {
|
|
|
|
version = "4.4.0"
|
|
|
|
}
|
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-06-09 15:28:40 +00:00
|
|
|
err = resourceSchemaRepository.Init(version, provider.Schema())
|
|
|
|
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
|
|
|
|
}
|