Skip to content

Commit aa3fd3e

Browse files
authored
Merge pull request #153 from arangodb-helper/agency-redirect-fix
Fixed agency access
2 parents 436a406 + 488de21 commit aa3fd3e

File tree

7 files changed

+63
-24
lines changed

7 files changed

+63
-24
lines changed

service/client_builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ package service
2424

2525
import driver "github.com/arangodb/go-driver"
2626

27+
type ConnectionType int
28+
29+
const (
30+
ConnectionTypeDatabase ConnectionType = iota
31+
ConnectionTypeAgency
32+
)
33+
2734
// ClientBuilder is a callback used to create authenticated go-driver clients with or without
2835
// follow-redirect.
29-
type ClientBuilder func(endpoints []string, followRedirect bool) (driver.Client, error)
36+
type ClientBuilder func(endpoints []string, connectionType ConnectionType) (driver.Client, error)

service/cluster_config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,12 @@ func (p ClusterConfig) CreateAgencyAPI(clientBuilder ClientBuilder) (agency.Agen
283283
if err != nil {
284284
return nil, maskAny(err)
285285
}
286-
c, err := clientBuilder(endpoints, true)
286+
c, err := clientBuilder(endpoints, ConnectionTypeAgency)
287287
if err != nil {
288288
return nil, maskAny(err)
289289
}
290-
a, err := agency.NewAgency(c.Connection())
290+
conn := c.Connection()
291+
a, err := agency.NewAgency(conn)
291292
if err != nil {
292293
return nil, maskAny(err)
293294
}
@@ -301,7 +302,7 @@ func (p ClusterConfig) CreateClusterAPI(ctx context.Context, clientBuilder Clien
301302
if err != nil {
302303
return nil, maskAny(err)
303304
}
304-
c, err := clientBuilder(endpoints, true)
305+
c, err := clientBuilder(endpoints, ConnectionTypeDatabase)
305306
if err != nil {
306307
return nil, maskAny(err)
307308
}

service/peer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (p Peer) CreateDBServerAPI(clientBuilder ClientBuilder) (driver.Client, err
102102
port := p.Port + p.PortOffset + ServerType(ServerTypeDBServer).PortOffset()
103103
scheme := NewURLSchemes(p.IsSecure).Browser
104104
ep := fmt.Sprintf("%s://%s", scheme, net.JoinHostPort(p.Address, strconv.Itoa(port)))
105-
c, err := clientBuilder([]string{ep}, false)
105+
c, err := clientBuilder([]string{ep}, ConnectionTypeDatabase)
106106
if err != nil {
107107
return nil, maskAny(err)
108108
}
@@ -117,7 +117,7 @@ func (p Peer) CreateCoordinatorAPI(clientBuilder ClientBuilder) (driver.Client,
117117
port := p.Port + p.PortOffset + ServerType(ServerTypeCoordinator).PortOffset()
118118
scheme := NewURLSchemes(p.IsSecure).Browser
119119
ep := fmt.Sprintf("%s://%s", scheme, net.JoinHostPort(p.Address, strconv.Itoa(port)))
120-
c, err := clientBuilder([]string{ep}, false)
120+
c, err := clientBuilder([]string{ep}, ConnectionTypeDatabase)
121121
if err != nil {
122122
return nil, maskAny(err)
123123
}

service/runtime_cluster_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type runtimeClusterManagerContext interface {
6262
ChangeState(newState State)
6363

6464
// CreateClient returns go-driver client with authentication configured for the given endpoint.
65-
CreateClient(endpoint []string, followRedirect bool) (driver.Client, error)
65+
CreateClient(endpoint []string, connectionType ConnectionType) (driver.Client, error)
6666

6767
// UpdateClusterConfig updates the current cluster configuration.
6868
UpdateClusterConfig(ClusterConfig)

service/service.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040

4141
"github.com/arangodb-helper/arangodb/client"
4242
driver "github.com/arangodb/go-driver"
43+
"github.com/arangodb/go-driver/agency"
4344
driver_http "github.com/arangodb/go-driver/http"
4445
"github.com/arangodb/go-driver/jwt"
4546
logging "github.com/op/go-logging"
@@ -940,14 +941,24 @@ func (s *Service) PrepareDatabaseServerRequestFunc() func(*http.Request) error {
940941
}
941942

942943
// CreateClient creates a go-driver client with authentication for the given endpoints.
943-
func (s *Service) CreateClient(endpoints []string, followRedirect bool) (driver.Client, error) {
944-
conn, err := driver_http.NewConnection(driver_http.ConnectionConfig{
944+
func (s *Service) CreateClient(endpoints []string, connectionType ConnectionType) (driver.Client, error) {
945+
connConfig := driver_http.ConnectionConfig{
945946
Endpoints: endpoints,
946-
DontFollowRedirect: !followRedirect,
947+
DontFollowRedirect: connectionType == ConnectionTypeAgency,
947948
TLSConfig: &tls.Config{
948949
InsecureSkipVerify: true,
949950
},
950-
})
951+
}
952+
var conn driver.Connection
953+
var err error
954+
switch connectionType {
955+
case ConnectionTypeDatabase:
956+
conn, err = driver_http.NewConnection(connConfig)
957+
case ConnectionTypeAgency:
958+
conn, err = agency.NewAgencyConnection(connConfig)
959+
default:
960+
return nil, maskAny(fmt.Errorf("Unknown ConnectionType: %d", connectionType))
961+
}
951962
if err != nil {
952963
return nil, maskAny(err)
953964
}

service/upgrade_manager.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type UpgradeManagerContext interface {
5555
// ClusterConfig returns the current cluster configuration and the current peer
5656
ClusterConfig() (ClusterConfig, *Peer, ServiceMode)
5757
// CreateClient creates a go-driver client with authentication for the given endpoints.
58-
CreateClient(endpoints []string, followRedirect bool) (driver.Client, error)
58+
CreateClient(endpoints []string, connectionType ConnectionType) (driver.Client, error)
5959
// RestartServer triggers a restart of the server of the given type.
6060
RestartServer(serverType ServerType) error
6161
}
@@ -368,7 +368,7 @@ func (m *upgradeManager) isAgencyHealth(ctx context.Context) error {
368368
// Build agency clients
369369
clients := make([]driver.Connection, 0, len(endpoints))
370370
for _, ep := range endpoints {
371-
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
371+
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeAgency)
372372
if err != nil {
373373
return maskAny(err)
374374
}
@@ -392,7 +392,7 @@ func (m *upgradeManager) areDBServersResponding(ctx context.Context) error {
392392
}
393393
// Check all
394394
for _, ep := range endpoints {
395-
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
395+
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeDatabase)
396396
if err != nil {
397397
return maskAny(err)
398398
}
@@ -414,7 +414,7 @@ func (m *upgradeManager) areCoordinatorsResponding(ctx context.Context) error {
414414
}
415415
// Check all
416416
for _, ep := range endpoints {
417-
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
417+
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeDatabase)
418418
if err != nil {
419419
return maskAny(err)
420420
}
@@ -436,7 +436,7 @@ func (m *upgradeManager) areSingleServersResponding(ctx context.Context) error {
436436
}
437437
// Check all
438438
for _, ep := range endpoints {
439-
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
439+
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeDatabase)
440440
if err != nil {
441441
return maskAny(err)
442442
}
@@ -459,7 +459,7 @@ func (m *upgradeManager) isSuperVisionMaintenanceSupported(ctx context.Context)
459459
}
460460
// Check agents
461461
for _, ep := range endpoints {
462-
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
462+
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeAgency)
463463
if err != nil {
464464
return false, maskAny(err)
465465
}
@@ -546,7 +546,7 @@ func (m *upgradeManager) ShowArangodServerVersions(ctx context.Context) (bool, e
546546
showGroup := func(serverType ServerType, endpoints []string) {
547547
groupVersions := make([]string, len(endpoints))
548548
for i, ep := range endpoints {
549-
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, false)
549+
c, err := m.upgradeManagerContext.CreateClient([]string{ep}, ConnectionTypeDatabase)
550550
if err != nil {
551551
groupVersions[i] = "?"
552552
continue

vendor/github.com/arangodb/go-driver/agency/agency_connection.go

Lines changed: 26 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)