Skip to content

Commit

Permalink
update IsProviderAllowed according to cs3org#953
Browse files Browse the repository at this point in the history
  • Loading branch information
mirekys committed Jul 9, 2020
1 parent e86ee87 commit c82e58c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions pkg/ocm/provider/authorizer/mentix/mentix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"net"
"net/http"
"net/url"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -67,8 +68,9 @@ func New(m map[string]interface{}) (provider.Authorizer, error) {
}

return &authorizer{
client: client,
conf: c,
client: client,
providerIPs: sync.Map{},
conf: c,
}, nil
}

Expand All @@ -90,7 +92,7 @@ type authorizer struct {
providers []*ocmprovider.ProviderInfo
providersExpiration int64
client *Client
providerIPs *sync.Map
providerIPs sync.Map
conf *config
}

Expand Down Expand Up @@ -167,7 +169,7 @@ func (a *authorizer) IsProviderAllowed(ctx context.Context, provider *ocmprovide
return errtypes.NotSupported("No IP provided")
}

ocmHost, err := getOCMHost(provider)
ocmHost, err := a.getOCMHost(provider.Domain)
if err != nil {
return errors.Wrap(err, "json: ocm host not specified for mesh provider")
}
Expand Down Expand Up @@ -207,12 +209,22 @@ func (a *authorizer) ListAllProviders(ctx context.Context) ([]*ocmprovider.Provi
return providers, nil
}

func getOCMHost(originProvider *ocmprovider.ProviderInfo) (string, error) {
for _, s := range originProvider.Services {
if s.Endpoint.Type.Name == "OCM" {
ocmHost := strings.TrimPrefix(s.Host, "https://")
ocmHost = strings.TrimPrefix(ocmHost, "http://")
return ocmHost, nil
func (a *authorizer) getOCMHost(providerDomain string) (string, error) {
providers, err := a.fetchAllProviders()
if err != nil {
return "", err
}
for _, p := range providers {
if p.Domain == providerDomain {
for _, s := range p.Services {
if s.Endpoint.Type.Name == "OCM" {
ocmHost, err := url.Parse(s.Host)
if err != nil {
return "", errors.Wrap(err, "json: error parsing OCM host URL")
}
return ocmHost.Host, nil
}
}
}
}
return "", errtypes.NotFound("OCM Host")
Expand Down

0 comments on commit c82e58c

Please sign in to comment.