Example #1
0
func NewFactory(options FactoryOptions, repos FactoryRepos, logger boshlog.Logger) Factory {
	if !options.Enabled {
		return Factory{Importer: NewNoopImporter(logger)}
	}

	buckets := []bhs3.Bucket{}

	for _, bucketOpts := range options.Buckets {
		bucket := bhs3.NewPlainBucket(bucketOpts.URL, logger)

		if len(bucketOpts.CDNURL) > 0 {
			urlFactory := bhs3.NewDirectURLFactory(bucketOpts.CDNURL)
			bucket = bhs3.NewCDNBucket(urlFactory, bucket)
		}

		buckets = append(buckets, bucket)
	}

	periodicImporter := NewPeriodicS3BucketImporter(
		options.Period,
		make(chan struct{}),
		buckets,
		repos.S3BoshInitBinsRepo(),
		logger,
	)

	return Factory{Importer: periodicImporter}
}
Example #2
0
func NewRepos(options ReposOptions, fs boshsys.FileSystem, logger boshlog.Logger) (Repos, error) {
	var i repoIndicies

	var err error

	switch {
	case options.Type == "file":
		i = newFileRepoIndicies(options.Dir, fs)
	case options.Type == "db":
		i, err = newDBRepoIndicies(options.ConnURL, logger)
	default:
		err = bosherr.New("Expected repos type '%s'", options.Type)
	}
	if err != nil {
		return Repos{}, err
	}

	predefinedAvatars := options.PredefinedAvatars
	if predefinedAvatars == nil {
		predefinedAvatars = map[string]string{}
	}

	linkerOpts := options.ReleaseTarballLinker

	var linkerFactory bhs3.URLFactory

	switch {
	case linkerOpts.Type == "CloudFront":
		linkerFactory, err = bhs3.NewCDNURLFactory(linkerOpts.BaseURL, linkerOpts.KeyPairID, linkerOpts.PrivateKey)
	case linkerOpts.Type == "S3":
		linkerFactory = bhs3.NewDirectURLFactory(linkerOpts.BaseURL)
	default:
		err = bosherr.New("Expected linker type '%s'", linkerOpts.Type)
	}
	if err != nil {
		return Repos{}, err
	}

	releaseNotesRepo := bhnotesrepo.NewConcreteNotesRepository(i.releaseNotesIndex, logger)
	releaseTarsRepo := bhreltarsrepo.NewConcreteReleaseTarballsRepository(i.releaseTarsIndex, linkerFactory, logger)

	releasesRepo := bhrelsrepo.NewConcreteReleasesRepository(
		options.PredefinedReleaseSources,
		predefinedAvatars,
		i.releasesIndex,
		releaseNotesRepo,
		releaseTarsRepo,
		logger,
	)

	repos := Repos{
		releasesRepo: releasesRepo,

		releaseVersionsRepo: bhrelsrepo.NewConcreteReleaseVersionsRepository(i.releaseVersionsIndex, logger),
		jobsRepo:            bhjobsrepo.NewConcreteJobsRepository(i.jobsIndex, logger),

		s3StemcellsRepo:    bhstemsrepo.NewS3StemcellsRepository(i.s3StemcellsIndex, logger),
		s3BoshInitBinsRepo: bhbibrepo.NewS3Repository(i.s3BoshInitBinsIndex, logger),

		importsRepo:    bhimpsrepo.NewConcreteImportsRepository(i.importsIndex, logger),
		importErrsRepo: bhimperrsrepo.NewConcreteImportErrsRepository(i.importErrsIndex, logger),
		watchersRepo:   bhwatchersrepo.NewConcreteWatchersRepository(i.watchersIndex, logger),
	}

	return repos, nil
}