-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
- Loading branch information
Showing
3 changed files
with
118 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Inlets Author(s) 2019. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func getFileOrString(flags *pflag.FlagSet, file, value string, required bool) (string, error) { | ||
var val string | ||
fileVal, _ := flags.GetString(file) | ||
if len(fileVal) > 0 { | ||
res, err := ioutil.ReadFile(fileVal) | ||
if err != nil { | ||
return "", err | ||
} | ||
val = strings.TrimSpace(string(res)) | ||
} else { | ||
|
||
flagVal, err := flags.GetString(value) | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to get '"+value+"' value.") | ||
} | ||
val = flagVal | ||
} | ||
|
||
if required && len(val) == 0 { | ||
return "", fmt.Errorf("give a value for --%s or --%s", file, value) | ||
} | ||
|
||
return val, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Inlets Author(s) 2019. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_makeUserdata_InletsOSS(t *testing.T) { | ||
userData := makeUserdata("auth", inletsControlPort, "") | ||
|
||
wantUserdata := `#!/bin/bash | ||
export AUTHTOKEN="auth" | ||
export CONTROLPORT="8080" | ||
curl -sLS https://get.inlets.dev | sh | ||
curl -sLO https://raw.githubusercontent.com/inlets/inlets/master/hack/inlets-operator.service && \ | ||
mv inlets-operator.service /etc/systemd/system/inlets.service && \ | ||
echo "AUTHTOKEN=$AUTHTOKEN" > /etc/default/inlets && \ | ||
echo "CONTROLPORT=$CONTROLPORT" >> /etc/default/inlets && \ | ||
systemctl start inlets && \ | ||
systemctl enable inlets` | ||
|
||
if userData != wantUserdata { | ||
t.Errorf("want:\n%s\nbut got:\n%s", wantUserdata, userData) | ||
} | ||
} | ||
|
||
func Test_makeUserdata_InletsPro(t *testing.T) { | ||
userData := makeUserdata("auth", inletsProControlPort, "localhost") | ||
|
||
wantUserdata := `#!/bin/bash | ||
export AUTHTOKEN="auth" | ||
export REMOTETCP="localhost" | ||
export IP=$(curl -sfSL https://ifconfig.co) | ||
curl -SLsf https://github.com/inlets/inlets-pro/releases/download/0.4.3/inlets-pro > /tmp/inlets-pro && \ | ||
chmod +x /tmp/inlets-pro && \ | ||
mv /tmp/inlets-pro /usr/local/bin/inlets-pro | ||
curl -sLO https://raw.githubusercontent.com/inlets/inlets/master/hack/inlets-pro.service && \ | ||
mv inlets-pro.service /etc/systemd/system/inlets-pro.service && \ | ||
echo "AUTHTOKEN=$AUTHTOKEN" >> /etc/default/inlets-pro && \ | ||
echo "REMOTETCP=$REMOTETCP" >> /etc/default/inlets-pro && \ | ||
echo "IP=$IP" >> /etc/default/inlets-pro && \ | ||
systemctl start inlets-pro && \ | ||
systemctl enable inlets-pro` | ||
|
||
if userData != wantUserdata { | ||
t.Errorf("want: %s, but got: %s", wantUserdata, userData) | ||
} | ||
} |