Python LDAP/AD IntegrationS3 gateway
Demonstrates how to integrate LDAP/AD with S3 gateway version 2.1.0 and higher in Python.
NOTICE The S3 gateway is included in EEP 6.0.0 -
EEP 8.0.0 repositories. S3 gateway is not
supported in HPE Ezmeral Data Fabric 7.0.0 onward. HPE Ezmeral Data Fabric 7.0.0 introduces a native object storage solution.
For more information, see HPE Ezmeral Data Fabric Object Store.
This example has the following dependencies:
boto3 1.15.13
botocore 1.16.26
requests 2.24.0
xmltodict 0.12.0
urllib3 1.24.3
import json
import boto3
import requests
import urllib3
import xmltodict
from botocore.client import Config
from operations import *
def get_credentials(host, username, password):
url = host + "?Action=AssumeRoleWithLDAPIdentity" \
"&LDAPUsername=" + username + \
"&LDAPPassword=" + password + "&Version=2011-06-15"
print("POST to " + url)
response = requests.post(url)
data = response.text
data = xmltodict.parse(data)
data = json.dumps(data)
data = json.loads(data)
credentials = data["AssumeRoleWithLDAPIdentityResponse"]["AssumeRoleWithLDAPIdentityResult"]["Credentials"]
access = credentials["AccessKeyId"]
secret = credentials["SecretAccessKey"]
session = credentials["SessionToken"]
return access, secret, session
def replace_special_characters(string):
alphanumeric = ""
for character in string:
if character.isalnum():
alphanumeric += character
else:
alphanumeric += "%" + str(format(ord(character), "x"))
return alphanumeric
if __name__ == '__main__':
host = "http://localhost:9000"
username = "admin"
password = "abc@123"
bucketName = "test"
file = "file"
passwordWithoutSpecialCharacters = replace_special_characters(password)
print("Your password without special characters: " + passwordWithoutSpecialCharacters)
accessKey, secretKey, sessionToken = get_credentials(host, username, passwordWithoutSpecialCharacters)
print("\n")
print("accessKey: " + accessKey)
print("secretKey: " + secretKey)
print("sessionToken: " + sessionToken)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
s3 = boto3.client('s3',
endpoint_url=host,
aws_access_key_id=accessKey,
aws_secret_access_key=secretKey,
aws_session_token=sessionToken,
config=Config(signature_version='s3v4'),
region_name='us-east-1',
verify=False)
demo(s3, bucketName, file)