The SAS admin command-line interface
will allow administrators to perform
numerous administrative tasks in batch
as an alternative to using SAS Environment Manager.
In the video, I will introduce the administration CLIs
and demonstrate an example usage.
The SAS admin CLI is the main interface.
It acts as a wrapper for the other CLIs.
The individual CLIs operate as interfaces
to the functionality from within SAS admin.
The CLIs provide a simplified interface
to the SAS Viya REST services.
They abstract the functionality of the REST services,
allowing an administrator to enter commands
in a command line and receive a response back from the system.
There are two ways you can get the SAS admin command-line
interface.
Firstly, it's installed with SAS Viya in the directory
opt/sasviya/home/bin.
And then secondly, it's available for download
from support.sas.com in the Downloads area.
There's a couple of steps you need
to take before you can use the command-line interface.
Firstly, you need to create a profile
to tell the CLI the service endpoint of Viya.
The profile is stored in your home directory.
You have a default profile.
And you can also create other profiles
to access other systems.
The second thing you need to do is authenticate.
The authentication step creates a token
in a file stored inside the user's home directory, which
is valid for, by default, 12 hours.
This slide shows the general syntax of the SAS admin CLI.
In this example, we're using the identities interface or
plug-in.
We set our global option to display the output as text.
We use the command list-members.
And we passed the option -group ID and the value SAS
admins to list all members of the SAS administrators group.
Let's see Viya administration with a command-line interface
in action.
In the demo, I'm using the CLI in windows,
and Viya environment is on a remote Linux server.
For the purposes of the demo, we'll have a simple scenario.
We will create a folder, set permissions on it,
and to do this, we'll use three plug-ins, Identities,
Authorization, and Folders.
It is very easy to get help with the CLI.
You just type in SAS-admin and then -h, and you get help.
The help is context sensitive.
Here we see a list of all the plug-ins.
In this environment, I already have a profile.
So I'm going to do SAS admin profile list,
and we can see a list of the profiles
that we have available.
To use a profile, you use the --profile option,
give the profile name and where it
is sure to see the contents of that profile.
Let's change it and now look at the default profile, which
is the one we're going to use.
And it'll show the default profile,
you can see where I'm connecting to and
some of the other options.
So the first thing we need to do is to log in.
If we don't specify our profile, it
will use the default profile.
We do SAS admin auth login and then enter
the user ID and the password.
And that's going to log us on to the Viya application.
Next let's use one of the plug-ins.
We'll use Identities.
We'll do SAS admin identities -h.
We can see what commands are available for the Identities
plug-in.
Let's just check who we;re logged on us.
So we'll do whoami.
And we'll see that we're logged on as the SAS
administrator, SAS ADM.
In the demo, we're going to create some folders.
Let's first look at what folders we already have.
So we can see the Folders plug-in has a list members
command.
We'll do list-members and then let's look at the help again.
So we'll do a -h to see what's required
by the list-members command.
We can see we can pass a path of a parent folder.
So let's do that.
And we'll pass in the parent folder gelcontent.
And let's do recursive to get all the children of that parent
folder and -tree to get a nice tree member display.
You can see we can see what folders already exist
under the gelcontent folder.
Next let's add a new folder under that gelcontent folder.
We're going to call it Finance.
So we do sas-admin folders create -h.
We can see that the command requires some options.
We are going to pass in the name of the folder
we want to create.
And then we're going to pass in the parent path of where
we want to create the folder.
And that path is going to be gelcontent/gelcorp to create
the Finance folder under that folder.
We press Enter.
We get some JSON back and the command executed successfully,
and our folder was created.
Now we're going to check the authorization on the folder,
look at the Authorization plug-in,
and see the help for that plug-in.
Let's do an Explain.
And we can see that Explain requires a target URI.
Do we know the target URI?
We don't really know that yet.
We know the name of the folder that we want
to check the authorization on.
So let's go back to the Folders plug-in,
and we'll do a Show and the path of the folder we
want to check authorization on, which is that Finance folder.
Definitely have to spell it correctly.
And when we do that, we can see the ID of the folder
and the parent folders URI.
So that's going to be some information
we need to use explain.
So move back to our Explain, and we'll do a -h.
And then see we need to pass target URIs, so --target-uri.
Target URI starts with /folders/folders for a folder.
Then we can cut and paste the ID from the output of the Folder
plug-in to complete the target URI.
And we paste that in and press Enter,
where I put the JSON with an explanation
of the current authorization on the folder.
In our next step, we have the default permissions
in the folder.
We want to set permissions for the finance group.
So we do sas-admin authorization authorize -g finance
for the group, -p for the read permission.
And we paste in the URI of the folder
and then also the URI of the folder as a container.
So it's going to pass these permissions on to its children,
put that all in there, and enter the command.
We can see the authorization has been set.
If we try to set it again, it'll tell us
the rule already exists.
So it does do some error checking.
Then we'll do our Explain again to see if the authorization has
changed.
So sas-admin authorization explain
and our target URI, which again we
can cut and paste from the previous output of the URI,
press Enter.
We get the JSON.
JSON's not very readable in this case.
It's a lot of output.
It would be good if you wanted to read it into another program
or something.
But we can always change the output with a global --output
option and text.
And we see we got a much nicer output.
And you can see that the read permission has been
granted to the finance group.
So that's a quick demo of the CLI of some other things
you can do with it.
I hope that demo gave you a flavor
of what you can achieve with the SAS admin command-line
interface.
For more details, visit support.sas.com and the Viya
3.4 Administration Guide.
Check back later on more tips and tricks.