Skip to content

Commit

Permalink
fix env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroZ committed Dec 20, 2016
1 parent ca64d7a commit df361fe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
2 changes: 2 additions & 0 deletions Windows/laZagne.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ def set_env_variables(user = getpass.getuser(), toImpersonate = False):
constant.profile['HOMEDRIVE'] = os.environ.get('HOMEDRIVE', 'C:')
constant.profile['HOMEPATH'] = os.environ.get('HOMEPATH', 'C:\\Users\\%s' % user)
constant.profile['ALLUSERSPROFILE'] = os.environ.get('ALLUSERSPROFILE', 'C:\\ProgramData')
constant.profile['COMPOSER_HOME'] = os.environ.get('COMPOSER_HOME', 'C:\\Users\\%s\\AppData\\Roaming\\Composer\\' % user)
else:
constant.profile['APPDATA'] = 'C:\\Users\\%s\\AppData\\Roaming\\' % user
constant.profile['USERPROFILE'] = 'C:\\Users\\%s\\' % user
constant.profile['HOMEPATH'] = 'C:\\Users\\%s' % user
constant.profile['COMPOSER_HOME'] = 'C:\\Users\\%s\\AppData\\Roaming\\Composer\\' % user

# Used to print help menu when an error occurs
class MyParser(argparse.ArgumentParser):
Expand Down
3 changes: 2 additions & 1 deletion Windows/lazagne/config/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class constant():
'USERPROFILE': '',
'HOMEDRIVE': '',
'HOMEPATH': '',
'ALLUSERSPROFILE': ''
'ALLUSERSPROFILE': '',
'COMPOSER_HOME': ''
}
username = ''
Empty file modified Windows/lazagne/softwares/php/__init__.py
100644 → 100755
Empty file.
53 changes: 27 additions & 26 deletions Windows/lazagne/softwares/php/composer.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@ def extract_credentials(self, location):
:return: List of credentials founds
"""
creds_found = []

if os.path.isfile(location):
with open(location) as f:
creds = json.load(f)
for cred_type in creds:
for domain in creds[cred_type]:
values = {}
values["AuthenticationType"] = cred_type
values["Domain"] = domain
# Extract basic authentication if we are on a "http-basic" section
# otherwise extract authentication token
if cred_type == "http-basic":
values["Login"] = creds[cred_type][domain]["username"]
values["Password"] = creds[cred_type][domain]["password"]
else:
values["Password"] = creds[cred_type][domain]
creds_found.append(values)
with open(location) as f:
creds = json.load(f)
for cred_type in creds:
for domain in creds[cred_type]:
values = {}
values["AuthenticationType"] = cred_type
values["Domain"] = domain
# Extract basic authentication if we are on a "http-basic" section
# otherwise extract authentication token
if cred_type == "http-basic":
values["Login"] = creds[cred_type][domain]["username"]
values["Password"] = creds[cred_type][domain]["password"]
else:
values["Password"] = creds[cred_type][domain]
creds_found.append(values)

return creds_found

Expand All @@ -45,12 +43,15 @@ def run(self, software_name=None):
# Define the possible full path of the "auth.json" file when is defined at global level
# See "https://getcomposer.org/doc/articles/http-basic-authentication.md"
# See "https://seld.be/notes/authentication-management-in-composer"
if "COMPOSER_HOME" in os.environ:
location = os.environ.get("COMPOSER_HOME") + "\\auth.json"
else:
location = os.environ.get("APPDATA") + "\\Composer\\auth.json"

# Extract the credentials
creds_found = self.extract_credentials(location)

return creds_found
location = ''
tmp_location = [
constant.profile["COMPOSER_HOME"] + "\\auth.json",
constant.profile["APPDATA"] + "\\Composer\\auth.json"
]
for tmp in tmp_location:
if os.path.isfile(tmp):
location = tmp
break

if location:
return self.extract_credentials(location)

0 comments on commit df361fe

Please sign in to comment.