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