mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-02 13:03:01 +08:00
Replace usages of cl_sxml* for compatibility
cl_sxml_writer/reader do not support json on AS ABAP 7.02
This commit is contained in:
parent
dd516fbea1
commit
7715bdc59d
|
@ -436,80 +436,52 @@ CLASS lcl_2fa_github_authenticator IMPLEMENTATION.
|
||||||
|
|
||||||
rv_access_token = get_token_from_response( li_http_client->response ).
|
rv_access_token = get_token_from_response( li_http_client->response ).
|
||||||
IF rv_access_token IS INITIAL.
|
IF rv_access_token IS INITIAL.
|
||||||
RAISE EXCEPTION TYPE lcx_2fa_token_gen_failed.
|
RAISE EXCEPTION TYPE lcx_2fa_token_gen_failed
|
||||||
|
EXPORTING
|
||||||
|
iv_error_text = 'Token generation failed: parser error' ##NO_TEXT.
|
||||||
ENDIF.
|
ENDIF.
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
METHOD set_access_token_request.
|
METHOD set_access_token_request.
|
||||||
CONSTANTS: BEGIN OF lc_create_access_token_request,
|
DATA: lv_fingerprint TYPE string,
|
||||||
scopes TYPE string VALUE 'repo',
|
lv_json_string TYPE string.
|
||||||
note TYPE string VALUE 'abapGit',
|
|
||||||
END OF lc_create_access_token_request.
|
|
||||||
DATA: lo_json_writer TYPE REF TO cl_sxml_string_writer,
|
|
||||||
lt_scopes TYPE stringtab,
|
|
||||||
lt_rest_parvalues TYPE abap_trans_srcbind_tab,
|
|
||||||
ls_rest_line LIKE LINE OF lt_rest_parvalues,
|
|
||||||
lt_result_parvalues TYPE abap_trans_resbind_tab,
|
|
||||||
ls_result_line LIKE LINE OF lt_result_parvalues,
|
|
||||||
lr_data_ref TYPE REF TO data,
|
|
||||||
lv_note TYPE string,
|
|
||||||
lv_fingerprint TYPE string.
|
|
||||||
|
|
||||||
lo_json_writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
|
|
||||||
APPEND lc_create_access_token_request-scopes TO lt_scopes.
|
|
||||||
|
|
||||||
GET REFERENCE OF lc_create_access_token_request-scopes INTO lr_data_ref.
|
|
||||||
ls_rest_line-name = 'scopes'.
|
|
||||||
ls_rest_line-value = lr_data_ref.
|
|
||||||
APPEND ls_rest_line TO lt_rest_parvalues.
|
|
||||||
|
|
||||||
GET REFERENCE OF lc_create_access_token_request-note INTO lr_data_ref.
|
|
||||||
ls_rest_line-name = 'note'.
|
|
||||||
ls_rest_line-value = lr_data_ref.
|
|
||||||
APPEND ls_rest_line TO lt_rest_parvalues.
|
|
||||||
|
|
||||||
" The fingerprint must be unique, otherwise only one token can be generated, unless the user
|
" The fingerprint must be unique, otherwise only one token can be generated, unless the user
|
||||||
" deletes it in GitHub's settings. This is problematic if he deletes it in abapGit but keeps it
|
" deletes it in GitHub's settings. This is problematic if he deletes it in abapGit but keeps it
|
||||||
" on GitHub.
|
" on GitHub.
|
||||||
lv_fingerprint = |abapGit-{ sy-sysid }-{ sy-uname }-{ sy-datum }-{ sy-uzeit }|.
|
lv_fingerprint = |abapGit-{ sy-sysid }-{ sy-uname }-{ sy-datum }-{ sy-uzeit }|.
|
||||||
GET REFERENCE OF lv_fingerprint INTO lr_data_ref.
|
|
||||||
ls_rest_line-name = 'fingerprint'.
|
|
||||||
ls_rest_line-value = lr_data_ref.
|
|
||||||
APPEND ls_rest_line TO lt_rest_parvalues.
|
|
||||||
|
|
||||||
" Dynamic source table is used because otherwise identifiers will always be written in uppercase
|
lv_json_string = |\{"scopes":["repo"],"note":"abapGit","fingerprint":"{ lv_fingerprint }"\}|.
|
||||||
" which is not supported by GitHub's API.
|
|
||||||
CALL TRANSFORMATION id SOURCE (lt_rest_parvalues)
|
|
||||||
RESULT XML lo_json_writer.
|
|
||||||
|
|
||||||
ii_request->set_data( lo_json_writer->get_output( ) ).
|
ii_request->set_data( cl_abap_codepage=>convert_to( lv_json_string ) ).
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
METHOD get_token_from_response.
|
METHOD get_token_from_response.
|
||||||
CONSTANTS: lc_token_field_name TYPE string VALUE 'token'.
|
CONSTANTS: lc_search_regex TYPE string VALUE '.*"token":"([^"]*).*$'.
|
||||||
DATA: lt_result_parvalues TYPE abap_trans_resbind_tab,
|
DATA: lv_response TYPE string,
|
||||||
ls_result_line LIKE LINE OF lt_result_parvalues,
|
lo_regex TYPE REF TO cl_abap_regex,
|
||||||
lr_data_ref TYPE REF TO data,
|
lo_matcher TYPE REF TO cl_abap_matcher.
|
||||||
lv_binary_response TYPE xstring.
|
|
||||||
|
|
||||||
GET REFERENCE OF rv_token INTO lr_data_ref.
|
lv_response = cl_abap_codepage=>convert_from( ii_response->get_data( ) ).
|
||||||
ls_result_line-name = lc_token_field_name.
|
|
||||||
ls_result_line-value = lr_data_ref.
|
|
||||||
APPEND ls_result_line TO lt_result_parvalues.
|
|
||||||
|
|
||||||
lv_binary_response = ii_response->get_data( ).
|
CREATE OBJECT lo_regex
|
||||||
|
EXPORTING
|
||||||
|
pattern = lc_search_regex.
|
||||||
|
|
||||||
CALL TRANSFORMATION id SOURCE XML lv_binary_response
|
lo_matcher = lo_regex->create_matcher( text = lv_response ).
|
||||||
RESULT (lt_result_parvalues).
|
IF lo_matcher->match( ) = abap_true.
|
||||||
|
rv_token = lo_matcher->get_submatch( 1 ).
|
||||||
|
ENDIF.
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
METHOD parse_repo_from_url.
|
METHOD parse_repo_from_url.
|
||||||
|
CONSTANTS: lc_search_regex TYPE string VALUE 'https?:\/\/(www\.)?github.com\/(.*)$'.
|
||||||
DATA: lo_regex TYPE REF TO cl_abap_regex,
|
DATA: lo_regex TYPE REF TO cl_abap_regex,
|
||||||
lo_matcher TYPE REF TO cl_abap_matcher.
|
lo_matcher TYPE REF TO cl_abap_matcher.
|
||||||
|
|
||||||
CREATE OBJECT lo_regex
|
CREATE OBJECT lo_regex
|
||||||
EXPORTING
|
EXPORTING
|
||||||
pattern = 'https?:\/\/(www\.)?github.com\/(.*)$'.
|
pattern = lc_search_regex.
|
||||||
|
|
||||||
lo_matcher = lo_regex->create_matcher( text = iv_url ).
|
lo_matcher = lo_regex->create_matcher( text = iv_url ).
|
||||||
IF lo_matcher->match( ) = abap_true.
|
IF lo_matcher->match( ) = abap_true.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user