Skip to content

Commit

Permalink
Various updates to the Site Accounts service (#2672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-WWU-IT authored Mar 28, 2022
1 parent d8593c2 commit f6e430b
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 436 deletions.
9 changes: 9 additions & 0 deletions changelog/unreleased/siteacc-upd-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Enhancement: Further Site Accounts improvements

Yet another PR to update the site accounts (and Mentix):
New default site ID;
Include service type in alerts;
Naming unified;
Remove obsolete stuff.

https://github.com/cs3org/reva/pull/2672
7 changes: 0 additions & 7 deletions pkg/mentix/config/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ package config
const (
// ConnectorIDGOCDB is the connector identifier for GOCDB.
ConnectorIDGOCDB = "gocdb"
// ConnectorIDLocalFile is the connector identifier for local files.
ConnectorIDLocalFile = "localfile"
)

const (
// ImporterIDSiteRegistration is the identifier for the external site registration importer.
ImporterIDSiteRegistration = "sitereg"
)

const (
Expand Down
10 changes: 5 additions & 5 deletions pkg/mentix/connectors/gocdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,13 @@ func (connector *GOCDBConnector) querySites(meshData *meshdata.MeshData) error {
for _, site := range sites.Sites {
properties := connector.extensionsToMap(&site.Extensions)

siteID := meshdata.GetPropertyValue(properties, meshdata.PropertySiteID, "")
if len(siteID) == 0 {
return fmt.Errorf("site ID missing for site '%v'", site.ShortName)
}
// The site ID can be set through a property; by default, the site short name will be used
siteID := meshdata.GetPropertyValue(properties, meshdata.PropertySiteID, site.ShortName)

// See if an organization has been defined using properties; otherwise, use the official name
organization := meshdata.GetPropertyValue(properties, meshdata.PropertyOrganization, site.OfficialName)

meshsite := &meshdata.Site{
Type: meshdata.SiteTypeScienceMesh, // All sites stored in the GOCDB are part of the mesh
ID: siteID,
Name: site.ShortName,
FullName: site.OfficialName,
Expand Down Expand Up @@ -295,6 +292,9 @@ func (connector *GOCDBConnector) getServiceURL(service *gocdb.Service, endpoint
svcURL.Path = endpoint.URL
} else {
svcURL.Path = path.Join(svcURL.Path, endpoint.URL)
if strings.HasSuffix(endpoint.URL, "/") { // Restore trailing slash if necessary
svcURL.Path += "/"
}
}
}
}
Expand Down
23 changes: 3 additions & 20 deletions pkg/mentix/exchangers/exchanger.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ type BaseExchanger struct {

enabledConnectors []string

meshData *meshdata.MeshData
allowUnauthorizedSites bool
meshData *meshdata.MeshData

locker sync.RWMutex
}
Expand Down Expand Up @@ -125,22 +124,11 @@ func (exchanger *BaseExchanger) storeMeshDataSet(meshDataSet meshdata.Map) error
return nil
}

func (exchanger *BaseExchanger) cloneMeshData(clean bool) *meshdata.MeshData {
func (exchanger *BaseExchanger) cloneMeshData() *meshdata.MeshData {
exchanger.locker.RLock()
meshDataClone := exchanger.meshData.Clone()
exchanger.locker.RUnlock()

if clean && !exchanger.allowUnauthorizedSites {
cleanedSites := make([]*meshdata.Site, 0, len(meshDataClone.Sites))
for _, site := range meshDataClone.Sites {
// Only keep authorized sites
if site.IsAuthorized {
cleanedSites = append(cleanedSites, site)
}
}
meshDataClone.Sites = cleanedSites
}

return meshDataClone
}

Expand All @@ -167,7 +155,7 @@ func (exchanger *BaseExchanger) SetEnabledConnectors(connectors []string) {
// MeshData returns the stored mesh data. The returned data is cloned to prevent accidental data changes.
// Unauthorized sites are also removed if this exchanger doesn't allow them.
func (exchanger *BaseExchanger) MeshData() *meshdata.MeshData {
return exchanger.cloneMeshData(true)
return exchanger.cloneMeshData()
}

func (exchanger *BaseExchanger) setMeshData(meshData *meshdata.MeshData) {
Expand All @@ -177,11 +165,6 @@ func (exchanger *BaseExchanger) setMeshData(meshData *meshdata.MeshData) {
exchanger.meshData = meshData
}

// SetAllowUnauthorizedSites sets whether this exchanger allows the exchange of unauthorized sites.
func (exchanger *BaseExchanger) SetAllowUnauthorizedSites(allow bool) {
exchanger.allowUnauthorizedSites = allow
}

// Locker returns the locking object.
func (exchanger *BaseExchanger) Locker() *sync.RWMutex {
return &exchanger.locker
Expand Down
4 changes: 1 addition & 3 deletions pkg/mentix/exchangers/exporters/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type Metrics struct {
const (
keySiteID = "site_id"
keySiteName = "site"
keySiteType = "site_type"
keyServiceType = "service_type"
)

Expand Down Expand Up @@ -70,7 +69,7 @@ func (m *Metrics) registerMetrics() error {
Name: m.isScheduledStats.Name(),
Description: m.isScheduledStats.Description(),
Measure: m.isScheduledStats,
TagKeys: []tag.Key{tag.MustNewKey(keySiteID), tag.MustNewKey(keySiteName), tag.MustNewKey(keySiteType), tag.MustNewKey(keyServiceType)},
TagKeys: []tag.Key{tag.MustNewKey(keySiteID), tag.MustNewKey(keySiteName), tag.MustNewKey(keyServiceType)},
Aggregation: view.LastValue(),
}

Expand All @@ -96,7 +95,6 @@ func (m *Metrics) exportSiteMetrics(site *meshdata.Site) error {
mutators := make([]tag.Mutator, 0)
mutators = append(mutators, tag.Insert(tag.MustNewKey(keySiteID), site.ID))
mutators = append(mutators, tag.Insert(tag.MustNewKey(keySiteName), site.Name))
mutators = append(mutators, tag.Insert(tag.MustNewKey(keySiteType), meshdata.GetSiteTypeName(site.Type)))
mutators = append(mutators, tag.Insert(tag.MustNewKey(keyServiceType), "SCIENCEMESH_HCHECK"))

// Create a new context to serve the metrics
Expand Down
2 changes: 0 additions & 2 deletions pkg/mentix/exchangers/exporters/promsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type PrometheusSDExporter struct {

const (
labelSiteName = "__meta_mentix_site"
labelSiteType = "__meta_mentix_site_type"
labelSiteID = "__meta_mentix_site_id"
labelSiteCountry = "__meta_mentix_site_country"
labelType = "__meta_mentix_type"
Expand All @@ -77,7 +76,6 @@ func getScrapeTargetLabels(site *meshdata.Site, service *meshdata.Service, endpo
endpointURL, _ := url.Parse(endpoint.URL)
labels := map[string]string{
labelSiteName: site.Name,
labelSiteType: meshdata.GetSiteTypeName(site.Type),
labelSiteID: site.ID,
labelSiteCountry: site.CountryCode,
labelType: endpoint.Type.Name,
Expand Down
1 change: 0 additions & 1 deletion pkg/mentix/exchangers/exporters/webapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (exporter *WebAPIExporter) Activate(conf *config.Configuration, log *zerolo
// Store WebAPI specifics
exporter.SetEndpoint(conf.Exporters.WebAPI.Endpoint, conf.Exporters.WebAPI.IsProtected)
exporter.SetEnabledConnectors(conf.Exporters.WebAPI.EnabledConnectors)
exporter.SetAllowUnauthorizedSites(true)

exporter.RegisterActionHandler("", webapi.HandleDefaultQuery)

Expand Down
47 changes: 0 additions & 47 deletions pkg/mentix/meshdata/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,12 @@ import (
"net/url"
"strings"

"github.com/cs3org/reva/pkg/mentix/accservice"
"github.com/cs3org/reva/pkg/mentix/utils/network"
)

const (
// SiteTypeScienceMesh flags a site as being part of the mesh.
SiteTypeScienceMesh SiteType = iota
// SiteTypeCommunity flags a site as being a community site.
SiteTypeCommunity
)

// SiteType holds the type of a site.
type SiteType int

// Site represents a single site managed by Mentix.
type Site struct {
// Internal settings
Type SiteType `json:"-"`
IsAuthorized bool `json:"-"`

ID string
Name string
FullName string
Expand Down Expand Up @@ -120,8 +106,6 @@ func (site *Site) Verify() error {
// InferMissingData infers missing data from other data where possible.
func (site *Site) InferMissingData() {
// Infer missing data
site.IsAuthorized = site.getAuthorizationStatus()

if site.Homepage == "" {
site.Homepage = fmt.Sprintf("http://www.%v", site.Domain)
} else if site.Domain == "" {
Expand All @@ -135,34 +119,3 @@ func (site *Site) InferMissingData() {
service.InferMissingData()
}
}

func (site *Site) getAuthorizationStatus() bool {
// ScienceMesh sites are always authorized
if site.Type == SiteTypeScienceMesh {
return true
}

// Use the accounts service to find out whether the site is authorized
resp, err := accservice.Query("is-authorized", network.URLParams{"by": "siteid", "value": site.ID})
if err == nil && resp.Success {
if authorized, ok := resp.Data.(bool); ok {
return authorized
}
}

return false
}

// GetSiteTypeName returns the readable name of the given site type.
func GetSiteTypeName(siteType SiteType) string {
switch siteType {
case SiteTypeScienceMesh:
return "sciencemesh"

case SiteTypeCommunity:
return "community"

default:
return "unknown"
}
}
2 changes: 1 addition & 1 deletion pkg/siteacc/account/contact/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (template *PanelTemplate) GetTitle() string {

// GetCaption returns the caption which is displayed on the panel.
func (template *PanelTemplate) GetCaption() string {
return "Contact the ScienceMesh administration"
return "Contact the ScienceMesh administration!"
}

// GetContentJavaScript delivers additional JavaScript code.
Expand Down
4 changes: 2 additions & 2 deletions pkg/siteacc/account/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type PanelTemplate struct {

// GetTitle returns the title of the panel.
func (template *PanelTemplate) GetTitle() string {
return "ScienceMesh Account"
return "ScienceMesh Site Administrator Account"
}

// GetCaption returns the caption which is displayed on the panel.
func (template *PanelTemplate) GetCaption() string {
return "Edit your ScienceMesh Account!"
return "Edit your ScienceMesh Site Administrator Account!"
}

// GetContentJavaScript delivers additional JavaScript code.
Expand Down
2 changes: 1 addition & 1 deletion pkg/siteacc/account/edit/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ html * {

const tplBody = `
<div>
<p>Edit your ScienceMesh account information below.</p>
<p>Edit your ScienceMesh Site Administrator Account information below.</p>
<p>Please note that you cannot modify your email address using this form.</p>
</div>
<div>&nbsp;</div>
Expand Down
4 changes: 2 additions & 2 deletions pkg/siteacc/account/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type PanelTemplate struct {

// GetTitle returns the title of the panel.
func (template *PanelTemplate) GetTitle() string {
return "ScienceMesh Account Login"
return "ScienceMesh Site Administrator Account Login"
}

// GetCaption returns the caption which is displayed on the panel.
func (template *PanelTemplate) GetCaption() string {
return "Login to your ScienceMesh Account!"
return "Login to your ScienceMesh Site Administrator Account!"
}

// GetContentJavaScript delivers additional JavaScript code.
Expand Down
2 changes: 1 addition & 1 deletion pkg/siteacc/account/login/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ html * {

const tplBody = `
<div>
<p>Login to your ScienceMesh account using the form below.</p>
<p>Login to your ScienceMesh Site Administrator Account using the form below.</p>
</div>
<div>&nbsp;</div>
<div>
Expand Down
4 changes: 2 additions & 2 deletions pkg/siteacc/account/manage/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type PanelTemplate struct {

// GetTitle returns the title of the panel.
func (template *PanelTemplate) GetTitle() string {
return "ScienceMesh Account"
return "ScienceMesh Site Administrator Account"
}

// GetCaption returns the caption which is displayed on the panel.
func (template *PanelTemplate) GetCaption() string {
return "Welcome to your ScienceMesh Account!"
return "Welcome to your ScienceMesh Site Administrator Account!"
}

// GetContentJavaScript delivers additional JavaScript code.
Expand Down
2 changes: 1 addition & 1 deletion pkg/siteacc/account/manage/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ html * {
const tplBody = `
<div>
<p><strong>Hello {{.Account.FirstName}} {{.Account.LastName}},</strong></p>
<p>On this page, you can manage your ScienceMesh user account. This includes editing your personal information, requesting access to the GOCDB and more.</p>
<p>On this page, you can manage your ScienceMesh Site Administrator Account. This includes editing your personal information, requesting access to the GOCDB and more.</p>
</div>
<div>&nbsp;</div>
<div>
Expand Down
4 changes: 2 additions & 2 deletions pkg/siteacc/account/registration/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type PanelTemplate struct {

// GetTitle returns the title of the panel.
func (template *PanelTemplate) GetTitle() string {
return "ScienceMesh Account Registration"
return "ScienceMesh Site Administrator Account Registration"
}

// GetCaption returns the caption which is displayed on the panel.
func (template *PanelTemplate) GetCaption() string {
return "Welcome to the ScienceMesh Account Registration!"
return "Welcome to the ScienceMesh Site Administrator Account Registration!"
}

// GetContentJavaScript delivers additional JavaScript code.
Expand Down
2 changes: 1 addition & 1 deletion pkg/siteacc/account/registration/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ html * {

const tplBody = `
<div>
<p>Fill out the form below to register for a ScienceMesh account. A confirmation email will be sent to you shortly after registration.</p>
<p>Fill out the form below to register for a ScienceMesh Site Administrator account. A confirmation email will be sent to you shortly after registration.</p>
</div>
<div>&nbsp;</div>
<div>
Expand Down
4 changes: 2 additions & 2 deletions pkg/siteacc/account/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type PanelTemplate struct {

// GetTitle returns the title of the panel.
func (template *PanelTemplate) GetTitle() string {
return "ScienceMesh Account"
return "ScienceMesh Site Administrator Account"
}

// GetCaption returns the caption which is displayed on the panel.
func (template *PanelTemplate) GetCaption() string {
return "Configure your ScienceMesh Account!"
return "Configure your ScienceMesh Site Administrator Account!"
}

// GetContentJavaScript delivers additional JavaScript code.
Expand Down
2 changes: 1 addition & 1 deletion pkg/siteacc/account/settings/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ input[type="checkbox"] {

const tplBody = `
<div>
<p>Configure your ScienceMesh account below.</p>
<p>Configure your ScienceMesh Site Administrator Account below.</p>
</div>
<div>&nbsp;</div>
<div>
Expand Down
4 changes: 2 additions & 2 deletions pkg/siteacc/admin/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func (panel *Panel) GetActiveTemplate(*html.Session, string) string {

// GetTitle returns the title of the htmlPanel.
func (panel *Panel) GetTitle() string {
return "ScienceMesh Administration Panel"
return "ScienceMesh Site Administrator Accounts Panel"
}

// GetCaption returns the caption which is displayed on the htmlPanel.
func (panel *Panel) GetCaption() string {
return "Accounts ({{.Accounts | len}})"
return "ScienceMesh Site Administrator Accounts ({{.Accounts | len}})"
}

// GetContentJavaScript delivers additional JavaScript code.
Expand Down
Loading

0 comments on commit f6e430b

Please sign in to comment.