feat: [CDE-192]: added a new factory method for infraproviders. (#2431)

* feat: [CDE-192]: added a new factory method for infraproviders.
* feat: [CDE-192]: added a new factory method for infraproviders.
pull/3545/head
Ansuman Satapathy 2024-08-08 12:39:09 +00:00 committed by Harness
parent 1748e57189
commit 3d4cbb95ec
1 changed files with 7 additions and 3 deletions

View File

@ -20,17 +20,21 @@ import (
"github.com/harness/gitness/types/enum"
)
type Factory struct {
type Factory interface {
GetInfraProvider(providerType enum.InfraProviderType) (InfraProvider, error)
}
type factory struct {
providers map[enum.InfraProviderType]InfraProvider
}
func NewFactory(dockerProvider *DockerProvider) Factory {
providers := make(map[enum.InfraProviderType]InfraProvider)
providers[enum.InfraProviderTypeDocker] = dockerProvider
return Factory{providers: providers}
return &factory{providers: providers}
}
func (f *Factory) GetInfraProvider(providerType enum.InfraProviderType) (InfraProvider, error) {
func (f *factory) GetInfraProvider(providerType enum.InfraProviderType) (InfraProvider, error) {
val := f.providers[providerType]
if val == nil {
return nil, fmt.Errorf("unknown infra provider type: %s", providerType)