summaryrefslogtreecommitdiff
path: root/src/repoList.cpp
blob: 7a69b7800309b9168eab12a445f9a291a6cfaf30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "repoList.h"
#include "repo.h"
#include <Ice/Communicator.h>
#include <Ice/Current.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Properties.h>
#include <Ice/Proxy.h>
#include <compileTimeFormatter.h>
#include <exceptions.h>
#include <memory>
#include <utility>
#include <volume.h>

GitFS::RepoList::RepoList(Ice::PropertiesPtr && p) : properties(std::move(p)) { }

AdHocFormatter(RepoPropertyName, "GitFS.%?.%?");

NetFS::VolumePrxPtr
GitFS::RepoList::connect(const ::std::string volume, const ::std::string auth, const ::Ice::Current & ice)
{
	if (volume.empty()) {
		throw NetFS::ConfigError();
	}

	const auto propReader = [volume, this](auto n) {
		return properties->getProperty(RepoPropertyName::get(volume, n));
	};

	if (propReader("gitdir").empty()) {
		throw NetFS::ConfigError();
	}
	if (propReader("authkey") != auth) {
		throw NetFS::AuthError();
	}
	return Ice::uncheckedCast<NetFS::VolumePrx>(ice.adapter->addWithUUID(std::make_shared<Repo>(propReader)));
}

NetFS::SettingsPtr
GitFS::RepoList::getSettings(const ::Ice::Current & ice)
{
	const auto props = ice.adapter->getCommunicator()->getProperties();
	return std::make_shared<NetFS::Settings>(props->getPropertyAsIntWithDefault("Ice.MessageSizeMax", 1024));
}