You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2017/12/06 23:03:07 UTC

[kibble] 01/02: let sources API use the yaml for determining creds needed

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble.git

commit fce6b92498230a5d046d66cfa9efe5c1aaa2c1f2
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Dec 3 14:10:13 2017 +0100

    let sources API use the yaml for determining creds needed
    
    instead of hardcoding username, password etc, use the
    sourcetypes.yaml file for determining what may be needed.
    This also allows us to reject unknown source types.
---
 api/pages/sources.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/api/pages/sources.py b/api/pages/sources.py
index 0d08ea7..9e4856c 100644
--- a/api/pages/sources.py
+++ b/api/pages/sources.py
@@ -130,6 +130,7 @@ import json
 import re
 import time
 import hashlib
+import yaml
 
 def canModifySource(session):
     """ Determine if the user can edit sources in this org """
@@ -216,16 +217,17 @@ def run(API, environ, indata, session):
         if canModifySource(session):
             new = 0
             old = 0
+            stypes = yaml.load(open("yaml/sourcetypes.yaml"))
             for source in indata.get('sources', []):
                 sourceURL = source['sourceURL']
                 sourceType = source['type']
                 creds = {}
-                if 'username' in source and len(source['username']) > 0:
-                    creds['username'] = source['username']
-                if 'password' in source and len(source['password']) > 0:
-                    creds['password'] = source['password']
-                if 'cookie' in source and len(source['cookie']) > 0:
-                    creds['cookie'] = source['cookie']
+                if not sourceType in stypes:
+                    raise API.exception(400, "Attempt to add unknown source type!")
+                if 'optauth' in stypes[sourceType]:
+                    for el in stypes[sourceType]['optauth']:
+                        if el in source and len(source[el]) > 0:
+                            creds[el] = source[el]
                 sourceID = hashlib.sha224( ("%s-%s" % (sourceType, sourceURL)).encode('utf-8') ).hexdigest()
                 
                 dOrg = session.user['defaultOrganisation'] or "apache"

-- 
To stop receiving notification emails like this one, please contact
"commits@kibble.apache.org" <co...@kibble.apache.org>.