Skip to content

Commit a60a98b

Browse files
committed
device/jita: block when opening URLs
1 parent 9f2f63b commit a60a98b

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

cmd/devicecmd/jitacmd.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/nais/cli/pkg/naisdevice"
87
"github.com/urfave/cli/v2"
98
"k8s.io/utils/strings/slices"
9+
10+
"github.com/nais/cli/pkg/naisdevice"
1011
)
1112

1213
func jitaCommand() *cli.Command {
@@ -33,8 +34,7 @@ func jitaCommand() *cli.Command {
3334
},
3435
Action: func(context *cli.Context) error {
3536
gateway := context.Args().First()
36-
naisdevice.AccessPrivilegedGateway(gateway)
37-
return nil
37+
return naisdevice.AccessPrivilegedGateway(gateway)
3838
},
3939
}
4040
}

pkg/naisdevice/jita.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/nais/device/pkg/device-agent/open"
87
"github.com/nais/device/pkg/pb"
8+
9+
"github.com/nais/cli/pkg/urlopen"
910
)
1011

11-
func AccessPrivilegedGateway(gatewayName string) {
12-
open.Open(fmt.Sprintf("https://naisdevice-jita.external.prod-gcp.nav.cloud.nais.io/?gateway=%s", gatewayName))
12+
func AccessPrivilegedGateway(gatewayName string) error {
13+
url := fmt.Sprintf("https://naisdevice-jita.external.prod-gcp.nav.cloud.nais.io/?gateway=%s", gatewayName)
14+
err := urlopen.Open(url)
15+
if err != nil {
16+
return fmt.Errorf("unable to open your browser, please open this manually: %s", url)
17+
}
18+
return nil
1319
}
1420

1521
func GetPrivilegedGateways(ctx context.Context) ([]string, error) {

pkg/urlopen/open.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package urlopen

pkg/urlopen/open_darwin.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package urlopen
2+
3+
import (
4+
"os/exec"
5+
)
6+
7+
func Open(url string) error {
8+
return exec.Command("open", url).Run()
9+
}

pkg/urlopen/open_linux.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package urlopen
2+
3+
import (
4+
"os/exec"
5+
)
6+
7+
func Open(url string) error {
8+
return exec.Command("xdg-open", url).Run()
9+
}

pkg/urlopen/open_windows.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package urlopen
2+
3+
import (
4+
"os/exec"
5+
)
6+
7+
func Open(url string) error {
8+
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Run()
9+
}

0 commit comments

Comments
 (0)