39%macro mv_getjobcode(outref=0,outfile=0
41 ,contextName=SAS Job Execution compute context
42 ,access_token_var=ACCESS_TOKEN
43 ,grant_type=sas_services
46%local dbg bufsize varcnt fname1 fname2 errmsg;
47%
if &mdebug=1 %then %
do;
48 %put &sysmacroname local entry vars:;
54%
if &grant_type=detect %then %
do;
55 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
56 %
else %let grant_type=sas_services;
58%
if &grant_type=sas_services %then %
do;
59 %let oauth_bearer=oauth_bearer=sas_services;
60 %let &access_token_var=;
62%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
63 and &grant_type ne sas_services
66 ,msg=%str(Invalid value
for grant_type: &grant_type)
68%mp_abort(iftrue=(
"&path"=
"0")
70 ,msg=%str(Job Path not provided)
72%mp_abort(iftrue=(
"&name"=
"0")
74 ,msg=%str(Job Name not provided)
76%mp_abort(iftrue=(
"&outfile"=
"0" and
"&outref"=
"0")
78 ,msg=%str(Output destination (file or fileref) must be provided)
82%let base_uri=%mf_getplatform(VIYARESTAPI);
85%let foldermembers=&syslast;
86%mv_getfoldermembers(root=&path
87 ,access_token_var=&access_token_var
88 ,grant_type=&grant_type
95 call missing(name,uri);
97 if name=
"&name" and uri=:
'/jobDefinitions/definitions'
98 then call symputx(
'joburi',uri);
100%mp_abort(iftrue=(
"&joburi"=
"0")
102 ,msg=%str(Job &path/&name not found)
106%let fname1=%mf_getuniquefileref();
107proc http method=
'GET' out=&fname1 &oauth_bearer
108 url=
"&base_uri&joburi";
109 headers
"Accept"=
"application/vnd.sas.job.definition+json"
110 %
if &grant_type=authorization_code %then %
do;
111 "Authorization"=
"Bearer &&&access_token_var"
116%
if &mdebug=1 %then %
do;
125 iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201)
127 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
130%let fname2=%mf_getuniquefileref();
131filename &fname2 temp ;
136 file &fname2 recfm=n;
137 infile &fname1 lrecl=1 recfm=n;
138 input sourcechar $char1. @@;
139 format sourcechar hex2.;
141 if startwrite=0 and sourcechar=
'"' then
do;
143 input sourcechar $ 1. @@;
144 if sourcechar=
'c' then
do;
146 input sourcechar $ 1. @@;
147 if sourcechar=
'o' then
do;
148 input sourcechar $ 1. @@;
149 if sourcechar=
'd' then
do;
150 input sourcechar $ 1. @@;
151 if sourcechar=
'e' then
do;
152 input sourcechar $ 1. @@;
153 if sourcechar=
'"' then
do;
154 input sourcechar $ 1. @@;
155 if sourcechar=
':' then
do;
156 input sourcechar $ 1. @@;
157 if sourcechar=
'"' then
do;
160 input sourcechar $ 1. @@;
163 else if sourcechar=
'c' then
goto reentry2;
166 else if sourcechar=
'"' then
goto reentry;
168 else if sourcechar=
'"' then
goto reentry;
170 else if sourcechar=
'"' then
goto reentry;
172 else if sourcechar=
'"' then
goto reentry;
175 if startwrite=1 then
do;
176 if sourcechar=
'\' then
do;
177 input sourcechar $ 1. @@;
178 if sourcechar in (
'"',
'\') then put sourcechar char1.;
179 else if sourcechar='n' then put '0A'x;
180 else if sourcechar='r' then put '0D'x;
181 else if sourcechar='t' then put '09'x;
182 else if sourcechar='u' then do;
185 sourcechar=unicode('\u'!!uni);
186 put sourcechar char1.;
189 call symputx('errmsg',"Uncaught escape
char: "!!sourcechar,'l');
190 call symputx('syscc',99);
194 else if sourcechar='"' then stop;
195 else put sourcechar char1.;
199%mp_abort(iftrue=("&syscc"="99")
205%if "&outref"="0" %then %do;
207 file "&outfile" lrecl=32767;
210 filename &outref temp;
217 &dbg. putlog _infile_;
220%if &mdebug=1 %then %do;
221 %put &sysmacroname exit vars:;
226 filename &fname1 clear;
227 filename &fname2 clear;