Пример #1
0
// startServer starts a new local storage server
// using a temporary directory and returns the listener,
// a base URL for the server and the directory path.
func startServer(c *gc.C) (listener net.Listener, url, dataDir string) {
	dataDir = c.MkDir()
	embedded, err := filestorage.NewFileStorageWriter(dataDir)
	c.Assert(err, gc.IsNil)
	listener, err = httpstorage.Serve("localhost:0", embedded)
	c.Assert(err, gc.IsNil)
	return listener, fmt.Sprintf("http://%s/", listener.Addr()), dataDir
}
Пример #2
0
// CreateLocalTestStorage returns the listener, which needs to be closed, and
// the storage that is backed by a directory created in the running test's temp
// directory.
func CreateLocalTestStorage(c *gc.C) (closer io.Closer, stor storage.Storage, dataDir string) {
	dataDir = c.MkDir()
	underlying, err := filestorage.NewFileStorageWriter(dataDir)
	c.Assert(err, gc.IsNil)
	listener, err := httpstorage.Serve("localhost:0", underlying)
	c.Assert(err, gc.IsNil)
	stor = httpstorage.Client(listener.Addr().String())
	closer = listener
	return
}
Пример #3
0
func (s *storageWorker) serveStorage(storageAddr, storageDir string, config *config) (net.Listener, error) {
	authenticated := len(config.caCertPEM) > 0 && len(config.caKeyPEM) > 0
	scheme := "http://"
	if authenticated {
		scheme = "https://"
	}
	logger.Infof("serving storage from %s to %s%s", storageDir, scheme, storageAddr)
	storage, err := filestorage.NewFileStorageWriter(storageDir)
	if err != nil {
		return nil, err
	}
	if authenticated {
		return httpstorage.ServeTLS(
			storageAddr,
			storage,
			config.caCertPEM,
			config.caKeyPEM,
			config.hostnames,
			config.authkey,
		)
	}
	return httpstorage.Serve(storageAddr, storage)
}