Skip to content
Snippets Groups Projects
Commit 9c88e1a1 authored by thijsheijden's avatar thijsheijden
Browse files

Updated arango request code

The request function now requires database credentials instead of using
hardcoded values.
parent 26498529
No related branches found
No related tags found
No related merge requests found
......@@ -4,5 +4,5 @@ import "query-service/internal/entity"
// UseCase is an interface describing the request usecases
type UseCase interface {
SendAQLQuery(query string) (*map[string][]entity.Document, error)
SendAQLQuery(query string, username string, password string, hostname string, port int, database string) (*map[string][]entity.Document, error)
}
......@@ -3,8 +3,8 @@ package request
import (
"context"
"crypto/tls"
"fmt"
"log"
"os"
"query-service/internal/entity"
"encoding/json"
......@@ -26,12 +26,10 @@ Parameters: AQLQuery is a string containing the query that will be send to the d
Return: a map with two entries: "nodes" with a list of vertices/nodes and "edges" with a list of edges
that will be returned to the frontend
*/
func (s *Service) SendAQLQuery(AQLQuery string) (*map[string][]entity.Document, error) {
// Get ArangoDB url from environment variable
arangoURL := os.Getenv("ARANGO_HOST")
func (s *Service) SendAQLQuery(query string, username string, password string, hostname string, port int, database string) (*map[string][]entity.Document, error) {
var queryResult = make(map[string][]entity.Document)
conn, err := http.NewConnection(http.ConnectionConfig{
Endpoints: []string{arangoURL},
Endpoints: []string{fmt.Sprintf("%s:%d", hostname, port)},
TLSConfig: &tls.Config{InsecureSkipVerify: true},
})
if err != nil {
......@@ -40,7 +38,7 @@ func (s *Service) SendAQLQuery(AQLQuery string) (*map[string][]entity.Document,
}
c, err := driver.NewClient(driver.ClientConfig{
Connection: conn,
Authentication: driver.BasicAuthentication("root", "DikkeDraak"),
Authentication: driver.BasicAuthentication(username, password),
})
if err != nil {
log.Println("Could not log in to the ArangoDB") // Handle error
......@@ -48,14 +46,14 @@ func (s *Service) SendAQLQuery(AQLQuery string) (*map[string][]entity.Document,
}
ctx := context.Background()
db, err := c.Database(ctx, "_system")
db, err := c.Database(ctx, database)
if err != nil {
// handle error
log.Println(err)
return nil, err
}
cursor, err := db.Query(ctx, AQLQuery, nil)
cursor, err := db.Query(ctx, query, nil)
if err != nil {
log.Println("Invalid query") // handle error
return nil, err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment