[Bps-public-commit] rt-extension-externalstorage-box branch, enable-rt-logger-in-storage-box, created. 8c335c47f41e9dd0bafe802a28666b18e614d679
Dave Goehrig
dave at bestpractical.com
Mon Sep 26 15:53:24 EDT 2016
The branch, enable-rt-logger-in-storage-box has been created
at 8c335c47f41e9dd0bafe802a28666b18e614d679 (commit)
- Log -----------------------------------------------------------------
commit 8c335c47f41e9dd0bafe802a28666b18e614d679
Author: Dave Goehrig <dave at bestpractical.com>
Date: Mon Sep 26 15:53:20 2016 -0400
activate RT->Logger in Storage::Box
Delegates Storage::Box::Logger to RT->Logger
diff --git a/lib/RT/Extension/ExternalStorage/Box.pm b/lib/RT/Extension/ExternalStorage/Box.pm
index 3445f27..3cadbd9 100644
--- a/lib/RT/Extension/ExternalStorage/Box.pm
+++ b/lib/RT/Extension/ExternalStorage/Box.pm
@@ -63,12 +63,17 @@ else {
with 'RT::Extension::ExternalStorage::Backend';
}
+use Storage::Box;
+use Storage::Box::Logger;
+
+$Storage::Box::Logger::delegate = RT->Logger;
+
our ( $Box );
sub Init {
my $self = shift;
my %self = %{$self};
-
+
if (not Storage::Box->require) {
RT->Logger->error("Required module Storage::Box is not installed");
return;
@@ -92,7 +97,7 @@ sub Init {
return;
}
- $Box = Storage::Box->new(
+ $Box = Storage::Box->new(
key_id => $self{KeyId},
enterprise_id => $self{EnterpriseId},
private_key => $self{PrivateKey},
@@ -117,20 +122,21 @@ sub Init {
);
}
$Box->user_id($user_id);
-
return $self;
}
sub Get {
my ($self,$key) = @_;
+ RT->Logger->info("Downloading $key");
my $contents = $Box->download_file($key);
- $contents;
+ $contents;
}
sub Store {
my ($self,$key,$content) = @_;
+ RT->Logger->info("Box Storing $key");
# we need to store the file locally for libcurl to be able to upload it
# this is a limitation of WWW::Curl::Form module, as it lacks support
# for the CURLFORM_BUFFER and CURLFORM_BUFFERPTR options, rather it only
@@ -139,101 +145,169 @@ sub Store {
open( my $fh, ">:raw", $key ) or return (undef, "Cannot write file to disk: $!");
print $fh $content or return (undef, "Cannot write file to disk: $!");
close $fh or return (undef, "Cannot write file to disk: $!");
-
+
+ RT->Logger->info("Created file $key");
my $file = $Box->create_file($key);
+ RT->Logger->info("Created file " . $file);
- unlink $key; # delete the file so we don't litter
+ unlink $key; # delete the file so we don't litter
return ($file); # we return the file_id for get to get it
}
+=pod
+
=head1 NAME
-RT::Extension::ExternalStorage::Box - Store attachments on box.com
+RT::Extension::ExternalStorage::Box
+
+=head1 SYNOPSIS
+
+ Plugin('RT::Extension::ExternalStorage');
+
+ Set(%ExternalStorage,
+ Type => 'Box',
+ KeyId => "box_com_key_id",
+ EnterpriseId => 'box_com_enterprise_id',
+ PrivateKey => "/opt/rt4/etc/keys/private_key.pem",
+ Password => "my_secret_password",
+ ClientId => "box_com_client_id",
+ ClientSecret => "box_com_client_secret");
+
+=head1 DESCRIPTION
+
+The C<RT::Extension::ExternalStorage::Box> package provides an interface
+that allows RT to store large attachments in Box.com's file storage. It
+requires setting up a custom enterprise application at Box.com attached
+to your enterprise account in order to enable creating an application
+managed Box.com user for RT, and provide a JWT based access credentials
+for RT.
+
+=head1 INSTALLATION
+
+
+=over
+
+=item 1.
+
+Install storage-box and rt-extension-externalstorage:
+
+ cpanm Storage::Box RT::Extension::ExternalStorage
+
+=item 2.
-=head1 SETUP
+Signup for an account at box.
-1.) Signup for an account at box.
+=item 3.
-2.) Login to developer.box.com or https://app.box.com/developers/services
+Login to developer.box.com or L<https://app.box.com/developers/services>
-3.) click Get Started if this is your first application
+=item 4.
-4.) create a unique name for your app, for example rt-myorganization
+Click Get Started if this is your first application
-OAuth2 Parameters:
+=item 5.
-5.) copy client_id and client_secret somewhere safe for later use
+Create a unique name for your app, for example rt-myorganization
-6.) Add a redirect uri, it must be https, but need not exist. We won't be using it anyways.
+=item 6.
-7.) under "Authentication Type" select "Server Authentication (OAuth2.0 with JWT)"
+Under OAuth parameters, copy C<client_id> and C<client_secret> somewhere safe for later use
-8.) under Scopes, Enterprise select:
-
- * Manage app users
+=item 7.
-9.) Before you can enable Public Key Managment, under Settings >> Security >>
+Add a redirect uri, it must be https, but need not exist. We won't be using it anyways.
- * select "Login verification: Require 2-step verification for unrecognized logins"
+=item 8.
-10.) Go back to your app and under Public Key Management
+Under C<Authentication Type> select C<Server Authentication (OAuth2.0 with JWT)>
- * Select "Add Public Key"
+=item 9.
-11.) Using openssl, generate a public / private key pair in pem format by either:
+Under Scopes, Enterprise select C<Manage app users>
- perl -Ilib -MStorage::Box::Auth -e 'Storage::Box::Auth->new->generate_keys("your_key_password_here")'
+=item 10.
-Or use openssl to generate a private rsa aes256 key of 2048 bytes long:
+Before you can enable Public Key Managment, under C<Settings / Security > select C<Login verification: Require 2-step verification for unrecognized logins>
+
+=item 11.
+
+Go back to your app and under Public Key Management, and select C<Add Public Key>
+
+=item 12.
+
+Using openssl, generate a private key with password in pem format by:
openssl genrsa -aes256 -out private_key.pem 2048
-and the corresponding public:
+=item 13.
+
+Using openssl, create the corresponding public key file:
openssl rsa -pubout -in private_key.pem -out public_key.pem
+=item 14.
+
Save your password where you put the client_id and client_secret!
-12.) Copy and paste your the contents of public_key.pem into the "Public Key" box and click "Verify" and then "Save", you may have to enter your F2A credentials again after this.
+=item 15.
+
+Copy and paste your public key into the C<Public Key> box and click C<Verify> and then C<Save>, you may have to enter your F2A credentials again after this.
+
+=item 16.
+
+Copy the Key ID next to Public Key 1 to the same safe place you are keeping your other secrets.
-13.) Copy the Key ID next to Public Key 1 to the same safe place you are keeping your other secrets.
+=item 17.
-14.) At the bottom of the page click "Save Applications"
+At the bottom of the page click C<Save Applications>
-15.) create a directory for your private and public keys in the rt4 install directory such as:
+=item 18.
- mkdir -p /opt/rt4/var/data/box.com
- mv *.pem /opt/rt4/var/data/box.com/
+create a directory for you private and public key in the rt4 install directory such as:
-16.) Under Settings >> Business Settings (or https://app.box.com/master/settings) find the field "Enterprise ID" and copy that to your list of secrets.
+ mkdir -p /opt/rt4/etc/keys
+ mv *.pem /opt/rt4/etc/keys/
-17.) Edit your RT_SiteConfig.pm file to enable the "Box" backend using the values you've saved in a safe place:
+=item 19.
- Plugin('RT::Extension::ExternalStorage::Box');
+Under C<Settings / Business Settings> find the field C<Enterprise ID> and copy that to your list of secrets.
+
+=item 20.
+
+Edit your RT_SiteConfig.pm file to enable the C<Box> backend using the values you've saved in a safe place:
+
+ Plugin('RT::Extension::ExternalStorage');
Set(%ExternalStorage,
- Type => 'Box',
- KeyId => 'KEY ID FROM STEP 13',
- EnterpriseId => 'ENTERPRISE ID FROM STEP 16',
- PrivateKey => '/opt/rt4/var/data/box.com/private_key.pem',
- Password => 'PASSWORD FROM STEP 11',
- ClientId => 'CLIENT ID FROM STEP 5',
- ClientSecret => 'CLIENT SECRET FROM STEP 5',
- );
+ Type => 'Box',
+ KeyId => "KEY ID FROM STEP 16",
+ EnterpriseId => 'ENTERPRISE ID FROM STEP 19',
+ PrivateKey => "/opt/rt4/etc/keys/private_key.pem",
+ Password => "PASSWORD FROM STEP 14",
+ ClientId => "CLIENT ID FROM STEP 6",
+ ClientSecret => "CLIENT SECRET FROM STEP 6");
+
+=item 21.
-18.) Trial run
+Trial run
Assuming your private key is installed and readable by your webserver process you should now have the integration working. If you're on RT 4.2, running:
/opt/rt4/local/plugins/RT-Extension-ExternalStorage/sbin/extract-attachments
-or on RT 4.4, running:
+or if you are on 4.4:
- /opt/rt4/sbin/sbin/rt-externalize-attachments
+ /opt/rt4/sbin/sbin/rt-externalize-attachments
by hand should copy the large files out of the current database and migrate them to Box.com.
-19.) Add the above script to a cron job, as described in the ExternalStorage documentation
+=item 22.
+
+Add the above script to a cron job, as described in the ExternalStorage documentation
+
+ 0 0 * * * root /opt/rt4/local/plugins/RT-Extension-ExternalStorage/sbin/extract-attachments
+
+=back
=head1 AUTHOR
@@ -243,11 +317,11 @@ Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>
All bugs should be reported via email to
- L<bug-RT-Extension-ExternalStorage-Box at rt.cpan.org|mailto:bug-RT-Extension-ExternalStorage-Box at rt.cpan.org>
+L<bug-RT-Extension-ExternalStorage-Box at rt.cpan.org|mailto:bug-RT-Extension-ExternalStorage-Box at rt.cpan.org>
or via the web at
- L<rt.cpan.org|http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-ExternalStorage-Box>.
+L<rt.cpan.org|http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-ExternalStorage-Box>.
=head1 COPYRIGHT
@@ -260,3 +334,4 @@ This is free software, licensed under:
=cut
1;
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list