masoudniki /
vSphere
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace FNDEV\vShpare\Auth; |
||
| 5 | |||
| 6 | use FNDEV\vShpare\Exceptions\CredentialException; |
||
| 7 | use FNDEV\vShpare\VmwareApiClient; |
||
| 8 | use GuzzleHttp\Client; |
||
| 9 | |||
| 10 | class SessionHandler |
||
| 11 | { |
||
| 12 | public static ?Client $client=null; |
||
| 13 | public static function getSession(VmwareApiClient $client){ |
||
| 14 | self::validateCredentials($client); |
||
| 15 | return self::isSessionExist($client->credential) ? $client->credential['Vmware-Api-Session-Id'] : self::authRequest($client); |
||
| 16 | } |
||
| 17 | public static function authRequest(VmwareApiClient $client){ |
||
| 18 | $HttpClient=isset(static::$client) ? self::$client : new Client( |
||
| 19 | [ |
||
| 20 | "verify"=>$client->ssl, |
||
| 21 | "headers"=>[ |
||
| 22 | "Content-Type"=>"application/x-www-form-urlencoded", |
||
| 23 | "Accept" => "application/json", |
||
| 24 | "Authorization"=>"Basic ".self::convertCredentials($client->credential) |
||
| 25 | ] |
||
| 26 | ] |
||
| 27 | ); |
||
| 28 | $response=$HttpClient->request('GET',$client->getAuthUrl(),[ |
||
|
0 ignored issues
–
show
|
|||
| 29 | "query"=>[ |
||
| 30 | "~method"=>"post" |
||
| 31 | ] |
||
| 32 | ]); |
||
| 33 | return json_decode($response->getBody())->value; |
||
| 34 | } |
||
| 35 | public static function isSessionExist($credential){ |
||
| 36 | return array_key_exists("Vmware-Api-Session-Id",$credential); |
||
| 37 | } |
||
| 38 | public static function validateCredentials(VmwareApiClient $client) |
||
| 39 | { |
||
| 40 | if((array_key_exists("username",$client->credential) && array_key_exists("password",$client->credential)) or array_key_exists("Vmware-Api-Session-Id",$client->credential)) |
||
| 41 | return true; |
||
| 42 | throw new CredentialException("required parameter you should send session-id or username-password for auth api "); |
||
| 43 | } |
||
| 44 | public static function convertCredentials($credentials){ |
||
| 45 | return base64_encode($credentials['username'].":".$credentials['password']); |
||
| 46 | } |
||
| 47 | |||
| 48 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.