@@ -79,8 +79,6 @@ public class InfluxDBImpl implements InfluxDB {
79
79
private static final LogLevel LOG_LEVEL = LogLevel .parseLogLevel (System .getProperty (LOG_LEVEL_PROPERTY ));
80
80
81
81
private final InetAddress hostAddress ;
82
- private final String username ;
83
- private final String password ;
84
82
private String version ;
85
83
private final Retrofit retrofit ;
86
84
private final InfluxDBService influxDBService ;
@@ -119,16 +117,14 @@ public InfluxDBImpl(final String url, final String username, final String passwo
119
117
final ResponseFormat responseFormat ) {
120
118
this .messagePack = ResponseFormat .MSGPACK .equals (responseFormat );
121
119
this .hostAddress = parseHostAddress (url );
122
- this .username = username ;
123
- this .password = password ;
124
120
125
121
this .loggingInterceptor = new HttpLoggingInterceptor ();
126
122
setLogLevel (LOG_LEVEL );
127
123
128
124
this .gzipRequestInterceptor = new GzipRequestInterceptor ();
129
125
OkHttpClient .Builder clonedBuilder = client .build ().newBuilder ();
130
- clonedBuilder .addInterceptor (loggingInterceptor ).addInterceptor (gzipRequestInterceptor );
131
-
126
+ clonedBuilder .addInterceptor (loggingInterceptor ).addInterceptor (gzipRequestInterceptor ).
127
+ addInterceptor ( new BasicAuthInterceptor ( username , password ));
132
128
Factory converterFactory = null ;
133
129
switch (responseFormat ) {
134
130
case MSGPACK :
@@ -167,16 +163,15 @@ public InfluxDBImpl(final String url, final String username, final String passwo
167
163
super ();
168
164
this .messagePack = false ;
169
165
this .hostAddress = parseHostAddress (url );
170
- this .username = username ;
171
- this .password = password ;
172
166
173
167
this .loggingInterceptor = new HttpLoggingInterceptor ();
174
168
setLogLevel (LOG_LEVEL );
175
169
176
170
this .gzipRequestInterceptor = new GzipRequestInterceptor ();
177
171
OkHttpClient .Builder clonedBuilder = client .build ().newBuilder ();
178
172
this .retrofit = new Retrofit .Builder ().baseUrl (url )
179
- .client (clonedBuilder .addInterceptor (loggingInterceptor ).addInterceptor (gzipRequestInterceptor ).build ())
173
+ .client (clonedBuilder .addInterceptor (loggingInterceptor ).addInterceptor (gzipRequestInterceptor ).
174
+ addInterceptor (new BasicAuthInterceptor (username , password )).build ())
180
175
.addConverterFactory (MoshiConverterFactory .create ()).build ();
181
176
this .influxDBService = influxDBService ;
182
177
@@ -423,8 +418,6 @@ public void write(final BatchPoints batchPoints) {
423
418
this .batchedCount .add (batchPoints .getPoints ().size ());
424
419
RequestBody lineProtocol = RequestBody .create (MEDIA_TYPE_STRING , batchPoints .lineProtocol ());
425
420
execute (this .influxDBService .writePoints (
426
- this .username ,
427
- this .password ,
428
421
batchPoints .getDatabase (),
429
422
batchPoints .getRetentionPolicy (),
430
423
TimeUtil .toTimePrecision (batchPoints .getPrecision ()),
@@ -437,8 +430,6 @@ public void write(final BatchPoints batchPoints) {
437
430
public void write (final String database , final String retentionPolicy , final ConsistencyLevel consistency ,
438
431
final TimeUnit precision , final String records ) {
439
432
execute (this .influxDBService .writePoints (
440
- this .username ,
441
- this .password ,
442
433
database ,
443
434
retentionPolicy ,
444
435
TimeUtil .toTimePrecision (precision ),
@@ -537,12 +528,10 @@ public void query(final Query query, final int chunkSize, final Consumer<QueryRe
537
528
Call <ResponseBody > call = null ;
538
529
if (query instanceof BoundParameterQuery ) {
539
530
BoundParameterQuery boundParameterQuery = (BoundParameterQuery ) query ;
540
- call = this .influxDBService .query (this .username , this .password ,
541
- query .getDatabase (), query .getCommandWithUrlEncoded (), chunkSize ,
531
+ call = this .influxDBService .query (query .getDatabase (), query .getCommandWithUrlEncoded (), chunkSize ,
542
532
boundParameterQuery .getParameterJsonWithUrlEncoded ());
543
533
} else {
544
- call = this .influxDBService .query (this .username , this .password ,
545
- query .getDatabase (), query .getCommandWithUrlEncoded (), chunkSize );
534
+ call = this .influxDBService .query (query .getDatabase (), query .getCommandWithUrlEncoded (), chunkSize );
546
535
}
547
536
548
537
call .enqueue (new Callback <ResponseBody >() {
@@ -581,11 +570,11 @@ public QueryResult query(final Query query, final TimeUnit timeUnit) {
581
570
Call <QueryResult > call = null ;
582
571
if (query instanceof BoundParameterQuery ) {
583
572
BoundParameterQuery boundParameterQuery = (BoundParameterQuery ) query ;
584
- call = this .influxDBService .query (this . username , this . password , query .getDatabase (),
573
+ call = this .influxDBService .query (query .getDatabase (),
585
574
TimeUtil .toTimePrecision (timeUnit ), query .getCommandWithUrlEncoded (),
586
575
boundParameterQuery .getParameterJsonWithUrlEncoded ());
587
576
} else {
588
- call = this .influxDBService .query (this . username , this . password , query .getDatabase (),
577
+ call = this .influxDBService .query (query .getDatabase (),
589
578
TimeUtil .toTimePrecision (timeUnit ), query .getCommandWithUrlEncoded ());
590
579
}
591
580
return executeQuery (call );
@@ -598,25 +587,23 @@ public QueryResult query(final Query query, final TimeUnit timeUnit) {
598
587
public void createDatabase (final String name ) {
599
588
Preconditions .checkNonEmptyString (name , "name" );
600
589
String createDatabaseQueryString = String .format ("CREATE DATABASE \" %s\" " , name );
601
- executeQuery (this .influxDBService .postQuery (this . username , this . password , Query .encode (createDatabaseQueryString )));
590
+ executeQuery (this .influxDBService .postQuery (Query .encode (createDatabaseQueryString )));
602
591
}
603
592
604
593
/**
605
594
* {@inheritDoc}
606
595
*/
607
596
@ Override
608
597
public void deleteDatabase (final String name ) {
609
- executeQuery (this .influxDBService .postQuery (this .username , this .password ,
610
- Query .encode ("DROP DATABASE \" " + name + "\" " )));
598
+ executeQuery (this .influxDBService .postQuery (Query .encode ("DROP DATABASE \" " + name + "\" " )));
611
599
}
612
600
613
601
/**
614
602
* {@inheritDoc}
615
603
*/
616
604
@ Override
617
605
public List <String > describeDatabases () {
618
- QueryResult result = executeQuery (this .influxDBService .query (this .username ,
619
- this .password , SHOW_DATABASE_COMMAND_ENCODED ));
606
+ QueryResult result = executeQuery (this .influxDBService .query (SHOW_DATABASE_COMMAND_ENCODED ));
620
607
// {"results":[{"series":[{"name":"databases","columns":["name"],"values":[["mydb"]]}]}]}
621
608
// Series [name=databases, columns=[name], values=[[mydb], [unittest_1433605300968]]]
622
609
List <List <Object >> databaseNames = result .getResults ().get (0 ).getSeries ().get (0 ).getValues ();
@@ -650,16 +637,13 @@ private Call<QueryResult> callQuery(final Query query) {
650
637
Call <QueryResult > call ;
651
638
if (query instanceof BoundParameterQuery ) {
652
639
BoundParameterQuery boundParameterQuery = (BoundParameterQuery ) query ;
653
- call = this .influxDBService .postQuery (this .username ,
654
- this .password , query .getDatabase (), query .getCommandWithUrlEncoded (),
640
+ call = this .influxDBService .postQuery (query .getDatabase (), query .getCommandWithUrlEncoded (),
655
641
boundParameterQuery .getParameterJsonWithUrlEncoded ());
656
642
} else {
657
643
if (query .requiresPost ()) {
658
- call = this .influxDBService .postQuery (this .username ,
659
- this .password , query .getDatabase (), query .getCommandWithUrlEncoded ());
644
+ call = this .influxDBService .postQuery (query .getDatabase (), query .getCommandWithUrlEncoded ());
660
645
} else {
661
- call = this .influxDBService .query (this .username ,
662
- this .password , query .getDatabase (), query .getCommandWithUrlEncoded ());
646
+ call = this .influxDBService .query (query .getDatabase (), query .getCommandWithUrlEncoded ());
663
647
}
664
648
}
665
649
return call ;
@@ -783,7 +767,7 @@ public void createRetentionPolicy(final String rpName, final String database, fi
783
767
if (isDefault ) {
784
768
queryBuilder .append (" DEFAULT" );
785
769
}
786
- executeQuery (this .influxDBService .postQuery (this . username , this . password , Query .encode (queryBuilder .toString ())));
770
+ executeQuery (this .influxDBService .postQuery (Query .encode (queryBuilder .toString ())));
787
771
}
788
772
789
773
/**
@@ -818,8 +802,7 @@ public void dropRetentionPolicy(final String rpName, final String database) {
818
802
.append ("\" ON \" " )
819
803
.append (database )
820
804
.append ("\" " );
821
- executeQuery (this .influxDBService .postQuery (this .username , this .password ,
822
- Query .encode (queryBuilder .toString ())));
805
+ executeQuery (this .influxDBService .postQuery (Query .encode (queryBuilder .toString ())));
823
806
}
824
807
825
808
private interface ChunkProccesor {
0 commit comments