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

Mentix site authorization status fix #1634

Merged
merged 18 commits into from
Apr 14, 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/fix-mentix-auth-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Mentix site authorization status changes

If a site changes its authorization status, Mentix did not update its internal data to reflect this change. This PR fixes this issue.

https://github.com/cs3org/reva/pull/1634
15 changes: 7 additions & 8 deletions pkg/mentix/connectors/localfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"

"github.com/pkg/errors"
"github.com/rs/zerolog"

"github.com/cs3org/reva/pkg/mentix/config"
Expand Down Expand Up @@ -66,19 +67,17 @@ func (connector *LocalFileConnector) Activate(conf *config.Configuration, log *z
func (connector *LocalFileConnector) RetrieveMeshData() (*meshdata.MeshData, error) {
jsonData, err := ioutil.ReadFile(connector.filePath)
if err != nil {
connector.log.Warn().Err(err).Msgf("unable to read file '%v'", connector.filePath)
return &meshdata.MeshData{}, nil
return nil, errors.Wrapf(err, "unable to read file '%v'", connector.filePath)
}

meshData := &meshdata.MeshData{}
if err := json.Unmarshal(jsonData, &meshData.Sites); err == nil {
// Enforce site types
connector.setSiteTypes(meshData)
meshData.InferMissingData()
} else {
connector.log.Warn().Err(err).Msgf("invalid file '%v'", connector.filePath)
if err := json.Unmarshal(jsonData, &meshData.Sites); err != nil {
return nil, errors.Wrapf(err, "invalid file '%v'", connector.filePath)
}

connector.setSiteTypes(meshData)
meshData.InferMissingData()

return meshData, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/mentix/exchangers/exchanger.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (exchanger *BaseExchanger) cloneMeshData(clean bool) *meshdata.MeshData {
cleanedSites := make([]*meshdata.Site, 0, len(meshDataClone.Sites))
for _, site := range meshDataClone.Sites {
// Only keep authorized sites
if site.IsAuthorized() {
if site.IsAuthorized {
cleanedSites = append(cleanedSites, site)
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/mentix/mentix.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ func (mntx *Mentix) tick(updateTimestamp *time.Time) {
if meshDataUpdated || time.Since(*updateTimestamp) >= mntx.updateInterval {
// Retrieve and update the mesh data; if the importers modified any data, these changes will
// be reflected automatically here
meshDataSet, err := mntx.retrieveMeshDataSet()
if err == nil {
if meshDataSet, err := mntx.retrieveMeshDataSet(); err == nil {
if err := mntx.applyMeshDataSet(meshDataSet); err != nil {
mntx.log.Err(err).Msg("failed to apply mesh data")
}
Expand Down Expand Up @@ -244,10 +243,11 @@ func (mntx *Mentix) retrieveMeshDataSet() (meshdata.Map, error) {

for _, connector := range mntx.connectors.Connectors {
meshData, err := connector.RetrieveMeshData()
if err != nil {
return nil, fmt.Errorf("retrieving mesh data from connector '%v' failed: %v", connector.GetName(), err)
if err == nil {
meshDataSet[connector.GetID()] = meshData
} else {
mntx.log.Err(err).Msgf("retrieving mesh data from connector '%v' failed", connector.GetName())
}
meshDataSet[connector.GetID()] = meshData
}

return meshDataSet, nil
Expand Down
10 changes: 6 additions & 4 deletions pkg/mentix/meshdata/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ type SiteType int

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

ID string
Name string
Expand Down Expand Up @@ -116,6 +118,8 @@ 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 @@ -130,9 +134,7 @@ func (site *Site) InferMissingData() {
}
}

// IsAuthorized checks whether the site is authorized. ScienceMesh are always authorized, while for community sites,
// the accounts service is queried.
func (site *Site) IsAuthorized() bool {
func (site *Site) getAuthorizationStatus() bool {
// ScienceMesh sites are always authorized
if site.Type == SiteTypeScienceMesh {
return true
Expand Down