Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging of license actions #77

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions src/edd/#mbtools#cl_edd.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.
DATA:
lv_endpoint TYPE string,
lv_data TYPE string,
lv_error TYPE string,
lo_json TYPE REF TO /mbtools/if_ajson.

LOG-POINT ID /mbtools/bc SUBKEY c_name FIELDS sy-datum sy-uzeit sy-uname.
Expand All @@ -189,26 +190,28 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.
IF lo_json->get_boolean( '/success' ) <> abap_true.
CASE lo_json->get_string( '/error' ).
WHEN 'missing'.
/mbtools/cx_exception=>raise( 'License doesn''t exist'(010) ).
lv_error = 'License doesn''t exist'(010).
WHEN 'missing_url'.
/mbtools/cx_exception=>raise( 'URL not provided'(011) ).
lv_error = 'URL not provided'(011).
WHEN 'license_not_activable'.
/mbtools/cx_exception=>raise( 'Attempting to activate a bundle''s parent license'(012) ).
lv_error = 'Attempting to activate a bundle''s parent license'(012).
WHEN 'disabled'.
/mbtools/cx_exception=>raise( 'License key revoked'(013) ).
lv_error = 'License key revoked'(013).
WHEN 'no_activations_left'.
/mbtools/cx_exception=>raise( 'No activations left'(014) ).
lv_error = 'No activations left'(014).
WHEN 'expired'.
/mbtools/cx_exception=>raise( 'License has expired'(015) ).
lv_error = 'License has expired'(015).
WHEN 'key_mismatch'.
/mbtools/cx_exception=>raise( 'License is not valid for this product'(016) ).
lv_error = 'License is not valid for this product'(016).
WHEN 'invalid_item_id'.
/mbtools/cx_exception=>raise( 'Invalid item ID'(017) ).
lv_error = 'Invalid item ID'(017).
WHEN 'item_name_mismatch'.
/mbtools/cx_exception=>raise( 'License is not valid for this product'(018) ).
lv_error = 'License is not valid for this product'(018).
WHEN OTHERS.
/mbtools/cx_exception=>raise( 'License is not valid for this product'(018) ).
lv_error = 'License is not valid for this product'(018).
ENDCASE.
gi_log->e( lv_error ).
/mbtools/cx_exception=>raise( lv_error ).
ENDIF.

IF lo_json->get_string( '/license' ) = 'valid' ##NO_TEXT.
Expand All @@ -219,6 +222,8 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.

ev_expire = lv_data(4) && lv_data+5(2) && lv_data+8(2).

gi_log->s( |License activated and valid until { ev_expire }| ).

ENDMETHOD.


Expand Down Expand Up @@ -280,6 +285,7 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.
DATA:
lv_endpoint TYPE string,
lv_data TYPE string,
lv_error TYPE string,
lo_json TYPE REF TO /mbtools/if_ajson.

LOG-POINT ID /mbtools/bc SUBKEY c_name FIELDS sy-datum sy-uzeit sy-uname.
Expand All @@ -300,18 +306,20 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.
IF lo_json->get_boolean( '/success' ) <> abap_true.
CASE lo_json->get_string( '/error' ).
WHEN 'disabled'.
/mbtools/cx_exception=>raise( 'License key revoked'(001) ).
lv_error = 'License key revoked'(001).
WHEN 'expired'.
/mbtools/cx_exception=>raise( 'License has expired'(002) ).
lv_error = 'License has expired'(002).
WHEN 'key_mismatch'.
/mbtools/cx_exception=>raise( 'License is not valid for this product'(003) ).
lv_error = 'License is not valid for this product'(003).
WHEN 'invalid_item_id'.
/mbtools/cx_exception=>raise( 'Invalid item ID'(004) ).
lv_error = 'Invalid item ID'(004).
WHEN 'item_name_mismatch'.
/mbtools/cx_exception=>raise( 'License is not valid for this product'(005) ).
lv_error = 'License is not valid for this product'(005).
WHEN OTHERS.
/mbtools/cx_exception=>raise( 'License is not valid for this product'(006) ).
lv_error = 'License is not valid for this product'(006).
ENDCASE.
gi_log->e( lv_error ).
/mbtools/cx_exception=>raise( lv_error ).
ENDIF.

IF lo_json->get_string( '/license' ) = 'valid' ##NO_TEXT.
Expand All @@ -322,6 +330,8 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.

ev_expire = lv_data(4) && lv_data+5(2) && lv_data+8(2).

gi_log->s( |License valid until { ev_expire }| ).

ENDMETHOD.


Expand Down Expand Up @@ -355,8 +365,10 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.
lo_json = _get_json( lv_data ).

IF lo_json->get_boolean( '/success' ) <> abap_true.
" Probably wasn't a valid license in the first place. Ignore errors.
rv_result = abap_true.
" Probably wasn't a valid license in the first place. Log error and ignore it.
gi_log->e( |Error deactivating license| ).
ELSE.
gi_log->s( |License deactivated| ).
ENDIF.

rv_result = abap_true.
Expand Down Expand Up @@ -432,9 +444,12 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.
iv_headers = abap_true ).
ENDIF.
CATCH /mbtools/cx_ajson_error INTO lx_error.
gi_log->e( |Error checking version { lx_error->get_text( ) }| ).
/mbtools/cx_exception=>raise( lx_error->get_text( ) ).
ENDTRY.

gi_log->s( |New version: { ev_version }| ).

ENDMETHOD.


Expand Down Expand Up @@ -468,10 +483,13 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.

LOOP AT ct_products ASSIGNING <ls_product>.

gi_log->i( |Product : { <ls_product>-id }| ).

lo_json = lo_json_all->slice( condense( |/{ <ls_product>-id }| ) ).

lv_msg = lo_json->get_string( '/msg' ).
IF lv_msg IS NOT INITIAL AND lv_msg NS 'No license key'.
gi_log->e( |Error: { lv_msg }| ).
/mbtools/cx_exception=>raise( lv_msg ).
ENDIF.

Expand Down Expand Up @@ -503,9 +521,12 @@ CLASS /mbtools/cl_edd IMPLEMENTATION.
iv_headers = abap_true ).
ENDIF.
CATCH /mbtools/cx_ajson_error INTO lx_error.
gi_log->e( |Error: { lx_error->get_text( ) }| ).
/mbtools/cx_exception=>raise( lx_error->get_text( ) ).
ENDTRY.

gi_log->s( |New version: { <ls_product>-version }| ).

ENDLOOP.

ENDMETHOD.
Expand Down
Loading