You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# if any credentials var then require all credentials vars
66
+
elif ('NETFOUNDRY_CLIENT_ID'inos.environ
67
+
or'NETFOUNDRY_PASSWORD'inos.environ
68
+
or'NETFOUNDRY_OAUTH_URL'inos.environ):
69
+
if ('NETFOUNDRY_CLIENT_ID'inos.environ
70
+
and'NETFOUNDRY_PASSWORD'inos.environ
71
+
and'NETFOUNDRY_OAUTH_URL'inos.environ):
72
+
client_id=os.environ['NETFOUNDRY_CLIENT_ID']
73
+
password=os.environ['NETFOUNDRY_PASSWORD']
74
+
token_endpoint=os.environ['NETFOUNDRY_OAUTH_URL']
75
+
else:
76
+
raiseException("ERROR: some but not all credentials vars present. Need NETFOUNDRY_CLIENT_ID, NETFOUNDRY_PASSWORD, and NETFOUNDRY_OAUTH_URL or a credentials file in default file locations or NETFOUNDRY_API_ACCOUNT as path to credentials file.")
65
77
else:
66
78
self.credentials="credentials.json"
67
79
68
-
# if no token or near expiry (30 min) then use credentials to obtain a token
80
+
# if no token or near expiry (30 min) then use env vars or credentials file to obtain a token
69
81
ifepochisNoneorepoch> (expiry-600):
70
-
# unless a valid path assume relative and search the default chain
71
-
ifnotos.path.exists(self.credentials):
72
-
default_creds_chain= [
73
-
{
74
-
"scope": "project",
75
-
"base": str(Path.cwd())
76
-
},
77
-
{
78
-
"scope": "user",
79
-
"base": str(Path.home())+"/.netfoundry"
80
-
},
81
-
{
82
-
"scope": "device",
83
-
"base": "/netfoundry"
84
-
}
85
-
]
86
-
forlinkindefault_creds_chain:
87
-
candidate=link['base']+"/"+self.credentials
88
-
ifos.path.exists(candidate):
89
-
print("INFO: using credentials in {path} (found in {scope}-default directory)".format(
90
-
scope=link['scope'],
91
-
path=candidate
92
-
))
93
-
self.credentials=candidate
94
-
break
95
-
else:
96
-
print("INFO: using credentials in {path}".format(
97
-
path=self.credentials
98
-
))
82
+
# if not creds as env vars then look for creds file
83
+
ifnotclient_idandpasswordandtoken_endpoint:
84
+
# unless a valid path assume relative and search the default chain
85
+
ifnotos.path.exists(self.credentials):
86
+
default_creds_chain= [
87
+
{
88
+
"scope": "project",
89
+
"base": str(Path.cwd())
90
+
},
91
+
{
92
+
"scope": "user",
93
+
"base": str(Path.home())+"/.netfoundry"
94
+
},
95
+
{
96
+
"scope": "device",
97
+
"base": "/netfoundry"
98
+
}
99
+
]
100
+
forlinkindefault_creds_chain:
101
+
candidate=link['base']+"/"+self.credentials
102
+
ifos.path.exists(candidate):
103
+
print("INFO: using credentials in {path} (found in {scope}-default directory)".format(
104
+
scope=link['scope'],
105
+
path=candidate
106
+
))
107
+
self.credentials=candidate
108
+
break
109
+
else:
110
+
print("INFO: using credentials in {path}".format(
111
+
path=self.credentials
112
+
))
113
+
114
+
try:
115
+
withopen(self.credentials) asfile:
116
+
try: account=json.load(file)
117
+
except: raiseException("ERROR: failed to load JSON from {file}".format(file=file))
118
+
except: raiseException("ERROR: failed to open {file} while working in {dir}".format(
119
+
file=self.credentials,dir=str(Path.cwd())))
120
+
token_endpoint=account['authenticationUrl']
121
+
client_id=account['clientId']
122
+
password=account['password']
99
123
100
-
try:
101
-
withopen(self.credentials) asfile:
102
-
try: account=json.load(file)
103
-
except: raiseException("ERROR: failed to load JSON from {file}".format(file=file))
104
-
except: raiseException("ERROR: failed to open {file} while working in {dir}".format(
105
-
file=self.credentials,dir=str(Path.cwd())))
106
-
token_endpoint=account['authenticationUrl']
107
-
client_id=account['clientId']
108
-
password=account['password']
109
124
# extract the environment name from the authorization URL aka token API endpoint
0 commit comments