Skip to content
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

Add alerting webhook to SiteAcc service #2203

Merged
merged 9 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/add-prom-webhook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add alerting webhook to SiteAcc service

To integrate email alerting with the monitoring pipeline, a Prometheus webhook has been added to the SiteAcc service. Furthermore account settings have been extended/modified accordingly.

https://github.com/cs3org/reva/pull/2203
24 changes: 20 additions & 4 deletions docs/content/en/docs/config/http/services/siteacc/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,28 @@ file = "/var/reva/accounts.json"
{{< /highlight >}}
{{% /dir %}}

## Site registration settings
## Mentix settings
{{% dir name="url" type="string" default="" %}}
The registration service URL.
The main Mentix URL.
{{< highlight toml >}}
[http.services.siteacc.sitereg]
url = "https://iop.example.com/sitereg"
[http.services.siteacc.mentix]
url = "https://iop.example.com/mentix"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="data_endpoint" type="string" default="/sites" %}}
The main data endpoint of Mentix.
{{< highlight toml >}}
[http.services.siteacc.mentix]
data_endpoint = "/data"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="sitereg_endpoint" type="string" default="/sitereg" %}}
The site registration endpoint of Mentix.
{{< highlight toml >}}
[http.services.siteacc.mentix]
sitereg_endpoint = "/register"
{{< /highlight >}}
{{% /dir %}}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.4
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/prometheus/alertmanager v0.23.0
github.com/rs/cors v1.8.0
github.com/rs/zerolog v1.25.0
github.com/sciencemesh/meshdirectory-web v1.0.4
Expand All @@ -75,7 +76,6 @@ require (
google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.27.1
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gotest.tools v2.2.0+incompatible
)

Expand Down
203 changes: 200 additions & 3 deletions go.sum

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions internal/http/services/siteacc/siteacc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func applyDefaultConfig(conf *config.Configuration) {
conf.Storage.Driver = "file"
}

if conf.Mentix.DataEndpoint == "" {
conf.Mentix.DataEndpoint = "/sites"
}

if conf.Mentix.SiteRegistrationEndpoint == "" {
conf.Mentix.SiteRegistrationEndpoint = "/sitereg"
}

