@@ -7,7 +7,7 @@ package Metabrik::Api::Onyphe;
77use strict;
88use warnings;
99
10- our $VERSION = ' 3.02 ' ;
10+ our $VERSION = ' 3.03 ' ;
1111
1212use base qw( Metabrik::Client::Rest) ;
1313
@@ -21,6 +21,7 @@ sub brik_properties {
2121 url => [ qw( url) ],
2222 key => [ qw( key) ],
2323 wait => [ qw( seconds) ],
24+ auth => [ qw( user:pass) ],
2425 _maxpage => [ qw( INTERNAL) ],
2526 _sj => [ qw( INTERNAL) ],
2627 },
@@ -49,6 +50,7 @@ sub brik_properties {
4950 },
5051 require_modules => {
5152 ' Metabrik::String::Json' => [ ],
53+ ' Metabrik::String::Base64' => [ ],
5254 ' Metabrik::File::Text' => [ ],
5355 ' AnyEvent' => [ ],
5456 ' AnyEvent::HTTP' => [ ],
@@ -81,9 +83,17 @@ sub api_standard {
8183 my $wait = $self -> wait;
8284 my $url = $self -> url;
8385 my $key = $self -> key;
86+ my $auth = $self -> auth;
87+ my ($username , $password ); ($username , $password ) = split (' :' , $auth )
88+ if defined ($auth );
89+
90+ if (defined ($username ) && defined ($password )) {
91+ $self -> username($username );
92+ $self -> password($password );
93+ }
8494
8595 $self -> add_headers({
86- ' Authorization' => " apikey $key " ,
96+ ' Authorization' => " bearer $key " ,
8797 ' Content-Type' => ' application/json' ,
8898 });
8999
@@ -103,8 +113,16 @@ sub api_standard {
103113 push @args , $k .' =' .$arg -> {$k };
104114 }
105115 }
116+ if (defined ($username ) && defined ($password )) {
117+ push @args , " k=$key " ;
118+ }
106119 $url .= ' ?' .join (' &' , @args );
107120 }
121+ else {
122+ if (defined ($username ) && defined ($password )) {
123+ $url .= ' ?k=' .$key ;
124+ }
125+ }
108126
109127 $self -> log -> verbose(" api_standard: using url[$url ]" );
110128
@@ -169,6 +187,16 @@ sub api_streaming {
169187 my $sj = $self -> _sj;
170188 my $url = $self -> url;
171189 my $key = $self -> key;
190+ my $auth = $self -> auth;
191+ my ($username , $password ); ($username , $password ) = split (' :' , $auth )
192+ if defined ($auth );
193+
194+ my $basic ;
195+ if (defined ($username ) && defined ($password )) {
196+ my $sb = Metabrik::String::Base64-> new_from_brik_init($self )
197+ or return ;
198+ $basic = " Basic " .$sb -> encode($auth );
199+ }
172200
173201 if ($req eq " GET" && defined ($oql )) {
174202 $oql = URI::Escape::uri_escape_utf8($oql );
@@ -186,8 +214,16 @@ sub api_streaming {
186214 push @args , $k .' =' .$arg -> {$k };
187215 }
188216 }
217+ if (defined ($username ) && defined ($password )) {
218+ push @args , " k=$key " ;
219+ }
189220 $url .= ' ?' .join (' &' , @args );
190221 }
222+ else {
223+ if (defined ($username ) && defined ($password )) {
224+ $url .= ' ?k=' .$key ;
225+ }
226+ }
191227
192228 $self -> log -> verbose(" api_streaming: using url[$url ]" );
193229
@@ -204,6 +240,8 @@ sub api_streaming {
204240
205241 my $cv = AnyEvent-> condvar;
206242
243+ my $authorization = defined ($basic ) ? $basic : " bearer $key " ;
244+
207245 my @args = ( $url );
208246 if ($req eq " POST" ) {
209247 push @args , $oql ;
@@ -212,7 +250,7 @@ sub api_streaming {
212250 # For each loop of processing, let callback work during X before sending a timeout.
213251 timeout => 3600,
214252 headers => {
215- ' Authorization' => " apikey $key " ,
253+ ' Authorization' => $authorization ,
216254 ' Content-Type' => " application/json" ,
217255 },
218256 on_body => sub {
0 commit comments