-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
credentials manager initial poc #24
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this config file? Any reference in the codebase, I did a simple search, couldn't find anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to approach. By default it should be a file in src that is an empty object. However, when testing and using the app, it gets populated with access key information which I don't want to push
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK so this file will be generated by code? I am good with that. Any reference in README or comments in code files will be helpful