-
Notifications
You must be signed in to change notification settings - Fork 10
/
zshow_composite_policies.prog.abap
295 lines (210 loc) · 8.1 KB
/
zshow_composite_policies.prog.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
*&---------------------------------------------------------------------*
*& Report ZSHOW_COMPOSITE_POLICIES
*&---------------------------------------------------------------------*
*&
*& Show composite policies
*&
*&---------------------------------------------------------------------*
REPORT zshow_composite_policies.
CONSTANTS c_program_version(30) TYPE c VALUE '27.04.2023 FQ4'.
TABLES sscrfields.
SELECTION-SCREEN: FUNCTION KEY 1. " Policy Management
SELECTION-SCREEN: FUNCTION KEY 2. " Composite Policy Management
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) ss_tsys FOR FIELD s_tsys.
SELECT-OPTIONS s_tsys FOR ('COVA_TARSYSID').
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS s_root AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN COMMENT 3(30) ss_root FOR FIELD s_root.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN COMMENT /1(60) ss_vers.
TYPES:
BEGIN OF ts_pol_id,
pol_id TYPE cova_tarsysid,
END OF ts_pol_id.
DATA g_tarsysid TYPE cova_tarsysid. " Global field for HIDE statement
*---------------------------------------------------------------------*
* CLASS lcl_report DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
initialization,
at_selection_screen,
start_of_selection,
line_selection.
PRIVATE SECTION.
CLASS-DATA:
lt_cova_cpolh TYPE TABLE OF cova_cpolh,
lt_cova_cpol TYPE TABLE OF cova_cpol,
lt_pol_id TYPE TABLE OF ts_pol_id.
CLASS-METHODS:
write_composite_policies,
write_composite_policy
IMPORTING
pol_id TYPE cova_cpolh-pol_id
pol_version TYPE cova_cpolh-pol_version
level TYPE i.
ENDCLASS. "lcl_report DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
METHOD initialization.
sy-title = 'Show composite policies'(tit).
DATA functxt TYPE smp_dyntxt.
functxt-icon_id = icon_wd_application.
functxt-quickinfo = 'Configuration & Security Analysis - CSA Policy Management'.
functxt-icon_text = 'Policy Management'.
sscrfields-functxt_01 = functxt.
functxt-icon_id = icon_wd_application.
functxt-quickinfo = 'Configuration & Security Analysis - CSA Composite Policy Management'.
functxt-icon_text = 'Composite Policy Management'.
sscrfields-functxt_02 = functxt.
ss_tsys = 'Composite policy'.
ss_root = 'Root policies only'.
CONCATENATE 'Program version:'(ver) c_program_version INTO ss_vers
SEPARATED BY space.
ENDMETHOD. " initialization
METHOD at_selection_screen.
CASE sscrfields-ucomm.
WHEN 'FC01'.
" CSA Policy Management
" https://ldcifq4.wdf.sap.corp:44390/sap/bc/ui5_ui5/sap/csa_policy_mgm/index.html?sap-client=200&sap-language=EN&#/PolicyMaint
DATA(lo_start_url) = NEW /ui2/cl_start_url( '/sap/bc/ui5_ui5/sap/csa_policy_mgm/index.html' ).
lo_start_url->add_sap_params( ). " add sap params "sy-mandt", "sap-language"
lo_start_url->add_url_param( '#/PolicyMaint' ).
" start in browser
lo_start_url->start_browser( ).
WHEN 'FC02'.
" CSA Policy Management
" https://ldcifq4.wdf.sap.corp:44390/sap/bc/ui5_ui5/sap/csa_policy_mgm/index.html?sap-client=200&sap-language=EN&#/CompositePol
lo_start_url = NEW /ui2/cl_start_url( '/sap/bc/ui5_ui5/sap/csa_policy_mgm/index.html' ).
lo_start_url->add_sap_params( ). " add sap params "sy-mandt", "sap-language"
lo_start_url->add_url_param( '#/CompositePol' ).
" start in browser
lo_start_url->start_browser( ).
ENDCASE.
ENDMETHOD. "at_selection_screen
METHOD start_of_selection.
" Get composite policies
SELECT * FROM cova_cpolh
INTO TABLE @lt_cova_cpolh
ORDER BY PRIMARY KEY.
" Get childs of composite policies
SELECT * FROM cova_cpol
INTO TABLE @lt_cova_cpol
ORDER BY PRIMARY KEY.
write_composite_policies( ).
ENDMETHOD. "start_of_selection
METHOD line_selection.
CLEAR g_tarsysid.
READ CURRENT LINE.
CHECK g_tarsysid IS NOT INITIAL.
MESSAGE s000(01) WITH `Show policy ` && g_tarsysid && ` in new browser window`.
" https://ldcifq4.wdf.sap.corp:44390/sap/bc/ui5_ui5/sap/csa_policy_mgm/index.html?sap-client=200&sap-language=EN&#/PolicyDefinition/BL22_CRITAU-A/0000
DATA(lo_start_url) = NEW /ui2/cl_start_url( `/sap/bc/ui5_ui5/sap/csa_policy_mgm/index.html` ).
lo_start_url->add_sap_params( ). " add sap params "sy-mandt", "sap-language"
lo_start_url->add_url_param( `#/PolicyDefinition/` && g_tarsysid && `/0000` ).
" start in browser
lo_start_url->start_browser( ).
ENDMETHOD. " line_selection
METHOD write_composite_policies.
FORMAT RESET.
LOOP AT lt_cova_cpolh INTO DATA(ls_cova_cpolh)
WHERE pol_id IN s_tsys.
" Check for root entries
IF s_root = abap_true.
READ TABLE lt_cova_cpol TRANSPORTING NO FIELDS
WITH KEY
child_pol_id = ls_cova_cpolh-pol_id
child_pol_version = ls_cova_cpolh-pol_version.
CHECK sy-subrc NE 0.
ENDIF.
" Clear recursion protection
CLEAR lt_pol_id.
" Show composite policy
write_composite_policy(
EXPORTING
pol_id = ls_cova_cpolh-pol_id
pol_version = ls_cova_cpolh-pol_version
level = 0 " initial level
).
ENDLOOP.
ENDMETHOD. " write_composite_policies
METHOD write_composite_policy.
"IMPORTING
" pol_id TYPE cova_cpolh-pol_id
" pol_version TYPE cova_cpolh-pol_version
" level TYPE i.
" Recursion protection
READ TABLE lt_pol_id TRANSPORTING NO FIELDS
WITH KEY pol_id = pol_id.
IF sy-subrc = 0.
EXIT.
ENDIF.
APPEND pol_id TO lt_pol_id.
DATA(indent) = level * 2.
" Get description
READ TABLE lt_cova_cpolh INTO DATA(ls_cova_cpolh)
WITH KEY
pol_id = pol_id
pol_version = pol_version.
IF sy-subrc NE 0.
CLEAR ls_cova_cpolh.
ENDIF.
NEW-LINE.
WRITE: AT indent pol_id COLOR COL_KEY,
50 ls_cova_cpolh-pol_desc COLOR COL_NORMAL.
indent = indent + 2. " Shift single policies to the right
LOOP AT lt_cova_cpol INTO DATA(ls_cova_cpol)
WHERE pol_id = pol_id
AND pol_version = pol_version.
CASE ls_cova_cpol-child_pol_type.
WHEN 'S'. " Single policy
SELECT SINGLE tardesc
FROM cova_tarsysv_dbv
INTO @DATA(tardesc)
WHERE tarsysid = @ls_cova_cpol-child_pol_id
AND tarversion = '0000' " current version (>= 9000 for historic versions)
.
IF sy-subrc NE 0.
CLEAR tardesc.
ENDIF.
g_tarsysid = ls_cova_cpol-child_pol_id.
NEW-LINE.
WRITE:
AT indent ls_cova_cpol-child_pol_id HOTSPOT,
50 tardesc.
HIDE g_tarsysid.
WHEN 'C'. " Composite policy
IF level > 10.
WRITE: / 'nesting error' COLOR COL_NEGATIVE.
EXIT.
ENDIF.
DATA(next_level) = level + 1.
write_composite_policy(
EXPORTING
pol_id = ls_cova_cpol-child_pol_id
pol_version = ls_cova_cpol-child_pol_version
level = next_level
).
WHEN OTHERS.
WRITE: / 'unknown type' COLOR COL_NEGATIVE.
EXIT.
ENDCASE.
ENDLOOP.
ENDMETHOD. " write_composite_policy
ENDCLASS. "lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
* REPORT events
*----------------------------------------------------------------------*
INITIALIZATION.
lcl_report=>initialization( ).
AT SELECTION-SCREEN.
lcl_report=>at_selection_screen( ).
START-OF-SELECTION.
lcl_report=>start_of_selection( ).
AT LINE-SELECTION.
lcl_report=>line_selection( ).