// Enforce a minimum session timeout of 1 minute (and default to 5 minutes)
if conf.Webserver.SessionTimeout < 60 {
conf.Webserver.SessionTimeout = 5 * 60
Expand Down
40 changes: 14 additions & 26 deletions pkg/siteacc/account/edit/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ function verifyForm(formData) {
return false;
}

if (formData.getTrimmed("organization") == "") {
setState(STATE_ERROR, "Please specify your organization/company.", "form", "organization", true);
return false;
}

if (formData.getTrimmed("role") == "") {
setState(STATE_ERROR, "Please specify your role within the organization/company.", "form", "role", true);
setState(STATE_ERROR, "Please specify your role within your site.", "form", "role", true);
return false;
}

Expand Down Expand Up @@ -80,8 +75,6 @@ function handleAction(action) {
"title": formData.getTrimmed("title"),
"firstName": formData.getTrimmed("fname"),
"lastName": formData.getTrimmed("lname"),
"organization": formData.getTrimmed("organization"),
"website": formData.getTrimmed("website"),
"role": formData.getTrimmed("role"),
"phoneNumber": formData.getTrimmed("phone"),
"password": {
Expand Down Expand Up @@ -127,25 +120,20 @@ const tplBody = `
<div style="grid-row: 3;"><label for="lname">Last name: <span class="mandatory">*</span></label></div>
<div style="grid-row: 4;"><input type="text" id="lname" name="lname" value="{{.Account.LastName}}"/></div>

<div style="grid-row: 5;"><label for="organization">Organization/Company: <span class="mandatory">*</span></label></div>
<div style="grid-row: 6;"><input type="text" id="organization" name="organization" value="{{.Account.Organization}}"/></div>
<div style="grid-row: 5;"><label for="website">Website:</label></div>
<div style="grid-row: 6;"><input type="text" id="website" name="website" placeholder="https://www.example.com" value="{{.Account.Website}}"/></div>

<div style="grid-row: 7;"><label for="role">Role: <span class="mandatory">*</span></label></div>
<div style="grid-row: 8;"><input type="text" id="role" name="role" placeholder="Site administrator" value="{{.Account.Role}}"/></div>
<div style="grid-row: 7;"><label for="phone">Phone number:</label></div>
<div style="grid-row: 8;"><input type="text" id="phone" name="phone" placeholder="+49 030 123456" value="{{.Account.PhoneNumber}}"/></div>
<div style="grid-row: 5;"><label for="role">Role: <span class="mandatory">*</span></label></div>
<div style="grid-row: 6;"><input type="text" id="role" name="role" placeholder="Site administrator" value="{{.Account.Role}}"/></div>
<div style="grid-row: 5;"><label for="phone">Phone number:</label></div>
<div style="grid-row: 6;"><input type="text" id="phone" name="phone" placeholder="+49 030 123456" value="{{.Account.PhoneNumber}}"/></div>

<div style="grid-row: 9;">&nbsp;</div>
<div style="grid-row: 7;">&nbsp;</div>

<div style="grid-row: 10; grid-column: 1 / span 2;">If you want to change your password, fill out the fields below. Otherwise, leave them empty to keep your current one.</div>
<div style="grid-row: 11;"><label for="password">New password:</label></div>
<div style="grid-row: 12;"><input type="password" id="password" name="password" autocomplete="new-password"/></div>
<div style="grid-row: 11"><label for="password2">Confirm new password:</label></div>
<div style="grid-row: 12;"><input type="password" id="password2" name="password2" autocomplete="new-password"/></div>
<div style="grid-row: 8; grid-column: 1 / span 2;">If you want to change your password, fill out the fields below. Otherwise, leave them empty to keep your current one.</div>
<div style="grid-row: 9;"><label for="password">New password:</label></div>
<div style="grid-row: 10;"><input type="password" id="password" name="password" autocomplete="new-password"/></div>
<div style="grid-row: 9"><label for="password2">Confirm new password:</label></div>
<div style="grid-row: 10;"><input type="password" id="password2" name="password2" autocomplete="new-password"/></div>

<div style="grid-row: 13; font-style: italic; font-size: 0.8em;">
<div style="grid-row: 11; font-style: italic; font-size: 0.8em;">
The password must fulfil the following criteria:
<ul style="margin-top: 0em;">
<li>Must be at least 8 characters long</li>
Expand All @@ -155,10 +143,10 @@ const tplBody = `
</ul>
</div>

<div style="grid-row: 14; align-self: center;">
<div style="grid-row: 12; align-self: center;">
Fields marked with <span class="mandatory">*</span> are mandatory.
</div>
<div style="grid-row: 14; grid-column: 2; text-align: right;">
<div style="grid-row: 12; grid-column: 2; text-align: right;">
<button type="reset">Reset</button>
<button type="submit" style="font-weight: bold;">Save</button>
</div>
Expand Down
8 changes: 7 additions & 1 deletion pkg/siteacc/account/manage/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
package manage

const tplJavaScript = `
function handleSettings() {
setState(STATE_STATUS, "Redirecting to the account settings...");
window.location.replace("{{getServerAddress}}/account/?path=settings");
}

function handleEditAccount() {
setState(STATE_STATUS, "Redirecting to the account editor...");
window.location.replace("{{getServerAddress}}/account/?path=edit");
Expand Down Expand Up @@ -78,7 +83,7 @@ const tplBody = `
<ul style="margin-top: 0em;">
<li>Name: <em>{{.Account.Title}}. {{.Account.FirstName}} {{.Account.LastName}}</em></li>
<li>Email: <em><a href="mailto:{{.Account.Email}}">{{.Account.Email}}</a></em></li>
<li>Organization/company: <em>{{.Account.Organization}} {{if .Account.Website}}(<a href="{{.Account.Website}}">{{.Account.Website}}</a>){{end}}</em></li>
<li>ScienceMesh Site: <em>{{getSiteName .Account.Site false}} ({{getSiteName .Account.Site true}})</em></li>
<li>Role: <em>{{.Account.Role}}</em></li>
{{if .Account.PhoneNumber}}
<li>Phone: <em>{{.Account.PhoneNumber}}</em></li>
Expand All @@ -94,6 +99,7 @@ const tplBody = `
</div>
<div>
<form id="form" method="POST" class="box" style="width: 100%;">
<button type="button" onClick="handleSettings();">Settings</button>
<button type="button" onClick="handleEditAccount();">Edit account</button>
<span style="width: 25px;">&nbsp;</span>
<button type="button" onClick="handleRequestKey();" {{if .Account.Data.APIKey}}disabled{{end}}>Request API Key</button>
Expand Down
24 changes: 22 additions & 2 deletions pkg/siteacc/account/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cs3org/reva/pkg/siteacc/account/login"
"github.com/cs3org/reva/pkg/siteacc/account/manage"
"github.com/cs3org/reva/pkg/siteacc/account/registration"
"github.com/cs3org/reva/pkg/siteacc/account/settings"
"github.com/cs3org/reva/pkg/siteacc/config"
"github.com/cs3org/reva/pkg/siteacc/data"
"github.com/cs3org/reva/pkg/siteacc/html"
Expand All @@ -39,18 +40,26 @@ import (
type Panel struct {
html.PanelProvider

conf *config.Configuration

htmlPanel *html.Panel
}

const (
templateLogin = "login"
templateManage = "manage"
templateSettings = "settings"
templateEdit = "edit"
templateContact = "contact"
templateRegistration = "register"
)

func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger) error {
if conf == nil {
return errors.Errorf("no configuration provided")
}
panel.conf = conf

// Create the internal HTML panel
htmlPanel, err := html.NewPanel("account-panel", panel, conf, log)
if err != nil {
Expand All @@ -67,6 +76,10 @@ func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger)
return errors.Wrap(err, "unable to create the account management template")
}

if err := panel.htmlPanel.AddTemplate(templateSettings, &settings.PanelTemplate{}); err != nil {
return errors.Wrap(err, "unable to create the account settings template")
}

if err := panel.htmlPanel.AddTemplate(templateEdit, &edit.PanelTemplate{}); err != nil {
return errors.Wrap(err, "unable to create the account editing template")
}
Expand All @@ -84,7 +97,7 @@ func (panel *Panel) initialize(conf *config.Configuration, log *zerolog.Logger)

// GetActiveTemplate returns the name of the active template.
func (panel *Panel) GetActiveTemplate(session *html.Session, path string) string {
validPaths := []string{templateLogin, templateManage, templateEdit, templateContact, templateRegistration}
validPaths := []string{templateLogin, templateManage, templateSettings, templateEdit, templateContact, templateRegistration}
template := templateLogin

// Only allow valid template paths; redirect to the login page otherwise
Expand All @@ -100,7 +113,7 @@ func (panel *Panel) GetActiveTemplate(session *html.Session, path string) string

// PreExecute is called before the actual template is being executed.
func (panel *Panel) PreExecute(session *html.Session, path string, w http.ResponseWriter, r *http.Request) (html.ExecutionResult, error) {
protectedPaths := []string{templateManage, templateEdit, templateContact}
protectedPaths := []string{templateManage, templateSettings, templateEdit, templateContact}

if session.LoggedInUser == nil {
// If no user is logged in, redirect protected paths to the login page
Expand All @@ -125,17 +138,24 @@ func (panel *Panel) Execute(w http.ResponseWriter, r *http.Request, session *htm
flatValues[strings.Title(k)] = v[0]
}

availSites, err := data.QueryAvailableSites(panel.conf.Mentix.URL, panel.conf.Mentix.DataEndpoint)
if err != nil {
return errors.Wrap(err, "unable to query available sites")
}

type TemplateData struct {
Account *data.Account
Params map[string]string

Titles []string
Sites []data.SiteInformation
}

return TemplateData{
Account: session.LoggedInUser,
Params: flatValues,
Titles: []string{"Mr", "Mrs", "Ms", "Prof", "Dr"},
Sites: availSites,
}
}
return panel.htmlPanel.Execute(w, r, session, dataProvider)
Expand Down
48 changes: 25 additions & 23 deletions pkg/siteacc/account/registration/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ function verifyForm(formData) {
return false;
}

if (formData.getTrimmed("organization") == "") {
setState(STATE_ERROR, "Please specify your organization/company.", "form", "organization", true);
if (formData.getTrimmed("site") == "") {
setState(STATE_ERROR, "Please select your ScienceMesh site.", "form", "site", true);
return false;
}

if (formData.getTrimmed("role") == "") {
setState(STATE_ERROR, "Please specify your role within the organization/company.", "form", "role", true);
setState(STATE_ERROR, "Please specify your role within your site.", "form", "role", true);
return false;
}

Expand Down Expand Up @@ -92,8 +92,7 @@ function handleAction(action) {
"title": formData.getTrimmed("title"),
"firstName": formData.getTrimmed("fname"),
"lastName": formData.getTrimmed("lname"),
"organization": formData.getTrimmed("organization"),
"website": formData.getTrimmed("website"),
"site": formData.getTrimmed("site"),
"role": formData.getTrimmed("role"),
"phoneNumber": formData.getTrimmed("phone"),
"password": {
Expand Down Expand Up @@ -125,6 +124,14 @@ const tplBody = `
<form id="form" method="POST" class="box container-inline" style="width: 100%;" onSubmit="handleAction('create'); return false;">
<div style="grid-row: 1;"><label for="email">Email address: <span class="mandatory">*</span></label></div>
<div style="grid-row: 2;"><input type="text" id="email" name="email" placeholder="me@example.com"/></div>
<div style="grid-row: 1;"><label for="site">ScienceMesh Site: <span class="mandatory">*</span></label></div>
<div style="grid-row: 2;">
<select id="site" name="site">
{{range .Sites}}
<option value="{{.ID}}">{{.Name}} | {{.FullName}}</option>
{{end}}
</select>
</div>

<div style="grid-row: 3;">&nbsp;</div>

Expand All @@ -141,25 +148,20 @@ const tplBody = `
<div style="grid-row: 7;"><input type="text" id="fname" name="fname"/></div>
<div style="grid-row: 6;"><label for="lname">Last name: <span class="mandatory">*</span></label></div>
<div style="grid-row: 7;"><input type="text" id="lname" name="lname"/></div>

<div style="grid-row: 8;"><label for="role">Role: <span class="mandatory">*</span></label></div>
<div style="grid-row: 9;"><input type="text" id="role" name="role" placeholder="Site administrator"/></div>
<div style="grid-row: 8;"><label for="phone">Phone number:</label></div>
<div style="grid-row: 9;"><input type="text" id="phone" name="phone" placeholder="+49 030 123456"/></div>

<div style="grid-row: 8;"><label for="organization">Organization/Company: <span class="mandatory">*</span></label></div>
<div style="grid-row: 9;"><input type="text" id="organization" name="organization"/></div>
<div style="grid-row: 8;"><label for="website">Website:</label></div>
<div style="grid-row: 9;"><input type="text" id="website" name="website" placeholder="https://www.example.com"/></div>

<div style="grid-row: 10;"><label for="role">Role: <span class="mandatory">*</span></label></div>
<div style="grid-row: 11;"><input type="text" id="role" name="role" placeholder="Site administrator"/></div>
<div style="grid-row: 10;"><label for="phone">Phone number:</label></div>
<div style="grid-row: 11;"><input type="text" id="phone" name="phone" placeholder="+49 030 123456"/></div>

<div style="grid-row: 12;">&nbsp;</div>
<div style="grid-row: 10;">&nbsp;</div>

<div style="grid-row: 13;"><label for="password">Password: <span class="mandatory">*</span></label></div>
<div style="grid-row: 14;"><input type="password" id="password" name="password"/></div>
<div style="grid-row: 13;"><label for="password2">Confirm password: <span class="mandatory">*</span></label></div>
<div style="grid-row: 14;"><input type="password" id="password2" name="password2"/></div>
<div style="grid-row: 11;"><label for="password">Password: <span class="mandatory">*</span></label></div>
<div style="grid-row: 12;"><input type="password" id="password" name="password"/></div>
<div style="grid-row: 11;"><label for="password2">Confirm password: <span class="mandatory">*</span></label></div>
<div style="grid-row: 12;"><input type="password" id="password2" name="password2"/></div>

<div style="grid-row: 15; font-style: italic; font-size: 0.8em;">
<div style="grid-row: 13; font-style: italic; font-size: 0.8em;">
The password must fulfil the following criteria:
<ul style="margin-top: 0em;">
<li>Must be at least 8 characters long</li>
Expand All @@ -169,10 +171,10 @@ const tplBody = `
</ul>
</div>

<div style="grid-row: 16; align-self: center;">
<div style="grid-row: 14; align-self: center;">
Fields marked with <span class="mandatory">*</span> are mandatory.
</div>
<div style="grid-row: 16; grid-column: 2; text-align: right;">
<div style="grid-row: 14; grid-column: 2; text-align: right;">
<button type="reset">Reset</button>
<button type="submit" style="font-weight: bold;">Register</button>
</div>
Expand Down
Loading