@sasjs/core 4.57.0 → 4.57.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/viya/mfv_getpathuri.sas
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@file
|
|
3
3
|
@brief Returns the uri of a file or folder
|
|
4
|
-
@details The automatic variable _FILESRVC_[fref]_URI is used after assigning
|
|
4
|
+
@details The automatic variable `_FILESRVC_[fref]_URI` is used after assigning
|
|
5
5
|
a fileref using the filesrvc engine.
|
|
6
6
|
|
|
7
7
|
Usage:
|
|
8
8
|
|
|
9
|
-
%put %
|
|
10
|
-
%put %
|
|
9
|
+
%put %mfv_getpathuri(/Public/folder/file.txt);
|
|
10
|
+
%put %mfv_getpathuri(/Public/folder);
|
|
11
11
|
|
|
12
12
|
@param [in] filepath The full path to the file on SAS drive
|
|
13
13
|
(eg /Public/myfile.txt)
|
package/viya/mv_createfile.sas
CHANGED
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
@li password
|
|
37
37
|
@li authorization_code
|
|
38
38
|
@li sas_services
|
|
39
|
+
@param [in] force= (YES) Will overwrite (delete / recreate) files by default.
|
|
40
|
+
Set to NO to abort if a file already exists in that location.
|
|
39
41
|
@param [out] outds= (_null_) Output dataset with the uri of the new file
|
|
40
42
|
|
|
41
43
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
@li mf_getuniquename.sas
|
|
47
49
|
@li mf_isblank.sas
|
|
48
50
|
@li mf_mimetype.sas
|
|
51
|
+
@li mfv_getpathuri.sas
|
|
49
52
|
@li mp_abort.sas
|
|
50
53
|
@li mp_base64copy.sas
|
|
51
54
|
@li mv_createfolder.sas
|
|
@@ -65,6 +68,7 @@
|
|
|
65
68
|
,grant_type=sas_services
|
|
66
69
|
,mdebug=0
|
|
67
70
|
,outds=_null_
|
|
71
|
+
,force=YES
|
|
68
72
|
);
|
|
69
73
|
%local dbg;
|
|
70
74
|
%if &mdebug=1 %then %do;
|
|
@@ -86,16 +90,16 @@
|
|
|
86
90
|
%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
|
|
87
91
|
and &grant_type ne sas_services
|
|
88
92
|
)
|
|
89
|
-
,mac
|
|
93
|
+
,mac=MV_CREATEFILE
|
|
90
94
|
,msg=%str(Invalid value for grant_type: &grant_type)
|
|
91
95
|
)
|
|
92
96
|
|
|
93
97
|
%mp_abort(iftrue=(%mf_isblank(&path)=1 or %length(&path)=1)
|
|
94
|
-
,mac
|
|
98
|
+
,mac=MV_CREATEFILE
|
|
95
99
|
,msg=%str(path value must be provided)
|
|
96
100
|
)
|
|
97
101
|
%mp_abort(iftrue=(%mf_isblank(&name)=1 or %length(&name)=1)
|
|
98
|
-
,mac
|
|
102
|
+
,mac=MV_CREATEFILE
|
|
99
103
|
,msg=%str(name value with length >1 must be provided)
|
|
100
104
|
)
|
|
101
105
|
|
|
@@ -118,9 +122,12 @@
|
|
|
118
122
|
run;
|
|
119
123
|
%end;
|
|
120
124
|
|
|
125
|
+
options noquotelenmax;
|
|
126
|
+
%local base_uri; /* location of rest apis */
|
|
127
|
+
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
121
128
|
|
|
122
129
|
/* create folder if it does not already exist */
|
|
123
|
-
%local folderds
|
|
130
|
+
%local folderds self_uri;
|
|
124
131
|
%let folderds=%mf_getuniquename(prefix=folderds);
|
|
125
132
|
%mv_createfolder(path=&path
|
|
126
133
|
,access_token_var=&access_token_var
|
|
@@ -133,10 +140,26 @@ data _null_;
|
|
|
133
140
|
call symputx('self_uri',self_uri,'l');
|
|
134
141
|
run;
|
|
135
142
|
|
|
143
|
+
/* abort or delete if file already exists */
|
|
144
|
+
%let force=%upcase(&force);
|
|
145
|
+
%local fileuri ;
|
|
146
|
+
%let fileuri=%mfv_getpathuri(&path/&name);
|
|
147
|
+
%mp_abort(iftrue=(%mf_isblank(&fileuri)=0 and &force ne YES)
|
|
148
|
+
,mac=MV_CREATEFILE
|
|
149
|
+
,msg=%str(File &path/&name already exists and force=&force)
|
|
150
|
+
)
|
|
136
151
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
152
|
+
%if %mf_isblank(&fileuri)=0 and &force=YES %then %do;
|
|
153
|
+
proc http method="DELETE" url="&base_uri&fileuri" &oauth_bearer;
|
|
154
|
+
headers
|
|
155
|
+
%if &grant_type=authorization_code %then %do;
|
|
156
|
+
"Authorization"="Bearer &&&access_token_var"
|
|
157
|
+
%end;
|
|
158
|
+
"Accept"="*/*";
|
|
159
|
+
run;
|
|
160
|
+
%put &sysmacroname DELETE &base_uri&fileuri
|
|
161
|
+
&=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
|
|
162
|
+
%end;
|
|
140
163
|
|
|
141
164
|
%local url mimetype;
|
|
142
165
|
%let url=&base_uri/files/files?parentFolderUri=&self_uri;
|
|
@@ -152,7 +175,8 @@ proc http method='POST' out=&fname1 &oauth_bearer in=&fref
|
|
|
152
175
|
%else %do;
|
|
153
176
|
ct="&ctype"
|
|
154
177
|
%end;
|
|
155
|
-
%if "&mimetype"="text/html"
|
|
178
|
+
%if "&mimetype"="text/html" or "&mimetype"="text/css"
|
|
179
|
+
or "&mimetype"="text/javascript" %then %do;
|
|
156
180
|
url="&url%str(&)typeDefName=file";
|
|
157
181
|
%end;
|
|
158
182
|
%else %do;
|
|
@@ -165,10 +189,10 @@ proc http method='POST' out=&fname1 &oauth_bearer in=&fref
|
|
|
165
189
|
%end;
|
|
166
190
|
"Content-Disposition"= "&contentdisp filename=""&name""; name=""&name"";";
|
|
167
191
|
run;
|
|
168
|
-
%put &=
|
|
169
|
-
|
|
192
|
+
%put &sysmacroname POST &=url
|
|
193
|
+
&=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
|
|
170
194
|
%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 201)
|
|
171
|
-
,mac
|
|
195
|
+
,mac=MV_CREATEFILE
|
|
172
196
|
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
173
197
|
)
|
|
174
198
|
%local libref2;
|