-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YDA-5623: format microservices with clang-format
- Loading branch information
1 parent
ea294a4
commit 7caaa79
Showing
10 changed files
with
743 additions
and
781 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,61 @@ | ||
#include "jansson.h" | ||
#include "irods_includes.hh" | ||
|
||
# define CREDS_STORE "/var/lib/irods/.credentials_store/store_config.json" | ||
|
||
#define CREDS_STORE "/var/lib/irods/.credentials_store/store_config.json" | ||
|
||
/* | ||
* keep it simple | ||
*/ | ||
class CredentialsStore { | ||
public: | ||
class CredentialsStore | ||
{ | ||
public: | ||
// load stored values | ||
CredentialsStore() { | ||
json_error_t error; | ||
|
||
store = json_load_file(CREDS_STORE, 0, &error); | ||
if (store == NULL) { | ||
rodsLog(LOG_ERROR, "Failed to load credentials store"); | ||
} | ||
// store is returned with refcount 1 | ||
CredentialsStore() | ||
{ | ||
json_error_t error; | ||
|
||
store = json_load_file(CREDS_STORE, 0, &error); | ||
if (store == NULL) { | ||
rodsLog(LOG_ERROR, "Failed to load credentials store"); | ||
} | ||
// store is returned with refcount 1 | ||
} | ||
// free stored values | ||
~CredentialsStore() { | ||
if (store != NULL) { | ||
json_decref(store); | ||
} | ||
~CredentialsStore() | ||
{ | ||
if (store != NULL) { | ||
json_decref(store); | ||
} | ||
} | ||
|
||
// check that the store is properly initialized | ||
bool isLoaded() { | ||
return (store != NULL); | ||
bool isLoaded() | ||
{ | ||
return (store != NULL); | ||
} | ||
|
||
// check that the store has a credential | ||
bool has(const char *key) { | ||
return (store != NULL && json_object_get(store, key) != NULL); | ||
bool has(const char* key) | ||
{ | ||
return (store != NULL && json_object_get(store, key) != NULL); | ||
} | ||
|
||
// get a credential from the store | ||
const char *get(const char *key) { | ||
if (store != NULL) { | ||
json_t *value; | ||
|
||
value = json_object_get(store, key); | ||
if (value != NULL && json_is_string(value)) { | ||
return json_string_value(value); | ||
} | ||
} | ||
|
||
rodsLog(LOG_ERROR, "Failed to retrieve credential \"%s\"", key); | ||
return NULL; | ||
const char* get(const char* key) | ||
{ | ||
if (store != NULL) { | ||
json_t* value; | ||
|
||
value = json_object_get(store, key); | ||
if (value != NULL && json_is_string(value)) { | ||
return json_string_value(value); | ||
} | ||
} | ||
|
||
rodsLog(LOG_ERROR, "Failed to retrieve credential \"%s\"", key); | ||
return NULL; | ||
} | ||
|
||
private: | ||
json_t *store; // in-memory copy of credentials store | ||
private: | ||
json_t* store; // in-memory copy of credentials store | ||
}; |
Oops, something went wrong.