<commit_before>package API::DeliveryService::KeysUrlSig;
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#

use Mojo::Base 'Mojolicious::Controller';
use Data::Dumper;
use API::Keys;
use Utils::Helper;
use JSON;
use UI::Utils;
use constant URL_SIG_KEYS_BUCKET => "url_sig_keys";
use Exporter qw(import);
our @EXPORT_OK = qw(URL_SIG_KEYS_BUCKET);

sub view_by_xmlid {
	my $self                = shift;
	my $xml_id              = $self->param('xmlId');
	my $config_file = $self->url_sig_config_file_name($xml_id);
	my $response_container  = $self->riak_get( URL_SIG_KEYS_BUCKET, $config_file );
	my $rc                  = $response_container->{"response"}->{_rc};
	if ( $rc eq '200' ) {
		my $url_sig_values_json = $response_container->{"response"}->{_content};
		return $self->success($url_sig_values_json);
	} else {
		my $error_msg = $response_container->{"response"}->{_content};
		$self->app->log->debug("received error code '$rc' from riak: '$error_msg'");
		return $self->alert("Unable to retrieve keys from Delivery Service '$xml_id'");
	} 
}

sub copy_url_sig_keys {
	my $self                = shift;
	my $xml_id              = $self->param('xmlId'); #copying to this service
	my $copy_from_xml_id    = $self->param('copyFromXmlId'); # copying from this service

	my $current_user = $self->current_user()->{username};

	#check ds and generate config file name
	my $rs = $self->db->resultset("Deliveryservice")->find( { xml_id => $xml_id } ); 
	my $ds_id;
	if ( defined($rs) ) {
		$ds_id = $rs->id;
	}
	else {
		return $self->alert("Delivery Service '$xml_id' does not exist.");
	}
	my $config_file = $self->url_sig_config_file_name($xml_id);

	#check ds to copy from and generate config file name
	my $copy_rs = $self->db->resultset("Deliveryservice")->find( { xml_id => $copy_from_xml_id } );
	my $copy_ds_id;
	if ( defined($copy_rs) ) {
		$copy_ds_id = $copy_rs->id;
	}
	else {
		return $self->alert("Delivery Service to copy from '$copy_from_xml_id' does not exist.");
	}
	my $copy_config_file = $self->url_sig_config_file_name($copy_from_xml_id);

	my $helper = new Utils::Helper( { mojo => $self } );
	my $url_sig_key_values_json;

	#verify we can copy keys out
	if ( $helper->is_valid_delivery_service($copy_ds_id) ) {
		if ( &is_admin($self) || $helper->is_delivery_service_assigned($copy_ds_id) ) {
			my $response_container = $self->riak_get( URL_SIG_KEYS_BUCKET, $copy_config_file ); # verify this
			my $rc                 = $response_container->{"response"}->{_rc};
			if ( $rc eq '200' ) {
				$url_sig_key_values_json = $response_container->{"response"}->{_content};
			}
			else {
				my $error_msg = $response_container->{"response"}->{_content};
				$self->app->log->debug("received error code '$rc' from riak: '$error_msg'");
			}
		}
		else {
			return $self->forbidden("Forbidden. Delivery service to copy from not assigned to user.");
		}
	}
	else {
		return $self->alert("Delivery Service to copy from '$copy_from_xml_id' is not a valid delivery service.");
	}

	if ( defined($url_sig_key_values_json) ) { # verify we got keys copied
		# Admins can always do this, otherwise verify the user
		if ( $helper->is_valid_delivery_service($ds_id) ) {
			if ( &is_admin($self) || $helper->is_delivery_service_assigned($ds_id) ) {
				$self->app->log->debug( "url_sig_key_values_json #-> " . $url_sig_key_values_json );
				my $response_container = $self->riak_put( URL_SIG_KEYS_BUCKET, $config_file, $url_sig_key_values_json );
				my $response           = $response_container->{"response"};
				my $rc                 = $response->{_rc};
				if ( $rc eq '204' ) {
					return $self->success_message("Successfully copied and stored keys");
				}
				else {
					my $error_msg = $response->{_content};
					$self->app->log->debug("received error code '$rc' from riak: '$error_msg'");
					return $self->alert( $response->{_content} );
				}
			}
			else {
				return $self->forbidden("Forbidden. Delivery service not assigned to user.");
			}
		}
		else {
			return $self->alert("Delivery Service '$xml_id' is not a valid delivery service.");
		}
	}
	else {
		return $self->alert("Unable to retrieve keys from Delivery Service '$copy_from_xml_id'");
	}
}
<commit_msg>change riak logging in url sig key copy to warns based on feedback<commit_after>package API::DeliveryService::KeysUrlSig;
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#

