-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Control Plane API call to add apikey for Iglu authentication (closes
#116)
- Loading branch information
1 parent
997895a
commit 4f797cd
Showing
6 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
provisioning/resources/control-plane/scripts/add_iglu_server_super_uuid.sh
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,17 @@ | ||
#!/bin/bash | ||
iglu_server_super_uid=$1 | ||
config_dir=$2 | ||
|
||
iglu_resolver_config_dir="$config_dir/iglu-resolver.json" | ||
|
||
##there will be only one local iglu server, therefore apikey will be added for this iglu server | ||
n=$(awk '/localhost/{print NR}' $iglu_resolver_config_dir) ## find number of the line which contains "localhost" | ||
n=$((n+1)) ##add one to line number which contains 'localhost' keyword, this line will contain apikey for local iglu server | ||
sudo sed -i ''$n's/\(.*"apikey":\)\(.*\)/\1 "'$iglu_server_super_uid'"/' $iglu_resolver_config_dir ##write apikey for local iglu server | ||
|
||
#write super apikey to db | ||
export PGPASSWORD=snowplow | ||
delete_all_apikeys="DELETE FROM apikeys" | ||
iglu_server_setup="INSERT INTO apikeys (uid, vendor_prefix, permission, createdat) VALUES ('${iglu_server_super_uid}','*','super',current_timestamp);" | ||
psql --host=localhost --port=5432 --username=snowplow --dbname=iglu -c "${delete_all_apikeys}" | ||
psql --host=localhost --port=5432 --username=snowplow --dbname=iglu -c "${iglu_server_setup}" |
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
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
88 changes: 88 additions & 0 deletions
88
provisioning/resources/ui/js/components/ControlPlaneComponents/AddIgluServerSuperUUID.tsx
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,88 @@ | ||
/* | ||
* Copyright (c) 2016-2017 Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
|
||
/// <reference path="../../../typings/node/node.d.ts" /> | ||
/// <reference path="../../../typings/react/react.d.ts" /> | ||
/// <reference path="../../../typings/react/react-dom.d.ts" /> | ||
/// <reference path="../.././Interfaces.d.ts"/> | ||
|
||
import React = require('react'); | ||
import ReactDOM = require("react-dom"); | ||
import axios from 'axios'; | ||
|
||
export default React.createClass({ | ||
getInitialState () { | ||
return { | ||
iglu_server_super_uuid: '', | ||
disabled: false | ||
}; | ||
}, | ||
|
||
handleChange(evt) { | ||
this.setState({ | ||
iglu_server_super_uuid: evt.target.value | ||
}); | ||
}, | ||
|
||
sendFormData() { | ||
var _this = this | ||
var igluServerSuperUUID = this.state.iglu_server_super_uuid | ||
|
||
function setInitState() { | ||
_this.setState({ | ||
iglu_server_uri: "", | ||
iglu_server_apikey: "", | ||
disabled: false | ||
}); | ||
} | ||
|
||
_this.setState({ | ||
disabled: true | ||
}); | ||
var params = new URLSearchParams(); | ||
params.append('iglu_server_super_uuid', _this.state.iglu_server_super_uuid) | ||
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded' | ||
axios.post('/control-plane/add-iglu-server-super-uuid', params, {}) | ||
.then(function (response) { | ||
setInitState() | ||
alert('Uploaded successfully'); | ||
}) | ||
.catch(function (error) { | ||
setInitState() | ||
alert('Error:' + error.response.data); | ||
}); | ||
}, | ||
|
||
handleSubmit(event) { | ||
alert('Please wait...'); | ||
event.preventDefault(); | ||
this.sendFormData(); | ||
}, | ||
|
||
render() { | ||
return ( | ||
<div className="tab-content"> | ||
<h4>Add super UUID for local Iglu Server: </h4> | ||
<form action="" onSubmit={this.handleSubmit}> | ||
<div className="form-group"> | ||
<label htmlFor="iglu_server_super_uuid">Iglu Server Super UUID: </label> | ||
<input className="form-control" name="iglu_server_super_uuid" ref="iglu_server_super_uuid" required type="text" onChange={this.handleChange} value={this.state.iglu_server_super_uuid} /> | ||
</div> | ||
<div className="form-group"> | ||
<button className="btn btn-primary" type="submit" disabled={this.state.disabled}>Add UUID</button> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} | ||
}); |