Skip to content

Commit

Permalink
Add API key to Mentix GOCDB connector (cs3org#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-WWU-IT authored and tmourati committed Jul 12, 2021
1 parent ee6e0cc commit f5a65ae
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/add-gocdb-apikey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add API key to Mentix GOCDB connector

The PI (programmatic interface) of the GOCDB will soon require an API key; this PR adds the ability to configure this key in Mentix.

https://github.com/cs3org/reva/pull/1834
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ The scope to use for filtering sites and services.
scope = "SM"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="apikey" type="string" default="" %}}
The API key to use for the GOCDB PI.
{{< highlight toml >}}
[http.services.mentix.connectors.gocdb]
apikey = "abc123"
{{< /highlight >}}
{{% /dir %}}
1 change: 1 addition & 0 deletions examples/mentix/mentix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ update_interval = "15m"

[http.services.mentix.connectors.gocdb]
address = "http://sciencemesh-test.uni-muenster.de"
apikey = "abc123"

# Sites can also be stored in a local file
[http.services.mentix.connectors.localfile]
Expand Down
1 change: 1 addition & 0 deletions pkg/mentix/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Configuration struct {
GOCDB struct {
Address string `mapstructure:"address"`
Scope string `mapstructure:"scope"`
APIKey string `mapstructure:"apikey"`
} `mapstructure:"gocdb"`

LocalFile struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mentix/connectors/gocdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (connector *GOCDBConnector) query(v interface{}, method string, isPrivate b
}

// Get the data from GOCDB
data, err := gocdb.QueryGOCDB(connector.gocdbAddress, method, isPrivate, scope, params)
data, err := gocdb.QueryGOCDB(connector.gocdbAddress, method, isPrivate, scope, connector.conf.Connectors.GOCDB.APIKey, params)
if err != nil {
return err
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/mentix/connectors/gocdb/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ import (
)

// QueryGOCDB retrieves data from one of GOCDB's endpoints.
func QueryGOCDB(address string, method string, isPrivate bool, scope string, params network.URLParams) ([]byte, error) {
func QueryGOCDB(address string, method string, isPrivate bool, scope string, apiKey string, params network.URLParams) ([]byte, error) {
// The method must always be specified
params["method"] = method

// If a scope was specified, pass it to the endpoint as well
// If a scope or an API key were specified, pass them to the endpoint as well
if len(scope) > 0 {
params["scope"] = scope
}

if len(apiKey) > 0 {
params["apikey"] = apiKey
}

// GOCDB's public API is located at <gocdb-host>/gocdbpi/public, the private one at <gocdb-host>/gocdbpi/private
var path string
if isPrivate {
Expand All @@ -48,6 +52,7 @@ func QueryGOCDB(address string, method string, isPrivate bool, scope string, par
return nil, fmt.Errorf("unable to generate the GOCDB URL: %v", err)
}

fmt.Println(endpointURL.String())
data, err := network.ReadEndpoint(endpointURL, nil, true)
if err != nil {
return nil, fmt.Errorf("unable to read GOCDB endpoint: %v", err)
Expand Down

0 comments on commit f5a65ae

Please sign in to comment.