use Mojo::Base 'Mojolicious::Controller';
use Data::Dumper;
use API::Keys;
use Utils::Helper;
use JSON;
use UI::Utils;
use constant URL_SIG_KEYS_BUCKET => "url_sig_keys";
use Exporter qw(import);
our @EXPORT_OK = qw(URL_SIG_KEYS_BUCKET);

sub view_by_xmlid {
	my $self                = shift;
	my $xml_id              = $self->param('xmlId');
	my $config_file = $self->url_sig_config_file_name($xml_id);
	my $response_container  = $self->riak_get( URL_SIG_KEYS_BUCKET, $config_file );
	my $rc                  = $response_container->{"response"}->{_rc};
	if ( $rc eq '200' ) {
		my $url_sig_values_json = $response_container->{"response"}->{_content};
		return $self->success($url_sig_values_json);
	} else {
		my $error_msg = $response_container->{"response"}->{_content};
		$self->app->log->debug("received error code '$rc' from riak: '$error_msg'");
		return $self->alert("Unable to retrieve keys from Delivery Service '$xml_id'");
	} 
}

sub copy_url_sig_keys {
	my $self                = shift;
	my $xml_id              = $self->param('xmlId'); #copying to this service
	my $copy_from_xml_id    = $self->param('copyFromXmlId'); # copying from this service

	my $current_user = $self->current_user()->{username};
	my $is_admin = &is_admin($self);
	#check ds and generate config file name
	my $rs = $self->db->resultset("Deliveryservice")->find( { xml_id => $xml_id } ); 
	my $ds_id;
	if ( defined($rs) ) {
		$ds_id = $rs->id;
	}
	else {
		return $self->alert("Delivery Service '$xml_id' does not exist.");
	}
	my $config_file = $self->url_sig_config_file_name($xml_id);

	#check ds to copy from and generate config file name
	my $copy_rs = $self->db->resultset("Deliveryservice")->find( { xml_id => $copy_from_xml_id } );
	my $copy_ds_id;
	if ( defined($copy_rs) ) {
		$copy_ds_id = $copy_rs->id;
	}
	else {
		return $self->alert("Delivery Service to copy from '$copy_from_xml_id' does not exist.");
	}
	my $copy_config_file = $self->url_sig_config_file_name($copy_from_xml_id);

	my $helper = new Utils::Helper( { mojo => $self } );
	my $url_sig_key_values_json;

	#verify we can copy keys out
	if ( $helper->is_valid_delivery_service($copy_ds_id) ) {
		if ( $is_admin || $helper->is_delivery_service_assigned($copy_ds_id) ) {
			my $response_container = $self->riak_get( URL_SIG_KEYS_BUCKET, $copy_config_file ); # verify this
			my $rc                 = $response_container->{"response"}->{_rc};
			if ( $rc eq '200' ) {
				$url_sig_key_values_json = $response_container->{"response"}->{_content};
			}
			else {
				my $error_msg = $response_container->{"response"}->{_content};
				$self->app->log->warn("received error code '$rc' from riak: '$error_msg'");
			}
		}
		else {
			return $self->forbidden("Forbidden. Delivery service to copy from not assigned to user.");
		}
	}
	else {
		return $self->alert("Delivery Service to copy from '$copy_from_xml_id' is not a valid delivery service.");
	}

	if ( defined($url_sig_key_values_json) ) { # verify we got keys copied
		# Admins can always do this, otherwise verify the user
		if ( $helper->is_valid_delivery_service($ds_id) ) {
			if ( $is_admin || $helper->is_delivery_service_assigned($ds_id) ) {
				$self->app->log->debug( "url_sig_key_values_json #-> " . $url_sig_key_values_json );
				my $response_container = $self->riak_put( URL_SIG_KEYS_BUCKET, $config_file, $url_sig_key_values_json );
				my $response           = $response_container->{"response"};
				my $rc                 = $response->{_rc};
				if ( $rc eq '204' ) {
					return $self->success_message("Successfully copied and stored keys");
				}
				else {
					my $error_msg = $response->{_content};
					$self->app->log->warn("received error code '$rc' from riak: '$error_msg'");
					return $self->alert( $response->{_content} );
				}
			}
			else {
				return $self->forbidden("Forbidden. Delivery service not assigned to user.");
			}
		}
		else {
			return $self->alert("Delivery Service '$xml_id' is not a valid delivery service.");
		}
	}
	else {
		return $self->alert("Unable to retrieve keys from Delivery Service '$copy_from_xml_id'");
	}
}

{'fraction_non_alphanumeric': 0.1454410831394119, 'fraction_numerical': 0.0027501586629997883, 'mean_word_length': 4.015915119363395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 38}, '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': '6739125', 'n_tokens_mistral': 3449, 'n_tokens_neox': 3220, 'n_words': 813}