)

var _ = Describe("sha1VerifiableBlobstore", func() {
	const (
		fixturePath = "../../../fixtures/some.config"
		fixtureSHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
	)

	var (
		innerBlobstore          *fakeblob.FakeBlobstore
		sha1VerifiableBlobstore boshblob.Blobstore
	)

	BeforeEach(func() {
		innerBlobstore = &fakeblob.FakeBlobstore{}
		sha1VerifiableBlobstore = boshblob.NewSHA1VerifiableBlobstore(innerBlobstore)
	})

	Describe("Get", func() {
		It("returns without an error if sha1 matches", func() {
			innerBlobstore.GetFileName = fixturePath

			fileName, err := sha1VerifiableBlobstore.Get("fake-blob-id", fixtureSHA1)
			Expect(err).ToNot(HaveOccurred())

			Expect(innerBlobstore.GetBlobIDs).To(Equal([]string{"fake-blob-id"}))
			Expect(fileName).To(Equal(fixturePath))
		})

		It("returns error if sha1 does not match", func() {
			innerBlobstore.GetFileName = fixturePath
Ejemplo n.º 2
0
func main() {
	logger, fs, runner, uuidGen := basicDeps()

	defer logger.HandlePanic("Main")

	flag.Parse()

	config, err := NewConfigFromPath(*configPathOpt, fs)
	if err != nil {
		logger.Error(mainLogTag, "Loading config %s", err.Error())
		os.Exit(1)
	}

	localBlobstore := boshblob.NewLocalBlobstore(
		fs,
		uuidGen,
		config.Blobstore.Options,
	)

	blobstore := boshblob.NewSHA1VerifiableBlobstore(localBlobstore)

	downloader := bpdload.NewDefaultMuxDownloader(blobstore, fs, logger)

	extractor := bptar.NewCmdExtractor(runner, fs, logger)

	compressor := bptar.NewCmdCompressor(runner, fs, logger)

	renderedArchivesCompiler := bptplcomp.NewRenderedArchivesCompiler(
		fs,
		runner,
		compressor,
		logger,
	)

	jobReaderFactory := bpreljob.NewReaderFactory(
		downloader,
		extractor,
		fs,
		logger,
	)

	err = fs.MkdirAll(config.ReposDir, os.ModeDir)
	if err != nil {
		logger.Error(mainLogTag, "Failed to create repos dir: %s", err.Error())
		os.Exit(1)
	}

	reposFactory := NewReposFactory(config.ReposDir, fs, downloader, blobstore, logger)

	blobstoreProvisioner := bpprov.NewBlobstoreProvisioner(
		fs,
		config.Blobstore,
		logger,
	)

	err = blobstoreProvisioner.Provision()
	if err != nil {
		logger.Error(mainLogTag, "Failed to provision blobstore: %s", err.Error())
		os.Exit(1)
	}

	templatesCompiler := bptplcomp.NewConcreteTemplatesCompiler(
		renderedArchivesCompiler,
		jobReaderFactory,
		reposFactory.NewJobsRepo(),
		reposFactory.NewTemplateToJobRepo(),
		reposFactory.NewRuntimePackagesRepo(),
		reposFactory.NewTemplatesRepo(),
		blobstore,
		logger,
	)

	eventLog := bpeventlog.NewLog(logger)

	packagesCompilerFactory := bppkgscomp.NewConcretePackagesCompilerFactory(
		reposFactory.NewPackagesRepo(),
		reposFactory.NewCompiledPackagesRepo(),
		blobstore,
		eventLog,
		logger,
	)

	updaterFactory := bpinstupd.NewUpdaterFactory(
		templatesCompiler,
		packagesCompilerFactory,
		eventLog,
		logger,
	)

	releaseReaderFactory := bprel.NewReaderFactory(
		downloader,
		extractor,
		fs,
		logger,
	)

	deploymentReaderFactory := bpdep.NewReaderFactory(fs, logger)

	vagrantVMProvisionerFactory := bpvagrantvm.NewVMProvisionerFactory(
		fs,
		runner,
		config.AssetsDir,
		config.Blobstore.AsMap(),
		config.VMProvisioner,
		eventLog,
		logger,
	)

	vagrantVMProvisioner := vagrantVMProvisionerFactory.NewVMProvisioner()

	releaseCompiler := bpprov.NewReleaseCompiler(
		releaseReaderFactory,
		packagesCompilerFactory,
		templatesCompiler,
		vagrantVMProvisioner,
		eventLog,
		logger,
	)

	instanceProvisioner := bpinstance.NewInstanceProvisioner(
		updaterFactory,
		logger,
	)

	singleVMProvisionerFactory := bpprov.NewSingleVMProvisionerFactory(
		deploymentReaderFactory,
		config.DeploymentProvisioner,
		vagrantVMProvisioner,
		releaseCompiler,
		instanceProvisioner,
		eventLog,
		logger,
	)

	deploymentProvisioner := singleVMProvisionerFactory.NewSingleVMProvisioner()

	err = deploymentProvisioner.Provision()
	if err != nil {
		logger.Error(mainLogTag, "Failed to provision deployment: %s", err.Error())
		os.Exit(1)
	}
}