Skip to content

Commit

Permalink
Add extractor for PHP Composer credentials when they are defined at g…
Browse files Browse the repository at this point in the history
…lobal level
  • Loading branch information
righettod committed Dec 10, 2016
1 parent 749eb66 commit 51409a4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Windows/lazagne/config/manageModules.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
# memory
from lazagne.softwares.memory.keepass import Keepass
from lazagne.softwares.memory.memorydump import MemoryDump
# php
from lazagne.softwares.php.composer import Composer

def get_categories():
category = {
Expand All @@ -52,6 +54,7 @@ def get_categories():
'svn': {'help': 'SVN clients supported'},
'git': {'help': 'GIT clients supported'},
'maven': {'help': 'Maven java build tool'},
'php': {'help': 'PHP build tool'},
'mails': {'help': 'Email clients supported'},
'memory': {'help': 'Retrieve passwords from memory'},
'wifi': {'help': 'Wifi'},
Expand Down Expand Up @@ -95,6 +98,7 @@ def get_modules():
Squirrel(),
Turba(),
Wifi(),
WinSCP()
WinSCP(),
Composer()
]
return moduleNames
Empty file.
56 changes: 56 additions & 0 deletions Windows/lazagne/softwares/php/composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import json
from lazagne.config.constant import *
from lazagne.config.moduleInfo import ModuleInfo

class Composer(ModuleInfo):

def __init__(self):
options = {'command': '-phpcomp', 'action': 'store_true', 'dest': 'composer', 'help': 'PHP Composer'}
ModuleInfo.__init__(self, 'composer', 'php', options)

def extract_credentials(self, location):
"""
Extract the credentials from the "auth.json" file.
See "https://getcomposer.org/doc/articles/http-basic-authentication.md" for file format.
:param location: Full path to the "auth.json" file
: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)

return creds_found

def run(self, software_name=None):
"""
Main function
"""

# 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

0 comments on commit 51409a4

Please sign in to comment.