<filename>python/auth.py
#!/usr/bin/python

# coding: utf-8

# Copyright 2018 AstroLab Software
# Author: <NAME>
#
# 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.

"""
curl -i -k -u toto:tata -X POST --data '{"kind": "pyspark"}' -H 'Content-Type: application/json' https://172.16.31.10:8443/gateway/sandbox/livy/v1/sessions
curl -i -k -u christian.arnault:@@@DTsa57 -X GET --data '{"kind": "pyspark"}' -H 'Content-Type: application/json' https://172.16.17.32:8443/gateway/knox_spark/livy/v1/version


"""

import netrc
import base64
import os
import requests
import json

os.environ['HOME'] = 'c:/arnault'

def main():
    print('auth')

    gateway_name = "gateway_spark"
    host = "172.16.17.32"
    port = 8443
    gateway = "gateway/knox_spark"

    secrets = netrc.netrc()
    login, username, password = secrets.authenticators(gateway_name)

    """
    a = '{}:{}'.format(login, password).encode('utf-8')
    a = base64.b64encode(a)
    auth = u'Basic {}'.format(a)
    print(auth)

        ### 'Authorization': auth
    """

    # , 'Authorization': auth

    headers = {'Content-Type': 'application/json'}
    data = {"kind": "pyspark"}

    url = 'https://{}:{}/{}/livy/v1/version'.format(host, port, gateway)
    r = requests.get(url, auth=(login, password), headers=headers, data=json.dumps(data), verify=False)

    print(r.json())

if __name__ == "__main__":
    main()

<filename>python/auth.py
#!/usr/bin/python

# coding: utf-8

# Copyright 2018 AstroLab Software
# Author: <NAME>
#
# 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.

"""
curl -i -k -u toto:tata -X POST --data '{"kind": "pyspark"}' -H 'Content-Type: application/json' https://172.16.31.10:8443/gateway/sandbox/livy/v1/sessions
curl -i -k -u christian.arnault:@@@DTsa57 -X GET --data '{"kind": "pyspark"}' -H 'Content-Type: application/json' https://172.16.17.32:8443/gateway/knox_spark/livy/v1/version


"""

import netrc
import base64
import os
import requests
import json

os.environ['HOME'] = 'c:/arnault'

def main():
    print('auth')

    gateway_name = "gateway_spark"
    host = "172.16.17.32"
    port = 8443
    gateway = "gateway/knox_spark"

    secrets = netrc.netrc()
    login, username, password = secrets.authenticators(gateway_name)

    """
    a = '{}:{}'.format(login, password).encode('utf-8')
    a = base64.b64encode(a)
    auth = u'Basic {}'.format(a)
    print(auth)

        ### 'Authorization': auth
    """

    # , 'Authorization': auth

    headers = {'Content-Type': 'application/json'}
    data = {"kind": "pyspark"}

    url = 'https://{}:{}/{}/livy/v1/version'.format(host, port, gateway)
    r = requests.get(url, auth=(login, password), headers=headers, data=json.dumps(data), verify=False)

    print(r.json())

if __name__ == "__main__":
    main()

#!/usr/bin/python # coding: utf-8 # Copyright 2018 AstroLab Software # Author: <NAME> # # 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. curl -i -k -u toto:tata -X POST --data '{"kind": "pyspark"}' -H 'Content-Type: application/json' https://172.16.31.10:8443/gateway/sandbox/livy/v1/sessions curl -i -k -u christian.arnault:@@@DTsa57 -X GET --data '{"kind": "pyspark"}' -H 'Content-Type: application/json' https://172.16.17.32:8443/gateway/knox_spark/livy/v1/version a = '{}:{}'.format(login, password).encode('utf-8')     a = base64.b64encode(a)     auth = u'Basic {}'.format(a)     print(auth)          ### 'Authorization': auth # , 'Authorization': auth