Methods
(async) authenticate(req, res, req_body) → {Object}
This function is used to authenticate the incoming requests. Depending on the req, constructs the res and req_body objects.
The authentication happens based on the specifications provided here and here
Parameters:
Name | Type | Description |
---|---|---|
req |
Object | The request object. |
res |
Object | The response object. |
req_body |
string | The request body. |
- Source:
Returns:
auth Returns an object containing the method and the hash.
- Type
- Object
catalogue_exists() → {boolean}
Checks if the catalogue.xml exists.
- Source:
Returns:
Returns true if the catalogue.xml exists, either false.
- Type
- boolean
(async) cert_hash_exist(cert_hash) → {number}
Given a certificate hash, returns the number of records maching the certificate hash.
Parameters:
Name | Type | Description |
---|---|---|
cert_hash |
string | The certificate hash. |
- Source:
Returns:
The number of records or 0.
- Type
- number
Example
cert_hash_exist("1994a5c11fab6a1e951587bebe76beacba4226d0137001d65d2a792896c1fd12").then(function(result) {
console.log(result);
}).catch(err => console.error(err));
(async) clear_db(db)
Clears the database collections in order to refresh them.
Parameters:
Name | Type | Description |
---|---|---|
db |
object | The database object containing the collecitons. |
- Source:
create_backup() → {boolean}
Creates a backup of the catalogue.xml, named catalogue.xml.bak.
- Source:
Returns:
Returns true if the operation executed successfully, either false.
- Type
- boolean
create_digest_header(headers, not_allowed_response, res)
This function is used to create the digest header.
Parameters:
Name | Type | Description |
---|---|---|
headers |
Array | The header array to be signed. |
not_allowed_response |
string | The xml response. |
res |
Object | The response object. |
create_logger(folder, file_name_patern, date_format, The) → {object}
Returns a rolling file logger based on args or enviroment variables.
Parameters:
Name | Type | Description |
---|---|---|
folder |
string | The full path of the folder. |
file_name_patern |
string | The rolling file names patern. |
date_format |
string | The date format in the patern. |
The |
string | timestamp in each log. |
- Source:
Returns:
The rolling file logger object.
- Type
- object
create_x_request_sign_header(auth_header, headers, res)
This function is used to create the x-request-signature header.
Parameters:
Name | Type | Description |
---|---|---|
auth_header |
string | The authorization header. |
headers |
Array | The headers array to be signed. |
res |
Object | The response object. |
(async) createDB()
Creates the database, after deletion, based on the new catalogue.
- Source:
discovery_get(req, res)
This function is used to serv the servers' manifest during a GET request.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object | The request object. |
res |
Object | The response object. |
(async) echo_get(req, res)
This function is used to handle GET requests of the echo API according to here.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object | The request object. |
res |
Object | The response object. |
(async) echo_post(req, res)
This function is used to handle POST requests of the echo API according to here.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object | The request object. |
res |
Object | The response object. |
(async) get_catalogue() → {Promice}
Fetches the catalogue from the regisrty.
- Source:
Returns:
Returns a promise.
- Type
- Promice
get_from_backup() → {boolean}
If the catalogue.xml does not exist get data from catalogue.
- Source:
Returns:
Returns true if the catalogue.xml exists, either false.
- Type
- boolean
(async) get_heis_from_cert_hash(cert_hash) → {Array}
Given a certificagte hash, returns the macthed HEI IDs or empty Array.
Parameters:
Name | Type | Description |
---|---|---|
cert_hash |
string | The certificate hash. |
- Source:
Returns:
The macthed HEI IDs or empty Array.
- Type
- Array
Example
get_heis_from_cert_hash("1f4ed36ab99fb859e71c27282b95a46b7d7482702b86a73203958eb1c7146508").then(function(result) {
console.log(result); // prints a list of lists
console.log(result[0]); // need only the element at 0
}).catch(err => console.error(err));
(async) get_heis_from_rsa_hash(rsa_hash) → {Array}
Given a RSA hash, returns an Array with the HEI-IDs or empty Array.
Parameters:
Name | Type | Description |
---|---|---|
rsa_hash |
string | The RSA hash. |
- Source:
Returns:
The macthed RSA keys or empty Array.
- Type
- Array
Example
get_heis_from_rsa_hash("d85e663147ec92dcfb98de1fc94dd41d2c846fdaa4301f46e6ea3774af064d40").then(function(result) {
console.log(result); // prints a list of lists
console.log(result[0]); // need only the element at 0
}).catch(err => console.error(err));
get_keyid_from_header(auth_header) → {string}
This function is used to extract the keyID from the http-signature header.
Parameters:
Name | Type | Description |
---|---|---|
auth_header |
string | The authentication header. |
- Source:
Returns:
The keyID.
- Type
- string
(async) get_rsa_key_from_hash(rsa_hash) → {Array}
Given a RSA hash, returns the macthed RSA keys or empty Array.
Parameters:
Name | Type | Description |
---|---|---|
rsa_hash |
string | The RSA hash. |
- Source:
Returns:
The macthed RSA keys or empty Array.
- Type
- Array
Example
get_rsa_key_from_hash("2eb56a32d56675d01d3f2eabeca80439935aba548f41a415973158a4abcbe795").then(function(result) {
console.log(result); // prints the key in ""
console.log(result[0]); // prints the key evaluating the speacial chars like '\n'
}).catch(err => console.error(err));
init_db()
This function is used to invoke the update process every INTERVAL seconds, where INTERVAL is the homonym enviroment variable in the .env file.
The update process consists of the the actions with the following order:
- Fetch catalogue.xml from the regisrty
- Clear the database from the old data
- Insert to database the new data
- Source:
(async) insert_request_id(request_id)
Inserts the request_id in the database and the its creation date, in order to delete after 5 minutes.
Parameters:
Name | Type | Description |
---|---|---|
request_id |
string | The request_id. |
- Source:
Example
insert_request_id("11bf5b37-e0b8-42e0-8dcf-dc8c4aefc000").then(function() {
console.log("inserted");
}).catch(err => console.error(err));
institutions_get(req, res)
This function is used to handle GET requests of the institutions API according to here.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object | The request object. |
res |
Object | The response object. |
institutions_post(req, res)
This function is used to handle GET requests of the institutions API according to here.
We only accept parameters in the post request in application/x-www-form-urlencoded format
according to https://github.com/erasmus-without-paper/ewp-specs-api-institutions#request-parameters
Parameters:
Name | Type | Description |
---|---|---|
req |
Object | The request object. |
res |
Object | The response object. |
(async) method_not_allowed(req, res)
The use of this function is used to create the response to the methods that are not allowed.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object | The request object. |
res |
Object | The response object. |
- Source:
(async) request_id_exist(request_id) → {number}
Given a request id, returns the number of records maching that id.
Parameters:
Name | Type | Description |
---|---|---|
request_id |
string | The request id. |
- Source:
Returns:
The number of records or 0.
- Type
- number
Example
request_id_exist("11bf5b37-e0b8-42e0-8dcf-dc8c4aefc000").then(function() {
console.log("inserted");
}).catch(err => console.error(err));
(async) respond(req, res, res_body)
The use of this function is used to create the response for the incoming requests.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object | The request object. |
res |
Object | The response object. |
res_body |
string | The response body. |
- Source:
(async) rsa_hash_exist(rsa_hash) → {number}
Given a RSA hash, returns the number of records maching the RSA hash.
Parameters:
Name | Type | Description |
---|---|---|
rsa_hash |
string | The RSA hash. |
- Source:
Returns:
The number of records or 0.
- Type
- number
Example
rsa_hash_exist("2eb56a32d56675d01d3f2eabeca80439935aba548f41a415973158a4abcbe795").then(function(result) {
console.log(result);
}).catch(err => console.error(err));
sha_256_digest(req_body) → {string}
This function is used to create the SHA-256 of the request body in base64 encoding.
Parameters:
Name | Type | Description |
---|---|---|
req_body |
string | The request body. |
- Source:
Returns:
The SHA-256 of the request body in base64 encoding.
- Type
- string