"Fossies" - the Fresh Open Source Software Archive

Member "otrs-5.0.40/Kernel/System/Console/Command/Admin/WebService/Add.pm" (12 Dec 2019, 2724 Bytes) of package /linux/www/otrs-5.0.40.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Add.pm" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: rel-6_0_25_vs_rel-6_0_26.

    1 # --
    2 # Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
    3 # --
    4 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
    5 # the enclosed file COPYING for license information (GPL). If you
    6 # did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
    7 # --
    8 
    9 package Kernel::System::Console::Command::Admin::WebService::Add;
   10 
   11 use strict;
   12 use warnings;
   13 
   14 use base qw(Kernel::System::Console::BaseCommand);
   15 
   16 our @ObjectDependencies = (
   17     'Kernel::System::GenericInterface::Webservice',
   18     'Kernel::System::Main',
   19     'Kernel::System::YAML',
   20 );
   21 
   22 sub Configure {
   23     my ( $Self, %Param ) = @_;
   24 
   25     $Self->Description('Create a new web service.');
   26     $Self->AddOption(
   27         Name        => 'name',
   28         Description => "The name of the new web service.",
   29         Required    => 1,
   30         HasValue    => 1,
   31         ValueRegex  => qr/.*/smx,
   32     );
   33     $Self->AddOption(
   34         Name        => 'source-path',
   35         Description => "Specify the location of the web service YAML configuration file",
   36         Required    => 1,
   37         HasValue    => 1,
   38         ValueRegex  => qr/.*/smx,
   39     );
   40 
   41     return;
   42 }
   43 
   44 sub PreRun {
   45     my ( $Self, %Param ) = @_;
   46 
   47     my $SourcePath = $Self->GetOption('source-path');
   48     if ( !-r $SourcePath ) {
   49         die "Source file $SourcePath does not exist / is not readable.\n";
   50     }
   51 
   52     my $List             = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceList();
   53     my %WebServiceLookup = reverse %{$List};
   54 
   55     my $Name = $Self->GetOption('name');
   56     if ( $WebServiceLookup{$Name} ) {
   57         die "A web service with name $Name already exists in this system.\n";
   58     }
   59 
   60     return;
   61 }
   62 
   63 sub Run {
   64     my ( $Self, %Param ) = @_;
   65 
   66     $Self->Print("<yellow>Creating web service...</yellow>\n");
   67 
   68     # read config
   69     my $Content = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
   70         Location => $Self->GetOption('source-path'),
   71     );
   72     if ( !$Content ) {
   73         $Self->PrintError('Could not read YAML source.');
   74         return $Self->ExitCodeError();
   75     }
   76 
   77     my $Config = $Kernel::OM->Get('Kernel::System::YAML')->Load( Data => ${$Content} );
   78 
   79     if ( !$Config ) {
   80         $Self->PrintError('Could not parse YAML source.');
   81         return $Self->ExitCodeError();
   82     }
   83 
   84     # add new web service
   85     my $ID = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceAdd(
   86         Name    => $Self->GetOption('name'),
   87         Config  => $Config,
   88         ValidID => 1,
   89         UserID  => 1,
   90     );
   91 
   92     if ( !$ID ) {
   93         $Self->PrintError('Could not create web service!');
   94         return $Self->ExitCodeError();
   95     }
   96 
   97     $Self->Print("<green>Done.</green>\n");
   98     return $Self->ExitCodeOk();
   99 }
  100 
  101 1;