Skip to content

Commit

Permalink
Add Control Plane API call to add apikey for Iglu authentication (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
aldemirenes committed Sep 6, 2017
1 parent 3963e79 commit f776b87
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
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}"
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func main() {
http.HandleFunc("/restart-services", restartSPServices)
http.HandleFunc("/upload-enrichments", uploadEnrichments)
http.HandleFunc("/add-external-iglu-server", addExternalIgluServer)
http.HandleFunc("/add-iglu-server-super-uuid", addIgluServerSuperUUID)
log.Fatal(http.ListenAndServe(":10000", nil))
}

Expand Down Expand Up @@ -111,8 +112,7 @@ func addExternalIgluServer(resp http.ResponseWriter, req *http.Request) {
igluServerUri,
igluServerApikey,
configPath,
scriptsPath
}
scriptsPath}
cmd := exec.Command("/bin/bash", shellScriptCommand...)
err := cmd.Run()
if err != nil {
Expand All @@ -130,3 +130,28 @@ func addExternalIgluServer(resp http.ResponseWriter, req *http.Request) {
io.WriteString(resp, "added successfully")
}
}

func addIgluServerSuperUUID(resp http.ResponseWriter, req *http.Request) {
if req.Method == "POST" {
req.ParseForm()
igluServerSuperUUID := req.Form["iglu_server_super_uuid"][0]
shellScriptCommand := []string{scriptsPath + "/" + "add_iglu_server_super_uuid.sh",
igluServerSuperUUID,
configPath}
cmd := exec.Command("/bin/bash", shellScriptCommand...)
err := cmd.Run()
if err != nil {
http.Error(resp, err.Error(), 400)
return
}
//restart SP services
_, err = callRestartSPServicesScript()
resp.WriteHeader(http.StatusOK)
if err != nil {
http.Error(resp, err.Error(), 400)
return
}
resp.WriteHeader(http.StatusOK)
io.WriteString(resp, "added successfully")
}
}
13 changes: 13 additions & 0 deletions provisioning/resources/control-plane/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ else
exit 1
fi

## add Iglu Server super uuid test
sudo cp $testEnv/orgConfig/iglu-resolver.json $testEnv/testConfig/.
add_super_uuid_result=$(curl -s -o /dev/null -w "%{http_code}" -d "iglu_server_super_uuid=04577adf-6dce-49d7-8cbb-0ffdf83304de" localhost:10000/add-iglu-server-super-uuid)
sleep 2
diff_test_expected=$(diff $testEnv/testConfig/iglu-resolver.json $testEnv/expectedConfig/iglu-resolver-add-super-uuid.json)

if [[ "${add_super_uuid_result}" -eq 200 ]] && [[ "${diff_test_expected}" == "" ]];then
echo "Adding Iglu Server super uuid is working correctly."
else
echo "Adding Iglu Server super uuid is not working correctly."
exit 1
fi

sudo cp $testInit/snowplow_mini_control_plane_api_original_init /etc/init.d/snowplow_mini_control_plane_api
sudo /etc/init.d/snowplow_mini_control_plane_api restart

Expand Down
15 changes: 15 additions & 0 deletions provisioning/resources/ui/js/components/ControlPlane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ export class ControlPlane extends React.Component<{}, {}> {
</table>
</form>
</div>
<div className="tab-content">
<h4>Add super UUID for local Iglu Server:</h4>
<form action="/controlplane/add-iglu-server-super-uuid" method="post">
<table>
<tbody>
<tr>
<td>Iglu Server Super UUID: <input type="text" name="iglu_server_super_uuid" /></td>
</tr>
<tr>
<td><input type="submit" value="add UUID" /></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
);
}
Expand Down

0 comments on commit f776b87

Please sign in to comment.