func (f *factory) SetConfig(config davconf.Config) { client := davclient.NewClient(config, http.DefaultClient) f.cmds = map[string]Cmd{ "put": newPutCmd(client), "get": newGetCmd(client), } }
func NewBlobstore(uri string) BlobClient { config := davconfig.Config{Endpoint: uri} client := davclient.NewClient(config, http.DefaultClient) return BlobClient{ dav: client, uuidGenerator: uuid.NewGenerator(), } }
//TODO: rename NewBlobstore func (f blobstoreFactory) Create(blobstoreURL string, httpClient *http.Client) (Blobstore, error) { logger := boshlog.NewLogger(boshlog.LevelNone) blobstoreConfig, err := f.parseBlobstoreURL(blobstoreURL) if err != nil { return nil, bosherr.WrapError(err, "Creating blobstore config") } davClient := boshdavcli.NewClient(boshdavcliconf.Config{ Endpoint: fmt.Sprintf("%s/blobs", blobstoreConfig.Endpoint), User: blobstoreConfig.Username, Password: blobstoreConfig.Password, }, httpClient, logger) return NewBlobstore(davClient, f.uuidGenerator, f.fs, f.logger), nil }
fakeUUIDGenerator = fakeuuid.NewFakeGenerator() fs = fakesys.NewFakeFileSystem() logger = boshlog.NewLogger(boshlog.LevelNone) httpClient = bihttpclient.DefaultClient blobstoreFactory = NewBlobstoreFactory(fakeUUIDGenerator, fs, logger) }) Describe("Create", func() { Context("when username and password are provided", func() { It("returns the blobstore", func() { blobstore, err := blobstoreFactory.Create("https://*****:*****@fake-host:1234", httpClient) Expect(err).ToNot(HaveOccurred()) davClient := boshdavcli.NewClient(boshdavcliconf.Config{ Endpoint: "https://fake-host:1234/blobs", User: "******", Password: "******", }, httpClient, logger) expectedBlobstore := NewBlobstore(davClient, fakeUUIDGenerator, fs, logger) Expect(blobstore).To(Equal(expectedBlobstore)) }) }) Context("when URL does not have username and password", func() { // This test was added because parsing password is failing when userInfo is missing in URL It("returns the blobstore", func() { davClient := boshdavcli.NewClient(boshdavcliconf.Config{ Endpoint: "https://fake-host:1234/blobs", User: "", Password: "", }, httpClient, logger)