-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
credentials manager initial poc (#24)
* credentials manager initial poc Signed-off-by: Johnny On <[email protected]> * remove console.logs Signed-off-by: Johnny On <[email protected]> * remove empty line Signed-off-by: Johnny On <[email protected]> * add apache license Signed-off-by: Johnny On <[email protected]> * profile as a const Signed-off-by: Johnny On <[email protected]>
- Loading branch information
1 parent
8733807
commit 90a75e0
Showing
12 changed files
with
365 additions
and
82 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
const path = require('path'); | ||
const fs = require("fs"); | ||
const CONFIG_PATH = path.join(__dirname, "config.json"); | ||
|
||
function getConfig(name, configPath=CONFIG_PATH) { | ||
let config = fs.readFileSync(configPath); | ||
config = JSON.parse(config.toString()); | ||
if (name) { | ||
return config[name] || {}; | ||
} else { | ||
return config; | ||
} | ||
} | ||
|
||
function setConfig(config, callback, configPath=CONFIG_PATH) { | ||
let oldConfig = fs.readFileSync(configPath); | ||
oldConfig = JSON.parse(oldConfig.toString()); | ||
oldConfig[config.NAME] = config; | ||
fs.writeFile(configPath, JSON.stringify(oldConfig), callback); | ||
} | ||
|
||
|
||
exports.getConfig = getConfig; | ||
exports.setConfig = setConfig; |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>OpenSearch Dashboards | Configuration</title> | ||
<link rel="stylesheet" href="./css/bootstrap.min.css"/> | ||
<style> | ||
label { | ||
font-weight: bold | ||
} | ||
input[type="radio"] { | ||
margin-left: 12px; | ||
margin-right: 6px; | ||
font-weight: 800; | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
visibility: hidden | ||
} | ||
label { | ||
margin-top: 16px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="jumbotron" style="text-align: center;padding: 30px"> | ||
<h1>Credentials Manager</h1> | ||
</div> | ||
|
||
<div style="width:80%; margin-left:10%; margin-top: 30px; margin-bottom: 0"> | ||
<div id="error" class="alert alert-danger hidden"> | ||
<strong>Error!</strong> <span id="error-message"/> | ||
</div> | ||
<div id="warn" class="alert alert-warning hidden" role="alert"> | ||
<strong>Warning!</strong> <span id="warn-message"/> | ||
</div> | ||
<div style="margin:0"> | ||
<form style="margin:0"> | ||
<div class="form-group"> | ||
<label for="name">NAME</label> | ||
<input type="text" id="name" class="form-control"> | ||
</input> | ||
<label for="accessKey">AWS ACCESS KEY ID</label> | ||
<input type="text" id="awsAccessKeyId" class="form-control"> | ||
</input> | ||
|
||
<label for="secretAccessKey">AWS SECRET ACCESS KEY</label> | ||
<input type="text" id="awsSecretAccessKey" class="form-control"> | ||
</input> | ||
<label for="endpoint">ENDPOINT</label> | ||
<input type="text" id="endpoint" class="form-control"> | ||
</input> | ||
<label for="osdPath">Path to OpenSearch Dashboards</label> | ||
<input type="text" id="osdPath" class="form-control"> | ||
</input> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
<div style="width:80%; margin-left:10%; margin-top: 30px"> | ||
<div> | ||
<div style="text-align: center"> | ||
<a id="submit" class="btn btn-primary btn-lg" href="#">SAVE</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="./configRenderer.js"></script> | ||
</body> | ||
|
||
|
||
</html> |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
const { contextBridge } = require('electron'); | ||
const { ipcRenderer } = require("electron"); | ||
const configLibrary = require('./config'); | ||
|
||
contextBridge.exposeInMainWorld( | ||
'electron', | ||
{ | ||
ipcRenderer: ipcRenderer, | ||
onName: (fn) => { | ||
ipcRenderer.on("name", (event, ...args) => fn(...args)); | ||
}, | ||
getConfig: (name) => configLibrary.getConfig(name), | ||
setConfig: (config, callback) => configLibrary.setConfig(config, callback), | ||
} | ||
) |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
function init() { | ||
addListeners(); | ||
} | ||
|
||
// store name variable if exists | ||
window.electron.onName(function (name) { | ||
let config = window.electron.getConfig(name); | ||
populateFields(config); | ||
}); | ||
|
||
function getMapping() { | ||
return [{id: "name", key: "NAME"}, | ||
{id: "awsAccessKeyId", key: "AWS_ACCESS_KEY_ID"}, | ||
{id: "awsSecretAccessKey", key: "AWS_SECRET_ACCESS_KEY"}, | ||
{id: "endpoint", key: "ENDPOINT"}, | ||
{id: "osdPath", key: "OSD_PATH"} | ||
] | ||
} | ||
async function populateFields(config) { | ||
let mapping = getMapping(); | ||
for (map of mapping) { | ||
let input = document.getElementById(map.id); | ||
input.setAttribute("value", config[map.key]); | ||
} | ||
} | ||
|
||
function getNewConfig() { | ||
let mapping = getMapping(); | ||
let config = {}; | ||
mapping.forEach(function(map) { | ||
let input = document.getElementById(map.id); | ||
config[map.key] = input.value; | ||
}) | ||
return config; | ||
} | ||
|
||
function addListeners() { | ||
let submit = document.getElementById("submit"); | ||
submit.addEventListener("click", async (event) => { | ||
event.preventDefault(); | ||
let newConfig = getNewConfig(); | ||
window.electron.setConfig(newConfig, closeWindow); | ||
}) | ||
} | ||
|
||
function closeWindow() { | ||
window.electron.ipcRenderer.invoke("closeWindow"); | ||
} | ||
|
||
init(); | ||
|
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
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
Oops, something went wrong.