github.com/cs3org/reva/v2@v2.27.7/pkg/mentix/connectors/gocdb/query.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package gocdb 20 21 import ( 22 "fmt" 23 24 "github.com/cs3org/reva/v2/pkg/mentix/utils/network" 25 ) 26 27 // QueryGOCDB retrieves data from one of GOCDB's endpoints. 28 func QueryGOCDB(address string, method string, isPrivate bool, scope string, apiKey string, params network.URLParams) ([]byte, error) { 29 // The method must always be specified 30 params["method"] = method 31 32 // If a scope or an API key were specified, pass them to the endpoint as well 33 if len(scope) > 0 { 34 params["scope"] = scope 35 } 36 37 if len(apiKey) > 0 { 38 params["apikey"] = apiKey 39 } 40 41 // GOCDB's public API is located at <gocdb-host>/gocdbpi/public, the private one at <gocdb-host>/gocdbpi/private 42 var path string 43 if isPrivate { 44 path = "/gocdbpi/private" 45 } else { 46 path = "/gocdbpi/public" 47 } 48 49 // Query the data from GOCDB 50 endpointURL, err := network.GenerateURL(address, path, params) 51 if err != nil { 52 return nil, fmt.Errorf("unable to generate the GOCDB URL: %v", err) 53 } 54 55 data, err := network.ReadEndpoint(endpointURL, nil, true) 56 if err != nil { 57 return nil, fmt.Errorf("unable to read GOCDB endpoint: %v", err) 58 } 59 60 return data, nil 61 }