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 Sep 6, 2017
1 parent f776b87 commit da65cbc
Show file tree
Hide file tree
Showing 5 changed files with 75 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 @@ -46,6 +46,7 @@ func main() {
http.HandleFunc("/upload-enrichments", uploadEnrichments)
http.HandleFunc("/add-external-iglu-server", addExternalIgluServer)
http.HandleFunc("/add-iglu-server-super-uuid", addIgluServerSuperUUID)
http.HandleFunc("/change-username-and-password", changeUsernameAndPassword)
log.Fatal(http.ListenAndServe(":10000", nil))
}

Expand Down Expand Up @@ -155,3 +156,31 @@ func addIgluServerSuperUUID(resp http.ResponseWriter, req *http.Request) {
io.WriteString(resp, "added successfully")
}
}

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")
}
}
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 @@ -79,6 +79,19 @@ else
exit 1
fi

## Change username and password for basic http authentication test
sudo 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/change-username-and-password)
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
22 changes: 22 additions & 0 deletions provisioning/resources/ui/js/components/ControlPlane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ export class ControlPlane extends React.Component<{}, {}> {
</table>
</form>
</div>
<div className="tab-content">
<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>
</div>
);
}
Expand Down

0 comments on commit da65cbc

Please sign in to comment.