Skip to content

Commit

Permalink
Set a default username/password
Browse files Browse the repository at this point in the history
Set a default username of `php-thrift-sql` when there is no username given for either Hive or Impala.

Also set a default password for Hive if none given. With SASL Hive just needs something set to not error out which prevents some common problems when using this lib. This closes #22 and closes #23.
  • Loading branch information
xyu committed Jul 24, 2019
1 parent 9cdec7b commit 25e1476
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/ThriftSQL.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

abstract class ThriftSQL {

const USERNAME_DEFAULT = 'php-thrift-sql';

/**
* @return self
* @throws \ThriftSQL\Exception
Expand Down
16 changes: 12 additions & 4 deletions src/ThriftSQL/Hive.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public function connect() {
if ( null !== $this->_sessionHandle ) {
return $this;
}

// Make sure we have auth info set
if ( empty( $this->_username ) ) {
$this->_username = self::USERNAME_DEFAULT;
}
if ( empty( $this->_password ) ) {
$this->_password = 'ANY-PASSWORD';
}

try {
$this->_transport = new \Thrift\Transport\TSocket( $this->_host, $this->_port );
if ( null !== $this->_timeout ) {
Expand All @@ -51,10 +60,9 @@ public function connect() {
)
);
$TOpenSessionReq = new \ThriftGenerated\TOpenSessionReq();
if ( null !== $this->_username && null !== $this->_password ) {
$TOpenSessionReq->username = $this->_username;
$TOpenSessionReq->password = $this->_password;
}
$TOpenSessionReq->username = $this->_username;
$TOpenSessionReq->password = $this->_password;

// Ok, let's try to start a session
$this->_sessionHandle = $this
->_client
Expand Down
5 changes: 5 additions & 0 deletions src/ThriftSQL/Impala.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function connect() {
return $this;
}

// Make sure we have a username set
if ( empty( $this->_username ) ) {
$this->_username = self::USERNAME_DEFAULT;
}

try {
$this->_transport = new \Thrift\Transport\TSocket( $this->_host, $this->_port );

Expand Down

0 comments on commit 25e1476

Please sign in to comment.