Browse Source

Urlparse update (#28)

* Update loginviauthinfo.py

use urlparse on python 2 and 3

* update for python 3

* update for python3

* Update loginviauthinfo.py

* update loginviauthinfo

* update loginviauthinfo
master
Gerry Nelson 6 years ago
committed by GitHub
parent
commit
1540e74afe
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      __pycache__/sharedfunctions.cpython-36.pyc
  2. 33
      loginviauthinfo.md
  3. 22
      loginviauthinfo.py

BIN
__pycache__/sharedfunctions.cpython-36.pyc

Binary file not shown.

33
loginviauthinfo.md

@ -0,0 +1,33 @@
## Usage
loginviauthinfo.py is used to read the credentials from a secure location and authenticate. The secure location is a authinfo file stored in the users home directory. Authinfo files are currently used in Viya to authenticate from any of the programming interfaces (Python,Java, Lua, Base SAS). The use of the Authinfo file makes the code far easier to share and means the credentials are stored in one secure file rather than hundreds of unsecured code files."
SAS Documents creating authinfo files:
In the documnettation it says
"The format of an authinfo file is based on the .netrc file specification that is used for FTP login. In addition to the .netrc file standards, the authinfo specification allows for putting commands in the file, as well as using quoted strings for passwords. The quoted strings allow for spaces within passwords and user IDs. "
https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=authinfo&docsetTarget=n0xo6z7e98y63dn1fj0g9l2j7oyq.htm&locale=en
Note the **pyviyatools use the .netrc format** not the updated .authinfo format. An addtional difference is that .netrc uses "machine" to identify the target environment rather than "host" for .authinfo.
The .netrc format is documented here https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/filesreference/netrc.html
Related post: https://communities.sas.com/t5/SAS-Communities-Library/Automating-post-deployment-SAS-Viya-tasks-with-REST-and-the/ta-p/603304
Example of file.
First line specifies the default userid and password if no machine is specified.
Second line specifies a machine and the userid and password for that machine.
```bash
default user sasadm1 password mypass
machine sasviya01.race.sas.com user sasadm2 password mpass2
```
It is very similair to the .authinfo format, but not exactly the same.

22
loginviauthinfo.py

@ -8,7 +8,7 @@
# loginviauthinfo.py -f /tmp/myfile
#
#
# Authinfo file users .netrc format https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/filesreference/netrc.html
# Authinfo file uses .netrc format https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/filesreference/netrc.html
#
# Example of file. First line specifies the default userid and password if no machine is specified. Second line specifies a machine and the
# userid and password for that machine,
@ -21,6 +21,8 @@
# 25AUG2019 modified to logon to the host in the profile and support multiple lines in authinfo
# 10OCT2019 minor edits to header, no code changes
# 18OCT2019 quote the password in the CLI step to deal with special characters
# 12NOV2019 do quote the password for windows
# 12NOV2019 deal with urlparse on python 3
#
# Copyright © 2018, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
#
@ -37,14 +39,23 @@
# limitations under the License.
#
from __future__ import print_function
import netrc
import subprocess
import platform
import os
import argparse
import json
from sharedfunctions import file_accessible
from urlparse import urlparse
try:
# Python 3
from urllib.parse import urlparse
except ImportError:
# Python 2
from urlparse import urlparse
# CHANGE THIS VARIABLE IF YOUR CLI IS IN A DIFFERENT LOCATION
clidir='/opt/sas/viya/home/bin/'
@ -113,9 +124,10 @@ if profileexists:
print('user: '+username)
print('profile: '+myprofile)
print('host: '+host)
#command=clidir+'sas-admin --profile '+myprofile+ ' auth login -u '+username+ ' -p '+password
command=clidir+"sas-admin --profile "+myprofile+ " auth login -u "+username+ " -p '"+password+"'"
#quote the password string for posix systems
if (os.name =='posix'): command=clidir+"sas-admin --profile "+myprofile+ " auth login -u "+username+ " -p '"+password+"'"
else: command=clidir+'sas-admin --profile '+myprofile+ ' auth login -u '+username+ ' -p '+password
subprocess.call(command, shell=True)
else:

Loading…
Cancel
Save