@@ -77,8 +77,6 @@ public class InfluxDBImpl implements InfluxDB {
7777 private static final LogLevel LOG_LEVEL = LogLevel .parseLogLevel (System .getProperty (LOG_LEVEL_PROPERTY ));
7878
7979 private final InetAddress hostAddress ;
80- private final String username ;
81- private final String password ;
8280 private String version ;
8381 private final Retrofit retrofit ;
8482 private final InfluxDBService influxDBService ;
@@ -116,16 +114,14 @@ public InfluxDBImpl(final String url, final String username, final String passwo
116114 final ResponseFormat responseFormat ) {
117115 this .messagePack = ResponseFormat .MSGPACK .equals (responseFormat );
118116 this .hostAddress = parseHostAddress (url );
119- this .username = username ;
120- this .password = password ;
121117
122118 this .loggingInterceptor = new HttpLoggingInterceptor ();
123119 setLogLevel (LOG_LEVEL );
124120
125121 this .gzipRequestInterceptor = new GzipRequestInterceptor ();
126122 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 ));
129125 Factory converterFactory = null ;
130126 switch (responseFormat ) {
131127 case MSGPACK :
@@ -164,16 +160,15 @@ public InfluxDBImpl(final String url, final String username, final String passwo
164160 super ();
165161 this .messagePack = false ;
166162 this .hostAddress = parseHostAddress (url );
167- this .username = username ;
168- this .password = password ;
169163
170164 this .loggingInterceptor = new HttpLoggingInterceptor ();
171165 setLogLevel (LOG_LEVEL );
172166
173167 this .gzipRequestInterceptor = new GzipRequestInterceptor ();
174168 OkHttpClient .Builder clonedBuilder = client .build ().newBuilder ();
175169 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 ())
177172 .addConverterFactory (MoshiConverterFactory .create ()).build ();
178173 this .influxDBService = influxDBService ;
179174
@@ -420,8 +415,6 @@ public void write(final BatchPoints batchPoints) {
420415 this .batchedCount .add (batchPoints .getPoints ().size ());
421416 RequestBody lineProtocol = RequestBody .create (MEDIA_TYPE_STRING , batchPoints .lineProtocol ());
422417 execute (this .influxDBService .writePoints (
423- this .username ,
424- this .password ,
425418 batchPoints .getDatabase (),
426419 batchPoints .getRetentionPolicy (),
427420 TimeUtil .toTimePrecision (batchPoints .getPrecision ()),
@@ -434,8 +427,6 @@ public void write(final BatchPoints batchPoints) {
434427 public void write (final String database , final String retentionPolicy , final ConsistencyLevel consistency ,
435428 final TimeUnit precision , final String records ) {
436429 execute (this .influxDBService .writePoints (
437- this .username ,
438- this .password ,
439430 database ,
440431 retentionPolicy ,
441432 TimeUtil .toTimePrecision (precision ),
@@ -534,12 +525,10 @@ public void query(final Query query, final int chunkSize, final Consumer<QueryRe
534525 Call <ResponseBody > call = null ;
535526 if (query instanceof BoundParameterQuery ) {
536527 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 ,
539529 boundParameterQuery .getParameterJsonWithUrlEncoded ());
540530 } 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 );
543532 }
544533
545534 call .enqueue (new Callback <ResponseBody >() {
@@ -578,11 +567,11 @@ public QueryResult query(final Query query, final TimeUnit timeUnit) {
578567 Call <QueryResult > call = null ;
579568 if (query instanceof BoundParameterQuery ) {
580569 BoundParameterQuery boundParameterQuery = (BoundParameterQuery ) query ;
581- call = this .influxDBService .query (this . username , this . password , query .getDatabase (),
570+ call = this .influxDBService .query (query .getDatabase (),
582571 TimeUtil .toTimePrecision (timeUnit ), query .getCommandWithUrlEncoded (),
583572 boundParameterQuery .getParameterJsonWithUrlEncoded ());
584573 } else {
585- call = this .influxDBService .query (this . username , this . password , query .getDatabase (),
574+ call = this .influxDBService .query (query .getDatabase (),
586575 TimeUtil .toTimePrecision (timeUnit ), query .getCommandWithUrlEncoded ());
587576 }
588577 return executeQuery (call );
@@ -595,25 +584,23 @@ public QueryResult query(final Query query, final TimeUnit timeUnit) {
595584 public void createDatabase (final String name ) {
596585 Preconditions .checkNonEmptyString (name , "name" );
597586 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 )));
599588 }
600589
601590 /**
602591 * {@inheritDoc}
603592 */
604593 @ Override
605594 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 + "\" " )));
608596 }
609597
610598 /**
611599 * {@inheritDoc}
612600 */
613601 @ Override
614602 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 ));
617604 // {"results":[{"series":[{"name":"databases","columns":["name"],"values":[["mydb"]]}]}]}
618605 // Series [name=databases, columns=[name], values=[[mydb], [unittest_1433605300968]]]
619606 List <List <Object >> databaseNames = result .getResults ().get (0 ).getSeries ().get (0 ).getValues ();
@@ -647,16 +634,13 @@ private Call<QueryResult> callQuery(final Query query) {
647634 Call <QueryResult > call ;
648635 if (query instanceof BoundParameterQuery ) {
649636 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 (),
652638 boundParameterQuery .getParameterJsonWithUrlEncoded ());
653639 } else {
654640 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 ());
657642 } else {
658- call = this .influxDBService .query (this .username ,
659- this .password , query .getDatabase (), query .getCommandWithUrlEncoded ());
643+ call = this .influxDBService .query (query .getDatabase (), query .getCommandWithUrlEncoded ());
660644 }
661645 }
662646 return call ;
@@ -767,7 +751,7 @@ public void createRetentionPolicy(final String rpName, final String database, fi
767751 if (isDefault ) {
768752 queryBuilder .append (" DEFAULT" );
769753 }
770- executeQuery (this .influxDBService .postQuery (this . username , this . password , Query .encode (queryBuilder .toString ())));
754+ executeQuery (this .influxDBService .postQuery (Query .encode (queryBuilder .toString ())));
771755 }
772756
773757 /**
@@ -802,8 +786,7 @@ public void dropRetentionPolicy(final String rpName, final String database) {
802786 .append ("\" ON \" " )
803787 .append (database )
804788 .append ("\" " );
805- executeQuery (this .influxDBService .postQuery (this .username , this .password ,
806- Query .encode (queryBuilder .toString ())));
789+ executeQuery (this .influxDBService .postQuery (Query .encode (queryBuilder .toString ())));
807790 }
808791
809792 private interface ChunkProccesor {
0 commit comments