Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Site accounts & Mentix updates (cs3org#3404)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-WWU-IT authored and vascoguita committed Oct 28, 2022
1 parent 8d68dd3 commit b130efb
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 15 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/siteacc-mentix-upd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Site accounts & Mentix updates

Some small improvements to the Site Accounts and Mentix services, including normalization of data exposed at the `/cs3` endpoint of Mentix.

https://github.com/cs3org/reva/pull/3404
61 changes: 61 additions & 0 deletions pkg/mentix/exchangers/exporters/cs3api/normalize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2018-2021 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package cs3api

import (
"net/url"
"regexp"

"github.com/rs/zerolog"
)

func _normalizeAddress(addr string) (*url.URL, error) {
address := addr

// See if the address includes a protocol; if not, add a default one
re := regexp.MustCompile(".+://.+")
if !re.MatchString(address) {
address = "https://" + address
}

// Parse the address as a URL
addressURL, err := url.Parse(address)
if err != nil {
return nil, err
}
return addressURL, nil
}

func normalizeHost(domain string, log *zerolog.Logger) string {
address, err := _normalizeAddress(domain)
if err != nil {
log.Error().Msgf("unable to parse host %v", domain)
return domain
}
return address.Hostname()
}

func normalizeURLPath(path string, log *zerolog.Logger) string {
address, err := _normalizeAddress(path)
if err != nil {
log.Error().Msgf("unable to parse URL %v", path)
return path
}
return address.String()
}
18 changes: 9 additions & 9 deletions pkg/mentix/exchangers/exporters/cs3api/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
)

// HandleDefaultQuery processes a basic query.
func HandleDefaultQuery(meshData *meshdata.MeshData, params url.Values, conf *config.Configuration, _ *zerolog.Logger) (int, []byte, error) {
func HandleDefaultQuery(meshData *meshdata.MeshData, params url.Values, conf *config.Configuration, log *zerolog.Logger) (int, []byte, error) {
// Convert the mesh data
ocmData, err := convertMeshDataToOCMData(meshData, conf.Exporters.CS3API.ElevatedServiceTypes)
ocmData, err := convertMeshDataToOCMData(meshData, conf.Exporters.CS3API.ElevatedServiceTypes, log)
if err != nil {
return http.StatusBadRequest, []byte{}, fmt.Errorf("unable to convert the mesh data to OCM data structures: %v", err)
}
Expand All @@ -50,7 +50,7 @@ func HandleDefaultQuery(meshData *meshdata.MeshData, params url.Values, conf *co
return http.StatusOK, data, nil
}

func convertMeshDataToOCMData(meshData *meshdata.MeshData, elevatedServiceTypes []string) ([]*ocmprovider.ProviderInfo, error) {
func convertMeshDataToOCMData(meshData *meshdata.MeshData, elevatedServiceTypes []string, log *zerolog.Logger) ([]*ocmprovider.ProviderInfo, error) {
// Convert the mesh data into the corresponding OCM data structures
providers := make([]*ocmprovider.ProviderInfo, 0, len(meshData.Operators)*3)
for _, op := range meshData.Operators {
Expand All @@ -60,8 +60,8 @@ func convertMeshDataToOCMData(meshData *meshdata.MeshData, elevatedServiceTypes

addService := func(host string, endpoint *meshdata.ServiceEndpoint, addEndpoints []*ocmprovider.ServiceEndpoint, apiVersion string) {
services = append(services, &ocmprovider.Service{
Host: host,
Endpoint: convertServiceEndpointToOCMData(endpoint),
Host: normalizeHost(host, log),
Endpoint: convertServiceEndpointToOCMData(endpoint, log),
AdditionalEndpoints: addEndpoints,
ApiVersion: apiVersion,
})
Expand All @@ -77,7 +77,7 @@ func convertMeshDataToOCMData(meshData *meshdata.MeshData, elevatedServiceTypes
endpointURL, _ := url.Parse(endpoint.URL)
addService(endpointURL.Host, endpoint, nil, apiVersion)
} else {
addEndpoints = append(addEndpoints, convertServiceEndpointToOCMData(endpoint))
addEndpoints = append(addEndpoints, convertServiceEndpointToOCMData(endpoint, log))
}
}

Expand All @@ -90,7 +90,7 @@ func convertMeshDataToOCMData(meshData *meshdata.MeshData, elevatedServiceTypes
FullName: site.FullName,
Description: site.Description,
Organization: site.Organization,
Domain: site.Domain,
Domain: normalizeHost(site.Domain, log),
Homepage: site.Homepage,
Email: site.Email,
Services: services,
Expand All @@ -103,14 +103,14 @@ func convertMeshDataToOCMData(meshData *meshdata.MeshData, elevatedServiceTypes
return providers, nil
}

func convertServiceEndpointToOCMData(endpoint *meshdata.ServiceEndpoint) *ocmprovider.ServiceEndpoint {
func convertServiceEndpointToOCMData(endpoint *meshdata.ServiceEndpoint, log *zerolog.Logger) *ocmprovider.ServiceEndpoint {
return &ocmprovider.ServiceEndpoint{
Type: &ocmprovider.ServiceType{
Name: endpoint.Type.Name,
Description: endpoint.Type.Description,
},
Name: endpoint.Name,
Path: endpoint.URL,
Path: normalizeURLPath(endpoint.URL, log),
IsMonitored: endpoint.IsMonitored,
Properties: endpoint.Properties,
}
Expand Down
1 change: 0 additions & 1 deletion pkg/siteacc/panels/account/contact/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const tplBody = `
Fields marked with <span class="mandatory">*</span> are mandatory.
</div>
<div style="grid-row: 5; grid-column: 2; text-align: right;">
<button type="reset">Reset</button>
<button type="submit" style="font-weight: bold;">Send</button>
</div>
</form>
Expand Down
1 change: 0 additions & 1 deletion pkg/siteacc/panels/account/edit/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const tplBody = `
Fields marked with <span class="mandatory">*</span> are mandatory.
</div>
<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>
</form>
Expand Down
1 change: 0 additions & 1 deletion pkg/siteacc/panels/account/login/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ const tplBody = `
Fields marked with <span class="mandatory">*</span> are mandatory.
</div>
<div style="grid-row: 4; grid-column: 2; text-align: right;">
<button type="reset">Reset</button>
<button type="submit" style="font-weight: bold;">Login</button>
</div>
</form>
Expand Down
1 change: 0 additions & 1 deletion pkg/siteacc/panels/account/registration/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ const tplBody = `
Fields marked with <span class="mandatory">*</span> are mandatory.
</div>
<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>
</form>
Expand Down
1 change: 0 additions & 1 deletion pkg/siteacc/panels/account/settings/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const tplBody = `
</div>
<div style="grid-row: 3; grid-column: 2; text-align: right;">
<button type="reset">Reset</button>
<button type="submit" style="font-weight: bold;">Save</button>
</div>
</form>
Expand Down
1 change: 0 additions & 1 deletion pkg/siteacc/panels/account/sites/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ const tplBody = `
Fields marked with <span class="mandatory">*</span> are mandatory.
</div>
<div style="grid-row: {{add $row 1}}; grid-column: 2; text-align: right;">
<button type="reset">Reset</button>
<button type="submit" style="font-weight: bold;">Save</button>
</div>
</form>
Expand Down

0 comments on commit b130efb

Please sign in to comment.