Skip to content

Commit

Permalink
Modified error message for license expiry case (#3926)
Browse files Browse the repository at this point in the history
Signed-off-by: jan shahid shaik <[email protected]>
  • Loading branch information
jashaik authored Oct 23, 2024
1 parent cda60fb commit c748ca0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/oc_erchef/apps/chef_license/src/chef_license_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ check_license(State) ->
State#state{license_cache=commercial_grace_period, grace_period=true, scanned_time = erlang:timestamp(), expiration_date=ExpDate, message=Msg};
{ok, trial_expired, ExpDate, Msg} ->
State#state{license_cache=trial_expired_expired, license_type = <<"trial">>, grace_period=undefined, scanned_time = erlang:timestamp(), expiration_date=ExpDate, message=Msg};
{error, no_license} ->
State#state{license_cache=trial_expired_expired, license_type = <<"trial">>, grace_period=undefined, scanned_time = erlang:timestamp(), expiration_date="", message=get_alert_message(trial_expired, "")};
{error, _} -> State
end.

Expand Down Expand Up @@ -133,16 +135,23 @@ process_license(LicJson) ->
_ ->
{error, invalid_response}
end;
undefined ->
case ej:get({<<"status">>}, LicJson) of
<<"OK">> ->
{error, no_license};
_ ->
{error, invalid_response}
end;
_ ->
{error, invalid_response}
end.

get_alert_message(Type, ExpDate)->
case Type of
trial_expired ->
"Your Progress Chef InfraServer license has expired or does not exist! You no longer have access to Chef Automate. Please contact the Account Team to upgrade to an Enterprise License.";
"Your Progress Chef InfraServer license has expired or does not exist! You no longer have access to Chef InfraServer. Please contact the Account Team to upgrade to an Enterprise License.";
commercial_expired ->
"Your Progress Chef InfraServer license expired on " ++ ExpDate ++ " and you no longer have access to Chef Automate! To get a new license, please contact the Account Team or email us at [email protected]";
"Your Progress Chef InfraServer license expired on " ++ ExpDate ++ " and you no longer have access to Chef InfraServer! To get a new license, please contact the Account Team or email us at [email protected]";
commercial_grace_period ->
"Your Progress Chef InfraServer license expired on " ++ ExpDate ++ " and you are currently on a limited extension period! To get a new license, please contact the Account Team or email us at [email protected]"
end.
Expand Down
3 changes: 2 additions & 1 deletion src/oc_erchef/apps/oc_chef_wm/src/oc_chef_wm.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
goldrush,
lager,
eldap,
data_collector
data_collector,
chef_license
]},
{mod, {oc_chef_wm_app, []}},
{env, []}
Expand Down
6 changes: 3 additions & 3 deletions src/oc_erchef/apps/oc_chef_wm/src/oc_chef_wm_base.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ service_available(Req, #base_state{reqid_header_name = HeaderName} = State) ->
XOps = binary_to_list(chef_json:encode({[{<<"licenseType">>, Type},{<<"expirationDateTime">>, list_to_binary(ExpDate)},
{<<"warningMessage">>, list_to_binary(LicWarnMsg)}]})),
Req1 = wrq:set_resp_header("X-Ops-License", XOps, Req),
Req2 = chef_wm_util:set_json_body(Req1, {[{<<"error">>, <<"invalid-license">>},
{<<"message">>, list_to_binary(LicWarnMsg)}]}),
{{halt, 402}, Req2, State#base_state{log_msg = invalid_license}};
Req2 = chef_wm_util:set_json_body(Req1, {[{<<"error">>, list_to_binary(LicWarnMsg)},
{<<"message">>, <<"invalid-license">>}]}),
{{halt, 403}, Req2, State#base_state{log_msg = invalid_license}};
_ ->
{true, Req, State3}
end
Expand Down

0 comments on commit c748ca0

Please sign in to comment.