driftctl/pkg/remote/github/init.go

52 lines
1.7 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-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,
progress output.Progress,
resourceSchemaRepository *resource.SchemaRepository,
factory resource.ResourceFactory) error {
provider, err := NewGithubTerraformProvider(version, progress)
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-05-21 14:09:45 +00:00
supplierLibrary.AddSupplier(NewGithubRepositorySupplier(provider, repository, deserializer))
supplierLibrary.AddSupplier(NewGithubTeamSupplier(provider, repository, deserializer))
supplierLibrary.AddSupplier(NewGithubMembershipSupplier(provider, repository, deserializer))
supplierLibrary.AddSupplier(NewGithubTeamMembershipSupplier(provider, repository, deserializer))
supplierLibrary.AddSupplier(NewGithubBranchProtectionSupplier(provider, repository, deserializer))
2021-02-15 13:24:20 +00:00
2021-03-26 08:44:55 +00:00
resourceSchemaRepository.Init(provider.Schema())
github.InitResourcesMetadata(resourceSchemaRepository)
2021-03-26 08:44:55 +00:00
2021-02-15 13:24:20 +00:00
return nil
}