ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject incubator-ranger git commit: RANGER-440 : Add credential helper python file
Date Thu, 30 Apr 2015 16:55:43 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master 218d05ba8 -> 2ba2a2e58


RANGER-440 : Add credential helper python file

Signed-off-by: Velmurugan Periasamy <vel@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/2ba2a2e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/2ba2a2e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/2ba2a2e5

Branch: refs/heads/master
Commit: 2ba2a2e581cb2e6afd1bc288d26fdc8ef369d55c
Parents: 218d05b
Author: Gautam Borad <gborad@gmail.com>
Authored: Thu Apr 30 20:22:44 2015 +0530
Committer: Velmurugan Periasamy <vel@apache.org>
Committed: Thu Apr 30 12:55:23 2015 -0400

----------------------------------------------------------------------
 .../scripts/ranger_credential_helper.py         | 69 ++++++++++++++++++++
 src/main/assembly/admin-web.xml                 |  1 +
 2 files changed, 70 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/2ba2a2e5/security-admin/scripts/ranger_credential_helper.py
----------------------------------------------------------------------
diff --git a/security-admin/scripts/ranger_credential_helper.py b/security-admin/scripts/ranger_credential_helper.py
new file mode 100644
index 0000000..f195bc0
--- /dev/null
+++ b/security-admin/scripts/ranger_credential_helper.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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
+from subprocess import  Popen,PIPE
+from optparse import OptionParser
+
+
+def main():
+
+	parser = OptionParser()
+
+	parser.add_option("-l", "--libpath", dest="library_path", help="Path to folder where credential
libs are present")
+	parser.add_option("-f", "--file",  dest="jceks_file_path", help="Path to jceks file to use")
+	parser.add_option("-k", "--key",  dest="key", help="Key to use")
+	parser.add_option("-v", "--value",  dest="value", help="Value to use")
+	parser.add_option("-c", "--create",  dest="create", help="Add a new alias")
+
+	(options, args) = parser.parse_args()
+	library_path = options.library_path
+	jceks_file_path = options.jceks_file_path
+	key = options.key
+	value = options.value
+	getorcreate = 'create' if options.create else 'get'
+	call_keystore(library_path, jceks_file_path, key, value, getorcreate)
+
+
+def call_keystore(libpath, filepath, aliasKey, aliasValue='', getorcreate='get'):
+	finalLibPath = libpath.replace('\\','/').replace('//','/')
+	finalFilePath = 'jceks://file/'+filepath.replace('\\','/').replace('//','/')
+	if getorcreate == 'create':
+		commandtorun = ['java', '-cp', finalLibPath, 'org.apache.ranger.credentialapi.buildks'
,'create', aliasKey, '-value', aliasValue, '-provider',finalFilePath]
+		p = Popen(commandtorun,stdin=PIPE, stdout=PIPE, stderr=PIPE)
+		output, error = p.communicate()
+		statuscode = p.returncode
+		if statuscode == 0:
+			print "Alias " + aliasKey + " created successfully!"
+		else :
+			print "Error creating Alias!! Error: " + str(error)
+		
+	elif getorcreate == 'get':
+		commandtorun = ['java', '-cp', finalLibPath, 'org.apache.ranger.credentialapi.buildks'
,'get', aliasKey, '-provider',finalFilePath]
+		p = Popen(commandtorun,stdin=PIPE, stdout=PIPE, stderr=PIPE)
+		output, error = p.communicate()
+		statuscode = p.returncode
+		if statuscode == 0:
+			print "Alias : " + aliasKey + " Value : " + str(output)
+		else :
+			print "Error getting value!! Error: " + str(error)
+		
+	else:
+		print 'Invalid Arguments!!'
+	
+if __name__ == '__main__':
+	main()

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/2ba2a2e5/src/main/assembly/admin-web.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/admin-web.xml b/src/main/assembly/admin-web.xml
index 5886679..9136418 100644
--- a/src/main/assembly/admin-web.xml
+++ b/src/main/assembly/admin-web.xml
@@ -317,6 +317,7 @@
 			<include>upgrade_admin.py</include>
 			<include>upgrade.sh</include>
 			<include>update_property.py</include>
+			<include>ranger_credential_helper.py</include>
 		</includes>
 		<fileMode>544</fileMode>
 	</fileSet>


Mime
View raw message