diff --git a/.abapgit.xml b/.abapgit.xml index aeec0a0..62bb66f 100644 --- a/.abapgit.xml +++ b/.abapgit.xml @@ -12,7 +12,7 @@ 750 - ZIF_HTTP_AGENT=>C_VERSION + /APMG/IF_HTTP_AGENT=>C_VERSION diff --git a/abaplint.json b/abaplint.json index 3814f7f..96fb450 100644 --- a/abaplint.json +++ b/abaplint.json @@ -13,11 +13,16 @@ { "files": "/src/**/*.*", "folder": "/deps3", - "url": "https://github.com/sbcgua/abap-string-map" + "url": "https://github.com/abapPM/ABAP-Url" }, { "files": "/src/**/*.*", "folder": "/deps4", + "url": "https://github.com/sbcgua/abap-string-map" + }, + { + "files": "/src/**/*.*", + "folder": "/deps5", "url": "https://github.com/sbcgua/ajson" } ], @@ -43,7 +48,12 @@ "align_type_expressions": true, "allowed_object_naming": true, "allowed_object_types": { - "allowed": ["CLAS", "DEVC", "INTF"] + "allowed": [ + "CLAS", + "DEVC", + "INTF", + "NSPC" + ] }, "ambiguous_statement": true, "avoid_use": true, @@ -176,41 +186,41 @@ "no_yoda_conditions": true, "nrob_consistency": true, "object_naming": { - "aqbg": "^ZABAPPM", - "aqqu": "^ZABAPPM", - "aqsg": "^ZABAPPM", - "auth": "^ZABAPPM", - "clas": "^ZC(L|X)\\_HTTP", - "cmod": "^ZABAPPM", - "doma": "^ZABAPPM", - "dtel": "^ZABAPPM", - "enho": "^ZABAPPM", - "enhs": "^ZABAPPM", - "enqu": "^EZABAPPM", - "form": "^ZABAPPM", - "fugr": "^ZABAPPM", - "idoc": "^ZABAPPM", + "aqbg": "^Z", + "aqqu": "^Z", + "aqsg": "^Z", + "auth": "^Z", + "clas": "^/APMG/C(L|X)_HTTP", + "cmod": "^Z", + "doma": "^Z", + "dtel": "^Z", + "enho": "^Z", + "enhs": "^Z", + "enqu": "^EZ", + "form": "^Z", + "fugr": "^Z", + "idoc": "^Z", "ignoreNames": [], "ignorePatterns": [], - "intf": "^ZIF\\_HTTP", - "msag": "^ZABAPPM", + "intf": "^/APMG/IF_HTTP", + "msag": "^Z", "patternKind": "required", - "pinf": "^ZABAPPM", - "prog": "^ZABAPPM", - "sfpf": "^ZABAPPM", - "sfpi": "^ZABAPPM", - "shlp": "^ZABAPPM", - "ssfo": "^ZABAPPM", - "ssst": "^ZABAPPM", - "sucu": "^ZABAPPM", - "suso": "^ZABAPPM", - "sxci": "^ZABAPPM", - "tabl": "^ZABAPPM", - "tran": "^ZABAPPM", - "ttyp": "^ZABAPPM", - "wdya": "^ZABAPPM", - "wdyn": "^ZABAPPM", - "xslt": "^ZABAPPM" + "pinf": "^Z", + "prog": "^Z", + "sfpf": "^Z", + "sfpi": "^Z", + "shlp": "^Z", + "ssfo": "^Z", + "ssst": "^Z", + "sucu": "^Z", + "suso": "^Z", + "sxci": "^Z", + "tabl": "^Z", + "tran": "^Z", + "ttyp": "^Z", + "wdya": "^Z", + "wdyn": "^Z", + "xslt": "^Z" }, "obsolete_statement": true, "omit_parameter_name": true, @@ -279,7 +289,7 @@ "xml_consistency": true }, "syntax": { - "errorNamespace": "^(Z|Y|LCL_|TY_|LIF_)", + "errorNamespace": "^(/APMG/|LCL_|TY_|LIF_)", "globalConstants": [], "globalMacros": [], "version": "v750" diff --git a/src/#apmg#.nspc.xml b/src/#apmg#.nspc.xml new file mode 100644 index 0000000..5ecb4d0 --- /dev/null +++ b/src/#apmg#.nspc.xml @@ -0,0 +1,16 @@ + + + + + + /APMG/ + 41813564412598342476 + + + E + apm + apm.to Inc. + + + + diff --git a/src/zcl_http_agent.clas.abap b/src/#apmg#cl_http_agent.clas.abap similarity index 84% rename from src/zcl_http_agent.clas.abap rename to src/#apmg#cl_http_agent.clas.abap index 662d4f7..1e78ec6 100644 --- a/src/zcl_http_agent.clas.abap +++ b/src/#apmg#cl_http_agent.clas.abap @@ -1,4 +1,4 @@ -CLASS zcl_http_agent DEFINITION +CLASS /apmg/cl_http_agent DEFINITION PUBLIC FINAL CREATE PRIVATE. @@ -11,11 +11,11 @@ CLASS zcl_http_agent DEFINITION ************************************************************************ PUBLIC SECTION. - INTERFACES zif_http_agent. + INTERFACES /apmg/if_http_agent. CLASS-METHODS create RETURNING - VALUE(result) TYPE REF TO zif_http_agent. + VALUE(result) TYPE REF TO /apmg/if_http_agent. METHODS constructor. @@ -29,13 +29,13 @@ CLASS zcl_http_agent DEFINITION request TYPE REF TO if_http_request payload TYPE any RAISING - zcx_error. + /apmg/cx_error. ENDCLASS. -CLASS zcl_http_agent IMPLEMENTATION. +CLASS /apmg/cl_http_agent IMPLEMENTATION. METHOD attach_payload. @@ -50,7 +50,7 @@ CLASS zcl_http_agent IMPLEMENTATION. WHEN cl_abap_typedescr=>typekind_char. request->set_cdata( |{ payload }| ). WHEN OTHERS. - RAISE EXCEPTION TYPE zcx_error_text + RAISE EXCEPTION TYPE /apmg/cx_error_text EXPORTING text = |Unexpected payload type { payload_type->absolute_name }|. ENDCASE. @@ -67,19 +67,19 @@ CLASS zcl_http_agent IMPLEMENTATION. METHOD create. - result = NEW zcl_http_agent( ). + result = NEW /apmg/cl_http_agent( ). ENDMETHOD. - METHOD zif_http_agent~global_headers. + METHOD /apmg/if_http_agent~global_headers. result = global_headers. ENDMETHOD. - METHOD zif_http_agent~request. + METHOD /apmg/if_http_agent~request. DATA: http_client TYPE REF TO if_http_client, @@ -119,9 +119,9 @@ CLASS zcl_http_agent IMPLEMENTATION. ENDLOOP. ENDIF. - IF method = zif_http_agent=>c_method-post - OR method = zif_http_agent=>c_method-put - OR method = zif_http_agent=>c_method-patch. + IF method = /apmg/if_http_agent=>c_method-post + OR method = /apmg/if_http_agent=>c_method-put + OR method = /apmg/if_http_agent=>c_method-patch. attach_payload( request = http_client->request payload = payload ). @@ -149,7 +149,7 @@ CLASS zcl_http_agent IMPLEMENTATION. code = status_code message = message ). - RAISE EXCEPTION TYPE zcx_error_text + RAISE EXCEPTION TYPE /apmg/cx_error_text EXPORTING text = |HTTP error: [{ status_code }] { message }|. ENDIF. diff --git a/src/zcl_http_agent.clas.locals_imp.abap b/src/#apmg#cl_http_agent.clas.locals_imp.abap similarity index 71% rename from src/zcl_http_agent.clas.locals_imp.abap rename to src/#apmg#cl_http_agent.clas.locals_imp.abap index aea543c..d7d0bec 100644 --- a/src/zcl_http_agent.clas.locals_imp.abap +++ b/src/#apmg#cl_http_agent.clas.locals_imp.abap @@ -2,13 +2,13 @@ CLASS lcl_http_response DEFINITION FINAL. PUBLIC SECTION. - INTERFACES zif_http_response. + INTERFACES /apmg/if_http_response. CLASS-METHODS create IMPORTING http_client TYPE REF TO if_http_client RETURNING - VALUE(result) TYPE REF TO zif_http_response. + VALUE(result) TYPE REF TO /apmg/if_http_response. PRIVATE SECTION. @@ -29,32 +29,32 @@ CLASS lcl_http_response IMPLEMENTATION. ENDMETHOD. - METHOD zif_http_response~close. + METHOD /apmg/if_http_response~close. http_client->close( ). ENDMETHOD. - METHOD zif_http_response~is_ok. + METHOD /apmg/if_http_response~is_ok. - DATA(status_code) = zif_http_response~code( ). + DATA(status_code) = /apmg/if_http_response~code( ). result = xsdbool( status_code >= 200 AND status_code < 300 ). ENDMETHOD. - METHOD zif_http_response~data. + METHOD /apmg/if_http_response~data. result = http_response->get_data( ). ENDMETHOD. - METHOD zif_http_response~cdata. + METHOD /apmg/if_http_response~cdata. result = http_response->get_cdata( ). ENDMETHOD. - METHOD zif_http_response~code. + METHOD /apmg/if_http_response~code. DATA msg TYPE string ##NEEDED. @@ -65,23 +65,23 @@ CLASS lcl_http_response IMPLEMENTATION. ENDMETHOD. - METHOD zif_http_response~json. + METHOD /apmg/if_http_response~json. TRY. - result = zcl_ajson=>parse( zif_http_response~cdata( ) ). + result = zcl_ajson=>parse( /apmg/if_http_response~cdata( ) ). CATCH zcx_ajson_error INTO DATA(error). - RAISE EXCEPTION TYPE zcx_error_prev EXPORTING previous = error. + RAISE EXCEPTION TYPE /apmg/cx_error_prev EXPORTING previous = error. ENDTRY. ENDMETHOD. - METHOD zif_http_response~error. + METHOD /apmg/if_http_response~error. result = http_response->get_cdata( ). ENDMETHOD. - METHOD zif_http_response~headers. + METHOD /apmg/if_http_response~headers. DATA headers TYPE tihttpnvp. diff --git a/src/zcl_http_agent.clas.xml b/src/#apmg#cl_http_agent.clas.xml similarity index 90% rename from src/zcl_http_agent.clas.xml rename to src/#apmg#cl_http_agent.clas.xml index b872d7f..62d009c 100644 --- a/src/zcl_http_agent.clas.xml +++ b/src/#apmg#cl_http_agent.clas.xml @@ -3,7 +3,7 @@ - ZCL_HTTP_AGENT + /APMG/CL_HTTP_AGENT E HTTP Agent 1 diff --git a/src/zcl_http_login_manager.clas.abap b/src/#apmg#cl_http_login_manager.clas.abap similarity index 66% rename from src/zcl_http_login_manager.clas.abap rename to src/#apmg#cl_http_login_manager.clas.abap index a6941cc..c49c7ef 100644 --- a/src/zcl_http_login_manager.clas.abap +++ b/src/#apmg#cl_http_login_manager.clas.abap @@ -1,4 +1,4 @@ -CLASS zcl_http_login_manager DEFINITION +CLASS /apmg/cl_http_login_manager DEFINITION PUBLIC FINAL CREATE PUBLIC. @@ -44,6 +44,12 @@ CLASS zcl_http_login_manager DEFINITION CLASS-DATA auths TYPE TABLE OF ty_auth WITH DEFAULT KEY. + CLASS-METHODS get_host + IMPORTING + !host TYPE string + RETURNING + VALUE(result) TYPE string. + CLASS-METHODS append IMPORTING !host TYPE string @@ -53,14 +59,16 @@ ENDCLASS. -CLASS zcl_http_login_manager IMPLEMENTATION. +CLASS /apmg/cl_http_login_manager IMPLEMENTATION. METHOD append. - IF NOT line_exists( auths[ host = host ] ). + DATA(hostname) = get_host( host ). + + IF NOT line_exists( auths[ host = hostname ] ). APPEND INITIAL LINE TO auths ASSIGNING FIELD-SYMBOL(). - -host = host. + -host = hostname. -auth = auth. ENDIF. @@ -76,7 +84,7 @@ CLASS zcl_http_login_manager IMPLEMENTATION. METHOD get. - READ TABLE auths INTO DATA(auth) WITH KEY host = host. + READ TABLE auths INTO DATA(auth) WITH KEY host = get_host( host ). IF sy-subrc = 0. result = auth-auth. ENDIF. @@ -84,6 +92,23 @@ CLASS zcl_http_login_manager IMPLEMENTATION. ENDMETHOD. + METHOD get_host. + + " If it's a URL, use host:port, otherwise just take the input + TRY. + DATA(url) = /apmg/cl_url=>parse( host )->components. + + result = url-host. + IF url-port IS NOT INITIAL. + result = |{ result }:{ url-port }|. + ENDIF. + CATCH /apmg/cx_error. + result = host. + ENDTRY. + + ENDMETHOD. + + METHOD save. IF auth IS NOT INITIAL. @@ -102,12 +127,10 @@ CLASS zcl_http_login_manager IMPLEMENTATION. RETURN. ENDIF. - result = cl_http_utility=>encode_base64( |{ username }:{ password }| ). - IF is_basic = abap_true. - result = |Basic { result }|. + result = |Basic { cl_http_utility=>encode_base64( |{ username }:{ password }| ) }|. ELSE. - result = |Bearer { result }|. + result = |Bearer { password }|. ENDIF. append( host = host diff --git a/src/zcl_http_login_manager.clas.testclasses.abap b/src/#apmg#cl_http_login_manager.clas.testclasses.abap similarity index 51% rename from src/zcl_http_login_manager.clas.testclasses.abap rename to src/#apmg#cl_http_login_manager.clas.testclasses.abap index 4903685..557c3a5 100644 --- a/src/zcl_http_login_manager.clas.testclasses.abap +++ b/src/#apmg#cl_http_login_manager.clas.testclasses.abap @@ -3,25 +3,27 @@ CLASS ltcl_login_manager DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHO PRIVATE SECTION. CONSTANTS: c_username TYPE string VALUE 'Aladdin', - c_password TYPE string VALUE 'OpenSesame'. + c_password TYPE string VALUE 'OpenSesame', + c_token TYPE string VALUE 'TestToken'. METHODS: setup, teardown, - encoding FOR TESTING, - save FOR TESTING, - same_server FOR TESTING. + basic_auth FOR TESTING RAISING /apmg/cx_error, + bearer_auth FOR TESTING RAISING /apmg/cx_error, + save FOR TESTING RAISING /apmg/cx_error, + same_server FOR TESTING RAISING /apmg/cx_error. ENDCLASS. CLASS ltcl_login_manager IMPLEMENTATION. METHOD setup. - zcl_http_login_manager=>clear( ). + /apmg/cl_http_login_manager=>clear( ). ENDMETHOD. METHOD teardown. - zcl_http_login_manager=>clear( ). + /apmg/cl_http_login_manager=>clear( ). ENDMETHOD. METHOD save. @@ -29,22 +31,23 @@ CLASS ltcl_login_manager IMPLEMENTATION. CONSTANTS c_host TYPE string VALUE 'https://abapgit.org/foo/bar'. CONSTANTS c_auth TYPE string VALUE 'foobar'. - zcl_http_login_manager=>save( + /apmg/cl_http_login_manager=>save( host = c_host auth = c_auth ). cl_abap_unit_assert=>assert_equals( - act = zcl_http_login_manager=>get( c_host ) + act = /apmg/cl_http_login_manager=>get( c_host ) exp = c_auth ). ENDMETHOD. - METHOD encoding. + METHOD basic_auth. - DATA(auth) = zcl_http_login_manager=>set( + DATA(auth) = /apmg/cl_http_login_manager=>set( host = 'https://github.com/abapGit/abapGit.git' username = c_username - password = c_password ). + password = c_password + is_basic = abap_true ). cl_abap_unit_assert=>assert_equals( act = auth @@ -52,18 +55,32 @@ CLASS ltcl_login_manager IMPLEMENTATION. ENDMETHOD. + METHOD bearer_auth. + + DATA(auth) = /apmg/cl_http_login_manager=>set( + host = 'https://github.com/abapGit/abapGit.git' + username = c_username + password = c_token + is_basic = abap_false ). + + cl_abap_unit_assert=>assert_equals( + act = auth + exp = |Bearer { c_token }| ). + + ENDMETHOD. + METHOD same_server. CONSTANTS: c_github1 TYPE string VALUE 'https://github.com/abapGit/abapGit.git', c_github2 TYPE string VALUE 'https://github.com/larshp/Foobar.git'. - zcl_http_login_manager=>set( + /apmg/cl_http_login_manager=>set( host = c_github1 username = c_username password = c_password ). - DATA(auth1) = zcl_http_login_manager=>get( c_github1 ). - DATA(auth2) = zcl_http_login_manager=>get( c_github2 ). + DATA(auth1) = /apmg/cl_http_login_manager=>get( c_github1 ). + DATA(auth2) = /apmg/cl_http_login_manager=>get( c_github2 ). cl_abap_unit_assert=>assert_equals( act = auth1 diff --git a/src/zcl_http_login_manager.clas.xml b/src/#apmg#cl_http_login_manager.clas.xml similarity index 90% rename from src/zcl_http_login_manager.clas.xml rename to src/#apmg#cl_http_login_manager.clas.xml index 510b28e..c1410e2 100644 --- a/src/zcl_http_login_manager.clas.xml +++ b/src/#apmg#cl_http_login_manager.clas.xml @@ -3,7 +3,7 @@ - ZCL_HTTP_LOGIN_MANAGER + /APMG/CL_HTTP_LOGIN_MANAGER E HTTP Login 1 diff --git a/src/zif_http_agent.intf.abap b/src/#apmg#if_http_agent.intf.abap similarity index 93% rename from src/zif_http_agent.intf.abap rename to src/#apmg#if_http_agent.intf.abap index 48f69ae..d9eacd4 100644 --- a/src/zif_http_agent.intf.abap +++ b/src/#apmg#if_http_agent.intf.abap @@ -1,4 +1,4 @@ -INTERFACE zif_http_agent PUBLIC. +INTERFACE /apmg/if_http_agent PUBLIC. ************************************************************************ * HTTP Agent @@ -46,8 +46,8 @@ INTERFACE zif_http_agent PUBLIC. !headers TYPE REF TO zcl_abap_string_map OPTIONAL !payload TYPE any OPTIONAL " can be char, string, xstring RETURNING - VALUE(result) TYPE REF TO zif_http_response + VALUE(result) TYPE REF TO /apmg/if_http_response RAISING - zcx_error. + /apmg/cx_error. ENDINTERFACE. diff --git a/src/zif_http_agent.intf.xml b/src/#apmg#if_http_agent.intf.xml similarity index 90% rename from src/zif_http_agent.intf.xml rename to src/#apmg#if_http_agent.intf.xml index 39f9fd8..a506324 100644 --- a/src/zif_http_agent.intf.xml +++ b/src/#apmg#if_http_agent.intf.xml @@ -3,7 +3,7 @@ - ZIF_HTTP_AGENT + /APMG/IF_HTTP_AGENT E HTTP Agent 2 diff --git a/src/zif_http_response.intf.abap b/src/#apmg#if_http_response.intf.abap similarity index 90% rename from src/zif_http_response.intf.abap rename to src/#apmg#if_http_response.intf.abap index 3afe6fa..87e871a 100644 --- a/src/zif_http_response.intf.abap +++ b/src/#apmg#if_http_response.intf.abap @@ -1,4 +1,4 @@ -INTERFACE zif_http_response PUBLIC. +INTERFACE /apmg/if_http_response PUBLIC. ************************************************************************ * HTTP Response @@ -19,7 +19,7 @@ INTERFACE zif_http_response PUBLIC. RETURNING VALUE(result) TYPE REF TO zif_ajson RAISING - zcx_error. + /apmg/cx_error. METHODS is_ok RETURNING @@ -37,7 +37,7 @@ INTERFACE zif_http_response PUBLIC. RETURNING VALUE(result) TYPE REF TO zcl_abap_string_map RAISING - zcx_error. + /apmg/cx_error. METHODS close. diff --git a/src/zif_http_response.intf.xml b/src/#apmg#if_http_response.intf.xml similarity index 89% rename from src/zif_http_response.intf.xml rename to src/#apmg#if_http_response.intf.xml index 21495ca..5304d92 100644 --- a/src/zif_http_response.intf.xml +++ b/src/#apmg#if_http_response.intf.xml @@ -3,7 +3,7 @@ - ZIF_HTTP_RESPONSE + /APMG/IF_HTTP_RESPONSE E HTTP Response 2