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
MYST 361: add -discovery-address and -broker-address command line options #172
Changes from 2 commits
165b9bd
3df88d7
58ae6d5
e6fbb7d
f75ce0a
bd4d4ac
41a53ab
6791b53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#!/bin/bash | ||
|
||
sudo ./build/client/mysterium_client --config-dir=bin/client_package/config --runtime-dir=build/client $@ | ||
source bin/helpers/load_run_environment.sh | ||
|
||
sudo ./build/client/mysterium_client \ | ||
--config-dir=bin/client_package/config \ | ||
--runtime-dir=build/client \ | ||
$DISCOVERY \ | ||
$@ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
function get_linker_ldflags { | ||
echo " | ||
-X 'github.com/mysterium/node/server.mysteriumApiUrl=${MYSTERIUM_API_URL}' | ||
-X 'github.com/mysterium/node/communication/nats/discovery.natsServerIP=${NATS_SERVER_IP}' | ||
-X 'github.com/mysterium/node/server.natsServerIP=${NATS_SERVER_IP}' | ||
-X 'github.com/mysterium/node/client.mysteriumApiUrl=${MYSTERIUM_API_URL}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its in different packages. to remove duplication I could make it public.. |
||
" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
if [ -f .env ]; then | ||
source .env | ||
|
||
[ -n "$MYSTERIUM_API_URL" ] && DISCOVERY="-discovery-address=$MYSTERIUM_API_URL" | ||
[ -n "$NATS_SERVER_IP" ] && BROKER="-broker-address=$NATS_SERVER_IP" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't too dashes common practice for key-value params?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, but its true for all options. Legacy. |
||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
#!/bin/bash | ||
|
||
sudo ./build/server/mysterium_server --config-dir=bin/server_package/config --runtime-dir=build/server $@ | ||
source bin/helpers/load_run_environment.sh | ||
|
||
sudo ./build/server/mysterium_server \ | ||
--config-dir=bin/server_package/config \ | ||
--runtime-dir=build/server \ | ||
$DISCOVERY \ | ||
$BROKER \ | ||
$@ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,16 @@ type CommandOptions struct { | |
|
||
LocationCountry string | ||
LocationDatabase string | ||
|
||
DiscoveryAPIAddress string | ||
BrokerAddress string | ||
} | ||
|
||
const defaultLocationDatabase = "GeoLite2-Country.mmdb" | ||
|
||
var mysteriumApiUrl string | ||
var natsServerIP string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// ParseArguments parses CLI flags and adds to CommandOptions structure | ||
func ParseArguments(args []string) (options CommandOptions, err error) { | ||
flags := flag.NewFlagSet(args[0], flag.ContinueOnError) | ||
|
@@ -69,6 +75,19 @@ func ParseArguments(args []string) (options CommandOptions, err error) { | |
"Service location country. If not given country is autodetected", | ||
) | ||
|
||
flags.StringVar( | ||
&options.DiscoveryAPIAddress, | ||
"discovery-address", | ||
mysteriumApiUrl, | ||
"Address (URL form) of discovery service", | ||
) | ||
flags.StringVar( | ||
&options.BrokerAddress, | ||
"broker-address", | ||
natsServerIP, | ||
"Address (IP or domain name) of message broker", | ||
) | ||
|
||
err = flags.Parse(args[1:]) | ||
if err != nil { | ||
return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,22 +15,20 @@ const ( | |
authenticationSchemaName = "Signature" | ||
) | ||
|
||
var mysteriumApiUrl string | ||
|
||
func newGetRequest(path string, params url.Values) (*http.Request, error) { | ||
func newGetRequest(apiURI, path string, params url.Values) (*http.Request, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about this place, since its functions and not member methods we should not depend on internal state. Should we hardcoded in apiURI, can it be considered a state or never changing constant.. |
||
pathWithQuery := fmt.Sprintf("%v?%v", path, params.Encode()) | ||
return newRequest(http.MethodGet, pathWithQuery, nil) | ||
return newRequest(http.MethodGet, apiURI, pathWithQuery, nil) | ||
} | ||
|
||
func newPostRequest(path string, requestBody interface{}) (*http.Request, error) { | ||
func newPostRequest(apiURI, path string, requestBody interface{}) (*http.Request, error) { | ||
bodyBytes, err := encodeToJSON(requestBody) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return newRequest(http.MethodPost, path, bodyBytes) | ||
return newRequest(http.MethodPost, apiURI, path, bodyBytes) | ||
} | ||
|
||
func newSignedPostRequest(path string, requestBody interface{}, signer identity.Signer) (*http.Request, error) { | ||
func newSignedPostRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error) { | ||
bodyBytes, err := encodeToJSON(requestBody) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -41,7 +39,7 @@ func newSignedPostRequest(path string, requestBody interface{}, signer identity. | |
return nil, err | ||
} | ||
|
||
req, err := newRequest(http.MethodPost, path, bodyBytes) | ||
req, err := newRequest(http.MethodPost, apiURI, path, bodyBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -55,9 +53,9 @@ func encodeToJSON(value interface{}) ([]byte, error) { | |
return json.Marshal(value) | ||
} | ||
|
||
func newRequest(method, path string, body []byte) (*http.Request, error) { | ||
func newRequest(method, apiURI, path string, body []byte) (*http.Request, error) { | ||
|
||
fullUrl := fmt.Sprintf("%v/%v", mysteriumApiUrl, path) | ||
fullUrl := fmt.Sprintf("%v/%v", apiURI, path) | ||
req, err := http.NewRequest(method, fullUrl, bytes.NewBuffer(body)) | ||
if err != nil { | ||
return nil, err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ type mockedSigner struct { | |
signatureToReturn identity.Signature | ||
} | ||
|
||
var testMysteriumApiUrl = "http://testUrl" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't depend that url is |
||
|
||
func (signer *mockedSigner) Sign(message []byte) (identity.Signature, error) { | ||
return signer.signatureToReturn, nil | ||
} | ||
|
@@ -25,19 +27,18 @@ func TestSignatureIsInsertedForSignedPost(t *testing.T) { | |
|
||
signer := mockedSigner{identity.SignatureBase64("deadbeef")} | ||
|
||
req, err := newSignedPostRequest("/post-path", testPayload{"abc"}, &signer) | ||
req, err := newSignedPostRequest(testMysteriumApiUrl, "/post-path", testPayload{"abc"}, &signer) | ||
assert.NoError(t, err) | ||
assert.Equal(t, req.Header.Get("Authorization"), "Signature deadbeef") | ||
} | ||
|
||
func TestDoGetContactsPassedValuesForUrl(t *testing.T) { | ||
mysteriumApiUrl = "http://testUrl" | ||
|
||
params := url.Values{} | ||
params["param1"] = []string{"value1"} | ||
params["param2"] = []string{"value2"} | ||
|
||
req, err := newGetRequest("get-path", params) | ||
req, err := newGetRequest(testMysteriumApiUrl, "get-path", params) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, "http://testUrl/get-path?param1=value1¶m2=value2", req.URL.String()) | ||
|
@@ -46,7 +47,7 @@ func TestDoGetContactsPassedValuesForUrl(t *testing.T) { | |
|
||
func TestPayloadIsSerializedSuccessfullyForPostMethod(t *testing.T) { | ||
|
||
req, err := newPostRequest("post-path", testPayload{"abc"}) | ||
req, err := newPostRequest(testMysteriumApiUrl, "post-path", testPayload{"abc"}) | ||
|
||
assert.NoError(t, err) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this param be passed in docker-entrypoints as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it depends from environment we want to build for.. we should compile in for testnet and only for development to show our own discovery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is is passed now