-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
187 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../core/pythonAction/cli/wskadmin | ||
../tools/admin/wskadmin |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python | ||
|
||
# | ||
# Copyright 2015-2016 IBM Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
## | ||
# Helper methods for whisk properties | ||
## | ||
|
||
import os | ||
import pkg_resources | ||
|
||
def propfile(base): | ||
if base != '': | ||
filename = '%s/whisk.properties' % base | ||
if os.path.isfile(filename) and os.path.exists(filename): | ||
return filename | ||
else: | ||
parent = os.path.dirname(base) | ||
return propfile(parent) if parent != base else '' | ||
else: | ||
return '' | ||
|
||
def importPropsIfAvailable(filename): | ||
thefile = open(filename, 'r') if os.path.isfile(filename) and os.path.exists(filename) else [] | ||
return importProps(thefile) | ||
|
||
def importProps(stream): | ||
props = {} | ||
for line in stream: | ||
parts = line.split('=') | ||
if len(parts) >= 1: | ||
key = parts[0].strip() | ||
if len(parts) >= 2: | ||
val = parts[1].strip() | ||
if key != '' and val != '': | ||
props[key.upper().replace('.','_')] = val | ||
elif key != '': | ||
props[key.upper().replace('.','_')] = '' | ||
return props | ||
|
||
# | ||
# Returns a triple of (length(requiredProperties), requiredProperties, deferredInfo) | ||
# prints a message if a required property is not found | ||
# | ||
def checkRequiredProperties(requiredPropertiesByName, properties): | ||
requiredPropertiesByValue = [ getPropertyValue(key, properties) for key in requiredPropertiesByName ] | ||
requiredProperties = dict(zip(requiredPropertiesByName, requiredPropertiesByValue)) | ||
invalidProperties = [ key for key in requiredPropertiesByName if requiredProperties[key] == None ] | ||
deferredInfo = '' | ||
for key, value in requiredProperties.items(): | ||
if value == None or value == '': | ||
print 'property "%s" not found in environment or property file' % key | ||
else: | ||
deferredInfo += 'using %(key)s = %(value)s\n' % {'key': key, 'value': value} | ||
return (len(invalidProperties) == 0, requiredProperties, deferredInfo) | ||
|
||
def getPropertyValue(key, properties): | ||
evalue = os.environ.get(key) | ||
value = evalue if evalue != None and evalue != '' else properties[key] if key in properties else None | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# | ||
# Copyright 2015-2016 IBM Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import sys | ||
import os | ||
import json | ||
import httplib | ||
import ssl | ||
import base64 | ||
from urlparse import urlparse | ||
|
||
# global configurations, can control whether to allow untrusted certificates on HTTPS connections | ||
httpRequestProps = { 'secure': True } | ||
|
||
def request(method, urlString, body = '', headers = {}, auth = None, verbose = False, https_proxy = os.getenv('https_proxy', None)): | ||
url = urlparse(urlString) | ||
if url.scheme == 'http': | ||
conn = httplib.HTTPConnection(url.netloc) | ||
else: | ||
if httpRequestProps['secure'] or not hasattr(ssl, '_create_unverified_context'): | ||
conn = httplib.HTTPSConnection(url.netloc if https_proxy is None else https_proxy) | ||
else: | ||
conn = httplib.HTTPSConnection(url.netloc if https_proxy is None else https_proxy, context=ssl._create_unverified_context()) | ||
if https_proxy: | ||
conn.set_tunnel(url.netloc) | ||
|
||
if auth != None: | ||
auth = base64.encodestring(auth).replace('\n', '') | ||
headers['Authorization'] = 'Basic %s' % auth | ||
|
||
if verbose: | ||
print '========' | ||
print 'REQUEST:' | ||
print '%s %s' % (method, urlString) | ||
print 'Headers sent:' | ||
print getPrettyJson(headers) | ||
if body != '': | ||
print 'Body sent:' | ||
print body | ||
|
||
try: | ||
conn.request(method, urlString, body, headers) | ||
res = conn.getresponse() | ||
body = '' | ||
try: | ||
body = res.read() | ||
except httplib.IncompleteRead as e: | ||
body = e.partial | ||
|
||
# patch the read to return just the body since the normal read | ||
# can only be done once | ||
res.read = lambda: body | ||
|
||
if verbose: | ||
print '--------' | ||
print 'RESPONSE:' | ||
print 'Got response with code %s' % res.status | ||
print 'Body received:' | ||
print res.read() | ||
print '========' | ||
return res | ||
except Exception, e: | ||
res = dict2obj({ 'status' : 500, 'error': str(e) }) | ||
return res | ||
|
||
def getPrettyJson(obj): | ||
return json.dumps(obj, sort_keys=True, indent=4, separators=(',', ': ')) | ||
|
||
# class to convert dictionary to objects | ||
class dict2obj(dict): | ||
def __getattr__(self, name): | ||
if name in self: | ||
return self[name] | ||
else: | ||
raise AttributeError('object has no attribute "%s"' % name) | ||
|
||
def __setattr__(self, name, value): | ||
self[name] = value | ||
|
||
def __delattr__(self, name): | ||
if name in self: | ||
del self[name] | ||
else: | ||
raise AttributeError('object has no attribute "%s"' % name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters