Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Riot support for list of QED IP addr #101

Merged
merged 1 commit into from
Apr 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions tests/riot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -107,7 +108,8 @@ paths:
$ref: '#/components/schemas/Config'
examples:
simple: {"kind": "add"}
advanced: {"kind": "incremental", "insecure":true, "endpoint": "https://qedserver.8800"}
advanced: {"kind": "incremental", "insecure":true, "endpoint": "https://qedserver:8800"}
advanced: {"kind": "incremental", "insecure":true, "endpoint": "https://qedserver0:8800,qedserver1:8801"}

/plan:
post:
Expand Down Expand Up @@ -175,7 +177,7 @@ type Riot struct {

type Config struct {
// general conf
Endpoint string
Endpoint []string
APIKey string
Insecure bool

Expand Down Expand Up @@ -259,7 +261,7 @@ func newRiotCommand() *cobra.Command {
f.StringVarP(&logLevel, "log", "l", "debug", "Choose between log levels: silent, error, info and debug")
f.BoolVar(&APIMode, "api", false, "Raise a HTTP api in port 7700")

f.StringVar(&riot.Config.Endpoint, "endpoint", "http://localhost:8800", "The endopoint to make the load")
f.StringSliceVarP(&riot.Config.Endpoint, "endpoint", "e", []string{"127.0.0.1:8800"}, "The endopoint to make the load")
f.StringVarP(&riot.Config.APIKey, "apikey", "k", "my-key", "The key to use qed servers")
f.BoolVar(&riot.Config.Insecure, "insecure", false, "Allow self-signed TLS certificates")

Expand Down Expand Up @@ -367,12 +369,18 @@ func (riot *Riot) Serve() {

func newAttack(conf Config) {

cConf := client.DefaultConfig()
cConf.Endpoints = []string{conf.Endpoint}
cConf.APIKey = conf.APIKey
cConf.Insecure = conf.Insecure
// QED client
transport := http.DefaultTransport.(*http.Transport)
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: conf.Insecure}
httpClient := http.DefaultClient
httpClient.Transport = transport
client, err := client.NewHTTPClient(
client.SetHttpClient(httpClient),
client.SetURLs(conf.Endpoint[0], conf.Endpoint[1:]...),
client.SetAPIKey(conf.APIKey),
client.SetReadPreference(client.Any),
)

client, err := client.NewHTTPClientFromConfig(cConf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client.NewHTTPClientFromConfig it's near to be dead code, since it had 2 usages AFAIK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's useful for testing.

if err != nil {
panic(err)
}
Expand Down