<commit_before>%%%-------------------------------------------------------------------
%%% @author <NAME>
%%% @copyright (C) 2016 ACK CYFRONET AGH
%%% This software is released under the MIT license
%%% cited in 'LICENSE.txt'.
%%% @end
%%%-------------------------------------------------------------------
%%% @doc
%%% This module implements callback_backend_behaviour.
%%% It is used to handle RPC calls from clients with no session.
%%% @end
%%%-------------------------------------------------------------------
-module(public_rpc_backend).
-author("<NAME>").
-behaviour(rpc_backend_behaviour).

-include("gui/common.hrl").
-include_lib("ctool/include/logging.hrl").

%% API
-export([handle/2]).


%%%===================================================================
%%% API functions
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc
%% {@link rpc_backend_behaviour} callback handle/2.
%% @end
%%--------------------------------------------------------------------
-spec handle(FunctionId :: binary(), RequestData :: term()) ->
    ok | {ok, ResponseData :: term()} | gui_error:error_result().
handle(<<"getZoneName">>, _) ->
    {ok, ZoneName} = application:get_env(?APP_NAME, oz_name),
    {ok, [
        {<<"zoneName">>, str_utils:to_binary(ZoneName)}
    ]};

handle(<<"getSupportedAuthorizers">>, _) ->
    case application:get_env(?APP_NAME, dev_mode) of
        {ok, true} ->
            % If dev mode is enabled, always return basic auth and just one
            % dummy provider which will redirect to /dev_login page.
            {ok, [
                {<<"authorizers">>, [<<"basicAuth">>, <<"plgrid">>]}
            ]};
        _ ->
            % Production mode, return providers from config
            % get_auth_providers() returns list of atoms
            ProvidersAtoms = auth_config:get_auth_providers(),
            Providers =
                [str_utils:to_binary(Provider) || Provider <- ProvidersAtoms],
            {ok, [
                {<<"authorizers">>, Providers}
            ]}<commit_msg>VFS-3181 Add an RPC call to retrieve service version info<commit_after>%%%-------------------------------------------------------------------
%%% @author <NAME>piola
%%% @copyright (C) 2016 ACK CYFRONET AGH
%%% This software is released under the MIT license
%%% cited in 'LICENSE.txt'.
%%% @end
%%%-------------------------------------------------------------------
%%% @doc
%%% This module implements callback_backend_behaviour.
%%% It is used to handle RPC calls from clients with no session.
%%% @end
%%%-------------------------------------------------------------------
-module(public_rpc_backend).
-author("<NAME>").
-behaviour(rpc_backend_behaviour).

-include("gui/common.hrl").
-include_lib("ctool/include/logging.hrl").

%% API
-export([handle/2]).


%%%===================================================================
%%% API functions
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc
%% {@link rpc_backend_behaviour} callback handle/2.
%% @end
%%--------------------------------------------------------------------
-spec handle(FunctionId :: binary(), RequestData :: term()) ->
    ok | {ok, ResponseData :: term()} | gui_error:error_result().
handle(<<"getZoneName">>, _) ->
    {ok, ZoneName} = application:get_env(?APP_NAME, oz_name),
    {_AppId, _AppName, AppVersion} = lists:keyfind(
        ?APP_NAME, 1, application:loaded_applications()
    ),
    {ok, [
        {<<"zoneName">>, str_utils:to_binary(ZoneName)},
        {<<"serviceVersion">>, str_utils:to_binary(AppVersion)}
    ]};

handle(<<"getSupportedAuthorizers">>, _) ->
    case application:get_env(?APP_NAME, dev_mode) of
        {ok, true} ->
            % If dev mode is enabled, always return basic auth and just one
            % dummy provider which will redirect to /dev_login page.
            {ok, [
                {<<"authorizers">>, [<<"basicAuth">>, <<"plgrid">>]}
            ]};
        _ ->
            % Production mode, return providers from config
            % get_auth_providers() returns list of atoms
            ProvidersAtoms = auth_config:get_auth_providers(),
            Providers =
                [str_utils:to_binary(Provider) || Provider <- ProvidersAtoms],
            {ok, [
                {<<"authorizers">>, Providers}
            ]}
{'fraction_non_alphanumeric': 0.3419585099263886, 'fraction_numerical': 0.0037921035021191165, 'mean_word_length': 1.867007672634271, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '359601', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1129, 'n_words': 264}