Esempio n. 1
0
func getRegistryProvider() registry.RegistryProvider {
	if registryProvider == nil {
		rs := registry.NewInmemRegistryService()
		_, err := rs.GetByURL(*template_registry)
		if err != nil {
			r := newRegistry(*template_registry)
			if err := rs.Create(r); err != nil {
				panic(fmt.Errorf("cannot configure registry at %s: %s", r.URL, err))
			}
		}

		cp := registry.NewInmemCredentialProvider()
		if *apitoken == "" {
			*apitoken = os.Getenv("DM_GITHUB_API_TOKEN")
		}

		if *apitoken != "" {
			credential := common.RegistryCredential{
				APIToken: common.APITokenCredential(*apitoken),
			}
			if err := cp.SetCredential("default", &credential); err != nil {
				panic(fmt.Errorf("cannot set credential at %s: %s", "default", err))
			}
		}

		registryProvider = registry.NewRegistryProvider(rs, nil, cp)
	}

	return registryProvider
}
Esempio n. 2
0
func newManager(cp common.CredentialProvider) manager.Manager {
	registryProvider := registry.NewDefaultRegistryProvider(cp)
	resolver := manager.NewTypeResolver(registryProvider)
	expander := manager.NewExpander(getServiceURL(*expanderURL, *expanderName), resolver)
	deployer := manager.NewDeployer(getServiceURL(*deployerURL, *deployerName))
	r := repository.NewMapBasedRepository()
	service := registry.NewInmemRegistryService()
	credentialProvider := cp
	return manager.NewManager(expander, deployer, r, registryProvider, service, credentialProvider)
}
Esempio n. 3
0
func newManager(cp common.CredentialProvider) manager.Manager {
	service := registry.NewInmemRegistryService()
	registryProvider := registry.NewDefaultRegistryProvider(cp, service)
	resolver := manager.NewTypeResolver(registryProvider, util.DefaultHTTPClient())
	expander := manager.NewExpander(getServiceURL(*expanderURL, *expanderName, expanderPort), resolver)
	deployer := manager.NewDeployer(getServiceURL(*deployerURL, *deployerName, deployerPort))
	address := strings.TrimPrefix(getServiceURL(*mongoAddress, *mongoName, *mongoPort), "https://")
	repository := createRepository(address)
	return manager.NewManager(expander, deployer, repository, registryProvider, service, cp)
}
Esempio n. 4
0
	for t, instances := range is {
		for _, instance := range instances {
			d := instance.Deployment
			repository.TypeInstances[d] = append(repository.TypeInstances[d], t)
		}
	}

	return nil
}

func (repository *repositoryStub) Close() {}

var testExpander = &expanderStub{}
var testRepository = newRepositoryStub()
var testDeployer = newDeployerStub()
var testRegistryService = registry.NewInmemRegistryService()
var testCredentialProvider = registry.NewInmemCredentialProvider()
var testProvider = registry.NewRegistryProvider(nil, registry.NewTestGithubRegistryProvider("", nil), registry.NewTestGCSRegistryProvider("", nil), testCredentialProvider)
var testManager = NewManager(testExpander, testDeployer, testRepository, testProvider, testRegistryService, testCredentialProvider)

func TestListDeployments(t *testing.T) {
	testRepository.reset()
	d, err := testManager.ListDeployments()
	if err != nil {
		t.Fatalf(err.Error())
	}

	if !reflect.DeepEqual(d, deploymentList) {
		t.Fatalf("invalid deployment list")
	}
}