| 1 | package Redcentric::Roles::OCIP; | ||
| 2 | |||
| 3 | # ABSTRACT: OCI-P access role for Broadworks CLI programs | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use namespace::autoclean; | ||
| 8 | |||
| 9 | our $VERSION = '0.08'; # VERSION | ||
| 10 | our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY | ||
| 11 | |||
| 12 | use Method::Signatures; | ||
| 13 | use Moose::Role; # optional | ||
| 14 | use MooseX::App::Role; | ||
| 15 | use Digest::SHA1 qw( sha1_hex ); | ||
| 16 | use Broadworks::OCIP; | ||
| 17 | |||
| 18 | |||
| 19 | option oci_host => ( | ||
| 20 | is => 'ro', | ||
| 21 | isa => 'Str', | ||
| 22 | documentation => 'Broadworks host to connect to', | ||
| 23 | required => 1, | ||
| 24 | ); | ||
| 25 | |||
| 26 | # ------------------------------------------------------------------------ | ||
| 27 | |||
| 28 | |||
| 29 | option oci_port => ( | ||
| 30 | is => 'ro', | ||
| 31 | isa => 'Int', | ||
| 32 | default => 2208, | ||
| 33 | documentation => 'Port to connect to on Broadworks host', | ||
| 34 | ); | ||
| 35 | |||
| 36 | # ------------------------------------------------------------------------ | ||
| 37 | |||
| 38 | |||
| 39 | option oci_username => ( | ||
| 40 | is => 'ro', | ||
| 41 | isa => 'Str', | ||
| 42 | documentation => 'Username for authentication to Broadworks host', | ||
| 43 | required => 1, | ||
| 44 | ); | ||
| 45 | |||
| 46 | # ------------------------------------------------------------------------ | ||
| 47 | |||
| 48 | |||
| 49 | option oci_password => ( | ||
| 50 | is => 'ro', | ||
| 51 | isa => 'Str', | ||
| 52 | clearer => 'clear_oci_password', | ||
| 53 | documentation => 'Password for Broadworks host (or use authhash)', | ||
| 54 | ); | ||
| 55 | |||
| 56 | # ------------------------------------------------------------------------ | ||
| 57 | |||
| 58 | |||
| 59 | option oci_authhash => ( | ||
| 60 | is => 'ro', | ||
| 61 | isa => 'Str', | ||
| 62 | documentation => 'Hashed authentication token for Broadworks host (can derive from oci_password)', | ||
| 63 | builder => '_build_oci_authhash', | ||
| 64 | lazy => 1, | ||
| 65 | ); | ||
| 66 | |||
| 67 | method _build_oci_authhash () { | ||
| 68 | my $oci_password = $self->oci_password || die "No oci_password was set"; | ||
| 69 | my $authhash = lc( sha1_hex($oci_password) ); | ||
| 70 | $self->clear_oci_password; | ||
| 71 | return $authhash; | ||
| 72 | } | ||
| 73 | |||
| 74 | # ---------------------------------------------------------------------- | ||
| 75 | |||
| 76 | has oci => ( | ||
| 77 | is => 'ro', | ||
| 78 | isa => 'Object', | ||
| 79 | clearer => 'clear_oci', | ||
| 80 | builder => '_build_oci', | ||
| 81 | lazy => 1, | ||
| 82 | ); | ||
| 83 | |||
| 84 | method _build_oci () { | ||
| 85 | my $args = {}; | ||
| 86 | foreach my $arg (qw[username authhash host port]) { | ||
| 87 | my $method = 'oci_' . $arg; | ||
| 88 | $args->{$arg} = $self->$method; | ||
| 89 | } | ||
| 90 | $args->{trace} = 1 if ( $self->debug ); | ||
| 91 | return Broadworks::OCIP->new($args); | ||
| 92 | } | ||
| 93 | |||
| 94 | # ------------------------------------------------------------------------ | ||
| 95 | |||
| 96 | 1; | ||
| 97 | |||
| 98 | __END__ | ||
| 99 | |||
| 100 | =pod | ||
| 101 | |||
| 102 | =encoding UTF-8 | ||
| 103 | |||
| 104 | =head1 NAME | ||
| 105 | |||
| 106 | Redcentric::Roles::OCIP - OCI-P access role for Broadworks CLI programs | ||
| 107 | |||
| 108 | =head1 VERSION | ||
| 109 | |||
| 110 | version 0.08 | ||
| 111 | |||
| 112 | =for test_synopsis 1; | ||
| 113 | __END__ | ||
| 114 | |||
| 115 | =for stopwords NIGELM Broadworks OCI authhash programmes | ||
| 116 | |||
| 117 | =for Pod::Coverage mvp_multivalue_args | ||
| 118 | |||
| 119 | # ------------------------------------------------------------------------ | ||
| 120 | |||
| 121 | =head1 SUMMARY | ||
| 122 | |||
| 123 | This is a role for L<MooseX::App> CLI programmes which adds a Broadworks OCI-P | ||
| 124 | role for access a Broadworks voice platform. | ||
| 125 | |||
| 126 | # ------------------------------------------------------------------------ | ||
| 127 | |||
| 128 | =head3 oci_host | ||
| 129 | |||
| 130 | The host that is being connected to - either a host name or an IP address. | ||
| 131 | |||
| 132 | =head3 oci_port | ||
| 133 | |||
| 134 | The port number to connect to - default C<2208>. | ||
| 135 | |||
| 136 | =head3 oci_username | ||
| 137 | |||
| 138 | The username to authenticate with on the remote system. | ||
| 139 | |||
| 140 | =head3 oci_password | ||
| 141 | |||
| 142 | A password to use for authenticating the username. This is transformed into an | ||
| 143 | authhash and the original password cleared. | ||
| 144 | |||
| 145 | =head3 oci_authhash | ||
| 146 | |||
| 147 | An authentication hash to use for authenticating the username. Alternatively | ||
| 148 | the oci_password attribute can be set and this is transformed into an | ||
| 149 | appropriate authhash (and the oci_password deleted). | ||
| 150 | |||
| 151 | =head1 AUTHOR | ||
| 152 | |||
| 153 | Nigel Metheringham <nigelm@cpan.org> | ||
| 154 | |||
| 155 | =head1 COPYRIGHT AND LICENSE | ||
| 156 | |||
| 157 | This software is copyright (c) 2018 by Nigel Metheringham. | ||
| 158 | |||
| 159 | This is free software; you can redistribute it and/or modify it under | ||
| 160 | the same terms as the Perl 5 programming language system itself. | ||
| 161 | |||
| 162 | =cut |