Skip to content

Commit

Permalink
Add Control Plane API call to change username and password for basic …
Browse files Browse the repository at this point in the history
…http authentication (closes #117)
  • Loading branch information
aldemirenes committed Jul 12, 2017
1 parent 8a14d82 commit 7c8d0d4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
username=$1
password=$2
config_dir=$3

caddyfile_directory="$config_dir/Caddyfile"

#add username and password to Caddyfile for basic auth
sudo sed -i 's/\(.*basicauth\)\(.*\)/\1 "'$username'" "'$password'" {/' $caddyfile_directory

sudo service caddy_init restart
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
http.HandleFunc("/uploadenrichments", uploadEnrichments)
http.HandleFunc("/addexternaligluserver", addExternalIgluServer)
http.HandleFunc("/addigluserversuperuuid", addIgluServerSuperUUID)
http.HandleFunc("/changeusernameandpassword", changeUsernameAndPassword)
log.Fatal(http.ListenAndServe(":10000", nil))
}

Expand Down Expand Up @@ -139,3 +140,31 @@ func addIgluServerSuperUUID(resp http.ResponseWriter, req *http.Request) {
}
}

func changeUsernameAndPassword(resp http.ResponseWriter, req *http.Request) {
if req.Method == "POST" {
req.ParseForm()
newUsername := req.Form["new_username"][0]
newPassword := req.Form["new_password"][0]

shellScriptCommand := []string{scriptsPath + "/" + "submit_username_password_for_basic_auth.sh",
newUsername,
newPassword,
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, "changed successfully")
}
}

12 changes: 12 additions & 0 deletions provisioning/resources/control-plane/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ else
exit 1
fi

## Change username and password for basic http authentication test
cp $testEnv/orgConfig/Caddyfile $testEnv/testConfig/.
change_uname_pass_result=$(curl -s -o /dev/null -w "%{http_code}" -d 'new_username=test_username&new_password=test_password' localhost:10000/changeusernameandpassword)
sleep 2
diff_test_expected=$(diff $testEnv/testConfig/Caddyfile $testEnv/expectedConfig/Caddyfile_change_username_password)

if [[ "${change_uname_pass_result}" -eq 200 ]] && [[ "${diff_test_expected}" == "" ]];then
echo "Changing username and password is working correctly."
else
echo "Changing username and password 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
20 changes: 20 additions & 0 deletions provisioning/resources/ui/js/components/ControlPlane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ export class ControlPlane extends React.Component<{}, {}> {
</tbody>
</table>
</form>
<h4>Change username and password for basic http authentication:</h4>
<form action="/controlplane/changeusernameandpassword" method="post">
<table>
<tbody>
<tr>
<td>Username: <input type="text" name="new_username" /></td>
</tr>
<tr>
<td>Password: <input type="text" name="new_password" /></td>
</tr>
<tr>
<td><input type="submit" value="submit" /></td>
</tr>
</tbody>
</table>
</form>
<p>NOTE: You will lose connection after change the username and password because of server restarting.
Get back to previous page after submission and login with your new username and password.
</p>

</div>
);
}
Expand Down
Binary file removed snowplow-mini-control-plane-api
Binary file not shown.

0 comments on commit 7c8d0d4

Please sign in to comment.