Kevin D. Smith

SAS Viya


Скачать книгу

If there are no connection errors, you should now have an open CAS session that is referred to by the conn variable.

      In [1]: import swat

      In [2]: conn = swat.CAS('server-name.mycompany.com', 5570,

      'username', 'password')

      In [3]: conn

      Out[3]: CAS('server-name.mycompany.com', 5570, 'username',

      protocol='cas', name='py-session-1',

      session='ffee6422-96b9-484f-a868-03505b320987')

      As you can see in Out[3], we display the string representation of the CAS object. You see that it echoes the host name, the port, the user name, and several fields that were not specified. The name and session fields are created once the session is created. The session value contains a unique ID that can be used to make other connections to that same session. The name field is a user-friendly name that is used to tag the session on the server to make it easier to distinguish when querying information about current sessions. This is discussed in more depth later in the chapter.

      We mentioned using Authinfo rather than specifying your user name and password explicitly in your programs. The Authinfo specification is based on an older file format called Netrc. Netrc was used by FTP programs to store user names and passwords so that you don’t have to enter authentication information manually. Authinfo works the same way, but adds a few extensions.

      The basic format of an Authinfo file follows: (The format occupies two lines to enhance readability.)

      host server-name.mycompany.com port 5570

      user username password password

      Where server-name.mycompany.com is the host name of your CAS server (an IP address can also be used), 5570 is the port number of the CAS server, username is your user ID on that machine, and password is your password on that machine. If you don’t specify a port number, the same user name and password are used on any port on that machine. Each CAS host requires a separate host definition line. In addition, the host name must match exactly what is specified in the CAS constructor. There is no DNS name expansion if you use a shortened name such as server-name.

      By default, the Authinfo file is accessed from your home directory under the name .authinfo (on Windows, the name _authinfo is used). It also must have permissions that are set up so that only the owner can read it. This is done using the following command on Linux.

      chmod 0600 ~/.authinfo

      On Windows, the file permissions should be set so that the file isn’t readable by the Everyone group. Once that file is in place and has the correct permissions, you should be able to make a connection to CAS without specifying your user name and password explicitly.

      In [1]: import swat

      In [2]: conn = swat.CAS('server-name.mycompany.com', 5570)

      In [3]: conn

      Out[3]: CAS('server-name.mycompany.com', 5570, 'username',

      protocol='cas', name='py-session-1',

      session='ffee6422-96b9-484f-a868-03505b320987')

      After connecting to CAS, we can continue to a more interesting topic: running CAS actions.

      In the previous section, we made a connection to CAS, but didn’t explicitly perform any actions. However, after the connection was made, many actions were performed to obtain information about the server and what resources are available to the CAS installation. One of the things queried for is information about the currently loaded action sets. An action set is a collection of actions that can be executed. Actions can do various things such as return information about the server setup, load data, and perform advanced analytics. To see what action sets and actions are already loaded, you can call the help action on the CAS object that we previously created.

      In [4]: out = conn.help()

      NOTE: Available Action Sets and Actions:

      NOTE: accessControl

      NOTE: assumeRole - Assumes a role

      NOTE: dropRole - Relinquishes a role

      NOTE: showRolesIn - Shows the currently active role

      NOTE: showRolesAllowed - Shows the roles that a user is

      a member of

      NOTE: isInRole - Shows whether a role is assumed

      NOTE: isAuthorized - Shows whether access is authorized

      NOTE: isAuthorizedActions - Shows whether access is

      authorized to actions

      NOTE: isAuthorizedTables - Shows whether access is authorized

      to tables

      NOTE: isAuthorizedColumns - Shows whether access is authorized

      to columns

      NOTE: listAllPrincipals - Lists all principals that have

      explicit access controls

      NOTE: whatIsEffective - Lists effective access and

      explanations (Origins)

      NOTE: listAcsData - Lists access controls for caslibs, tables,

      and columns

      NOTE: listAcsActionSet - Lists access controls for an action

      or action set

      NOTE: repAllAcsCaslib - Replaces all access controls for

      a caslib

      NOTE: repAllAcsTable - Replaces all access controls for a table

      NOTE: repAllAcsColumn - Replaces all access controls for

      a column

      NOTE: repAllAcsActionSet - Replaces all access controls for

      an action set

      NOTE: repAllAcsAction - Replaces all access controls for

      an action

      NOTE: updSomeAcsCaslib - Adds, deletes, and modifies some

      access controls for a caslib

      NOTE: updSomeAcsTable - Adds, deletes, and modifies some

      access controls for a table

      NOTE: updSomeAcsColumn - Adds, deletes, and modifies some

      access controls for a column

      NOTE: updSomeAcsActionSet - Adds, deletes, and modifies some

      access controls for an action set

      NOTE: updSomeAcsAction - Adds, deletes, and modifies some

      access controls for an action

      NOTE: remAllAcsData - Removes all access controls for a

      caslib, table, or column

      ... truncated ...

      This prints out a listing of all of the loaded action sets and the actions within them. It also returns a CASResults structure that contains the action set information in tabular form. The results of CAS actions are discussed later in this chapter.

      The help action takes arguments that specify which action sets and actions you want information about. To display help for an action set, use the actionset keyword parameter. The following code displays the help content for the builtins action set.

      In [5]: