Skip to content

Commit e0ba9de

Browse files
committed
properties/yaml done
1 parent fb58537 commit e0ba9de

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ You can have several environments (a different name each time), each environment
3939

4040
# How to use
4141
```
42-
curl --location --request POST 'http://localhost:9000/secrets/dev/users-api/' \
42+
curl --location --request POST 'http://localhost:9000/secrets/dev/users-api/?option=yaml' \
4343
--header 'Accept: application/json' \
4444
--header 'Content-Type: application/json' \
4545
--header 'api-key: My-Super-Secret'
4646
```
47+
2 Options to generate configuration file :
48+
* properties: is a properties files with classical key/value,
49+
* yaml: is a yaml file
50+
51+
If no option in request param, the response is a json file.
4752

4853
Today two authentication : token (in query param of url) and by api-key (in the headers of the request)
4954

55+
5056
## With Docker
5157

5258
For example in a entrypoint.sh, you mut set <b>ENV</b> like : dev, prod, prep, qa... and the <b>API_KEY</b> of your mini-cloud-config
@@ -59,11 +65,11 @@ echo "Start retreive secrets"
5965
API_KEY= "api-key: $API_KEY"
6066
ACCEPT= "Accept: application/json"
6167
CONTENT_TYPE= "Content-Type: application/json"
62-
URL= "http://URL-MINI-CLOUD-CONFIG:9000/secrets/$ENV/users-api/"
68+
URL= "http://URL-MINI-CLOUD-CONFIG:9000/secrets/$ENV/users-api/?option=properties"
6369
64-
curl -X POST --header "$API_KEY" --header "$ACCEPT" --header "$CONTENT_TYPE" "$URL" >> properties.json
70+
curl -X POST --header "$API_KEY" --header "$ACCEPT" --header "$CONTENT_TYPE" "$URL" >> /apps/myapp/resources/application.properties
6571
66-
echo "Start replace secrets in conf file"
72+
#start myapp with external properties in param
6773
6874
..
6975
..

confs/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"environment": "development",
3+
"environment": "dev",
44
"description": "development environment for developer",
55
"authenticationType": "api-key",
66
"authenticationSecret": "My-Super-Secret",

secrets/index.js

+36-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ router.post('/secrets/*', (req, resp) => {
1111
url = url.split('/secrets')[1]
1212

1313
let environment = url.split('/')[1];
14-
let applicationName = url.split('/')[2];
14+
let applicationName = (url.split('/')[2]).split("?")[0];
1515
console.debug("Environment : " + environment);
1616
console.debug("Application : " + applicationName);
1717

18+
let option = req.query.option;
19+
1820
let settings = readConfiguration();
1921

2022
settings.filter(setting => setting.environment === environment).map(
@@ -37,9 +39,40 @@ router.post('/secrets/*', (req, resp) => {
3739
application => {
3840
console.debug("Application name : "+ application.name);
3941
console.debug("Application description : "+ application.description);
42+
43+
console.debug("Option: "+option);
44+
4045
resp.statusCode = 200;
41-
resp.json(application.secrets);
42-
return ;
46+
if( option && option !== null) {
47+
if(option === 'properties') {
48+
console.debug("Generate Properties");
49+
let result = "";
50+
application.secrets.map(secret => {
51+
result += "#"+ secret.description+"\n";
52+
result += secret.key+"="+secret.value+"\n\n";
53+
});
54+
resp.send(result);
55+
} else if(option === 'yaml' || option === 'yml') {
56+
console.debug("Generate Yaml");
57+
let result = "";
58+
application.secrets.map(secret => {
59+
result += "#"+ secret.description+"\n";
60+
result += secret.key+": "+secret.value+"\n\n";
61+
});
62+
resp.send(result);
63+
return;
64+
} else {
65+
console.debug("Generate Json");
66+
resp.json(application.secrets);
67+
return;
68+
}
69+
} else {
70+
console.debug("Generate Json");
71+
resp.json(application.secrets);
72+
return;
73+
}
74+
75+
return;
4376
}
4477
);
4578
}

0 commit comments

Comments
 (0)