Skip to content
Snippets Groups Projects
Commit e1eff1af authored by Sergey Yakubov's avatar Sergey Yakubov
Browse files

fix

parent d4aae4b1
No related branches found
No related tags found
No related merge requests found
......@@ -25,12 +25,16 @@ type authorizationRequest struct {
}
func getSourceCredentials(request authorizationRequest) (SourceCredentials, error) {
vals := strings.Split(request.SourceCredentials, "%")
if len(vals) != 5 {
vals := strings.Split(request.SourceCredentials, "%")
nvals:=len(vals)
if nvals < 5 {
return SourceCredentials{}, errors.New("cannot get source credentials from " + request.SourceCredentials)
}
creds := SourceCredentials{vals[1], vals[2], vals[3], vals[4],vals[0]}
creds := SourceCredentials{Type:vals[0], BeamtimeId: vals[1], Beamline: vals[2], Token:vals[nvals-1]}
creds.DataSource=strings.Join(vals[3:nvals-1],"%")
if creds.DataSource == "" {
creds.DataSource = "detector"
}
......
......@@ -91,6 +91,8 @@ var credTests = [] struct {
{"raw%%beamline%source%token", SourceCredentials{"auto","beamline","source","token","raw"},true,"empty beamtime"},
{"raw%asapo_test%%source%token", SourceCredentials{"asapo_test","auto","source","token","raw"},true,"empty bealine"},
{"raw%%%source%token", SourceCredentials{},false,"both empty"},
{"processed%asapo_test%beamline%source%blabla%token", SourceCredentials{"asapo_test","beamline","source%blabla","token","processed"},true,"% in source"},
{"processed%asapo_test%beamline%source%blabla%", SourceCredentials{"asapo_test","beamline","source%blabla","","processed"},true,"% in source, no token"},
}
func TestSplitCreds(t *testing.T) {
......@@ -100,7 +102,7 @@ func TestSplitCreds(t *testing.T) {
creds,err := getSourceCredentials(request)
if test.ok {
assert.Nil(t,err)
assert.Equal(t,creds,test.cred,test.message)
assert.Equal(t,test.cred,creds,test.message)
} else {
assert.NotNil(t,err,test.message)
}
......
......@@ -462,9 +462,9 @@ Error StreamInfoFromDbResponse(const std::string &last_record_str,
}
Error MongoDBClient::GetEncodedStreamInfo(const std::string &collection_encoded, StreamInfo* info) const {
Error MongoDBClient::GetStreamInfo(const std::string &collection, StreamInfo* info) const {
std::string last_record_str, earliest_record_str;
auto err = GetRecordFromDb(collection_encoded, 0, GetRecordMode::kLast, &last_record_str);
auto err = GetRecordFromDb(collection, 0, GetRecordMode::kLast, &last_record_str);
if (err) {
if (err
== DBErrorTemplates::kNoRecord) { // with noRecord error it will return last_id = 0 which can be used to understand that the stream is not started yet
......@@ -473,7 +473,7 @@ Error MongoDBClient::GetEncodedStreamInfo(const std::string &collection_encoded,
}
return err;
}
err = GetRecordFromDb(collection_encoded, 0, GetRecordMode::kEarliest, &earliest_record_str);
err = GetRecordFromDb(collection, 0, GetRecordMode::kEarliest, &earliest_record_str);
if (err) {
return err;
}
......@@ -481,19 +481,19 @@ Error MongoDBClient::GetEncodedStreamInfo(const std::string &collection_encoded,
return StreamInfoFromDbResponse(last_record_str, earliest_record_str, info);
}
Error MongoDBClient::GetStreamInfo(const std::string &collection, StreamInfo* info) const {
std::string collection_encoded = EncodeColName(collection);
return GetEncodedStreamInfo(collection_encoded,info);
}
bool MongoCollectionIsDataStream(const std::string &stream_name) {
std::string prefix = std::string(kDBDataCollectionNamePrefix) + "_";
return stream_name.rfind(prefix, 0) == 0;
}
Error MongoDBClient::UpdateCurrentLastStreamInfo(const std::string &collection_name, StreamInfo* info) const {
Error MongoDBClient::UpdateLastStreamInfo(const char* str, StreamInfo* info) const {
auto collection_name = DecodeName(str);
if (!MongoCollectionIsDataStream(collection_name)) {
return nullptr;
}
StreamInfo next_info;
auto err = GetEncodedStreamInfo(collection_name, &next_info);
auto err = GetStreamInfo(collection_name, &next_info);
std::string prefix = std::string(kDBDataCollectionNamePrefix) + "_";
if (err) {
return err;
......@@ -505,17 +505,6 @@ Error MongoDBClient::UpdateCurrentLastStreamInfo(const std::string &collection_n
return nullptr;
}
Error MongoDBClient::UpdateLastStreamInfo(const char* str, StreamInfo* info) const {
std::string collection_name{str};
if (MongoCollectionIsDataStream(collection_name)) {
auto err = UpdateCurrentLastStreamInfo(collection_name, info);
if (err) {
return err;
}
}
return nullptr;
}
Error MongoDBClient::GetLastStream(StreamInfo* info) const {
if (!connected_) {
return DBErrorTemplates::kNotConnected.Generate();
......
......@@ -74,8 +74,6 @@ class MongoDBClient final : public Database {
Error AddBsonDocumentToArray(bson_t* query, bson_t* update, bool ignore_duplicates) const;
Error GetRecordFromDb(const std::string& collection, uint64_t id, GetRecordMode mode, std::string* res) const;
Error UpdateLastStreamInfo(const char *str, StreamInfo* info) const;
Error UpdateCurrentLastStreamInfo(const std::string& collection_name, StreamInfo* info) const;
Error GetEncodedStreamInfo(const std::string& collection, StreamInfo* info) const;
Error DeleteCollection(const std::string& name) const;
Error DeleteCollections(const std::string &prefix) const;
Error DeleteDocumentsInCollection(const std::string &collection_name,const std::string &querystr) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment