55import json
66import os
77from base64 import b64decode
8+ from string import Template
89
910import pyunicore .client
1011import pyunicore .credentials
@@ -33,7 +34,8 @@ def _value(self, value: str):
3334 return True
3435 if value .lower () == "false" :
3536 return False
36- return value
37+ t = Template (value )
38+ return t .substitute (os .environ )
3739
3840 def load_user_properties (self ):
3941 with open (self .config_file ) as f :
@@ -43,7 +45,7 @@ def load_user_properties(self):
4345 continue
4446 try :
4547 key , value = line .split ("=" , 1 )
46- self .config [key ] = self ._value (value )
48+ self .config [key . strip () ] = self ._value (value . strip () )
4749 except ValueError :
4850 pass
4951
@@ -82,18 +84,31 @@ def get_group(self):
8284 return "Other"
8385
8486 def create_credential (self ):
85- auth_method = self .config .get ("authentication-method" , "USERNAME" ).upper ()
86- if "OIDC-AGENT" == auth_method :
87+ auth_method = self .config .get ("authentication-method" , "USERNAME" )
88+ _m = auth_method .upper ()
89+ if "OIDC-AGENT" == _m :
8790 account_name = self .config .get ("oidc-agent.account" )
8891 self .credential = pyunicore .credentials .OIDCAgentToken (account_name )
89- elif "OIDC-SERVER" == auth_method :
92+ elif "OIDC-SERVER" == _m :
9093 self .credential = pyunicore .credentials .OIDCServerToken (self .config )
91- elif "USERNAME" == auth_method :
94+ elif "USERNAME" == _m :
9295 username = self .config ["username" ]
9396 password = self ._get_password ()
9497 self .credential = pyunicore .credentials .create_credential (username , password )
95- elif "ANONYMOUS" == auth_method :
98+ elif "BEARER-TOKEN" == _m :
99+ token = self .config ["token" ]
100+ self .credential = pyunicore .credentials .BearerToken (token )
101+ elif "SSHKEY" == _m :
102+ username = self .config ["username" ]
103+ identity = self .config ["identity" ]
104+ password = self ._get_password ()
105+ self .credential = pyunicore .credentials .create_credential (
106+ username = username , password = password , identity = identity
107+ )
108+ elif "ANONYMOUS" == _m or "NONE" == _m :
96109 self .credential = pyunicore .credentials .Anonymous ()
110+ else :
111+ raise ValueError (f"No such authentication method: { auth_method } " )
97112
98113 def _get_password (self , key = "password" ) -> str :
99114 password = self .config .get (key )
0 commit comments