Skip to content

Commit 53281d8

Browse files
committed
simplify the binary location
1 parent c5c9c56 commit 53281d8

File tree

4 files changed

+15
-36
lines changed

4 files changed

+15
-36
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
/coverage.*
33
console
44
/awsmocks
5-
dist
5+
dist
6+
awscli-console-plugin
7+
awscli_console_plugin.egg-info/
8+
build/

console.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"os"
8-
"os/exec"
98
"strconv"
109

1110
"github.com/aws/aws-sdk-go/aws"
@@ -17,6 +16,7 @@ import (
1716

1817
"github.com/alecthomas/kong"
1918
"github.com/aws/aws-sdk-go/aws/session"
19+
"github.com/skratchdot/open-golang/open"
2020
)
2121

2222
type Context struct {
@@ -80,17 +80,12 @@ func (cli *Console) consoleURL(signinToken string, destinationURL string) string
8080
return consoleURL.String()
8181
}
8282

83-
// Credentials will only work with one of the latest versions of the AWS Go SDK (see go.mod)
84-
// 1.40.26 was found to work. Versions < 1.40.x would not read profiles that were kept in
85-
// ~/.aws/config but only looked at ~/.aws/credentials
8683
func (cli *Console) Credentials(profile string) (credentials.Value, string, error) {
8784
var sess *session.Session
8885

8986
if profile != "" {
9087
sess = session.Must(session.NewSessionWithOptions(session.Options{
9188
Profile: profile,
92-
// according to some otherwise unrelated Github Issue
93-
SharedConfigState: session.SharedConfigEnable,
9489
}))
9590
} else {
9691
sess = session.Must(session.NewSessionWithOptions(session.Options{
@@ -145,19 +140,9 @@ func (cli *Console) Run(ctx *Context) error {
145140
return nil
146141
}
147142

148-
// Have to run the browser "by hand", because of a discovered issues with AWS CLI v2 env vars
149-
c := exec.Command("xdg-open", consoleURL)
150-
// This is set somewhere in the framework to only the AWS CLI V2 dist path
151-
// to the exclusion of everything else.
152-
os.Unsetenv("LD_LIBRARY_PATH")
153-
c.Env = os.Environ()
154-
out, err := c.Output()
143+
err = open.Run(consoleURL)
155144
if err != nil {
156-
if string(out) == "" {
157-
e := err.(*exec.ExitError)
158-
out = e.Stderr
159-
}
160-
return fmt.Errorf("error while opening browser, %s", out)
145+
return fmt.Errorf("error while opening browser, %s", err)
161146
}
162147

163148
return nil

console.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,11 @@ def _call(self, options, parsed_globals):
5555
"""Run the command."""
5656
cmd = []
5757

58-
# miserable hack because there are issue with AWS CLI V2 which causes this plugin to not find site.py
59-
if found_site:
60-
bin = os.path.join(site.USER_BASE, 'bin', 'awscli-console-plugin')
61-
if not os.path.isfile(bin):
62-
bin = os.path.join(sys.prefix, 'bin', 'awscli-console-plugin')
63-
else:
64-
bin = os.path.join(sys.prefix, 'bin', 'awscli-console-plugin')
65-
if not os.path.isfile(bin):
66-
# in addition when using pyenv, the Go executable will be installed somewhere among the shims
67-
# instead of a "normal" location
68-
if os.environ['PYENV_ROOT']:
69-
bin = os.path.join(os.environ['PYENV_ROOT'], 'shims', 'awscli-console-plugin')
58+
side_packages = os.path.dirname(os.path.realpath(__file__))
59+
try:
60+
bin = os.path.join(side_packages, 'awscli-console-plugin', 'awscli-console-plugin')
61+
except Exception as e:
62+
print('executable is not found at {}'.format(bin))
7063

7164
cmd.append(bin)
7265

setup.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from setuptools import setup
2+
import sysconfig
23

34
setup(
45
name='awscli-console-plugin',
56
version='0.1',
67
py_modules=['console'],
7-
data_files=[('bin', ['./awscli-console-plugin'])],
8-
install_requires=[
9-
'awscli',
10-
],
8+
data_files=[('/awscli-console-plugin', ['./awscli-console-plugin'])],
119
classifiers=[
1210
"Programming Language :: Python :: 3",
1311
"License :: OSI Approved :: MIT License",
@@ -17,5 +15,5 @@
1715
author="Bernard Baltrusaitis",
1816
author_email="bernard@runawaylover.info",
1917
description="AWSCLI plugin to login to AWS Console using your IAM credentials",
20-
python_requires='>=3.6',
18+
python_requires='>=3.6'
2119
)

0 commit comments

Comments
 (0)