|
@@ -29,18 +29,19 @@ class ImportONUCommand extends Command
|
|
|
->setHelp('ONU.json shuld be a valid json file, probably looking like the following example:
|
|
|
[
|
|
|
{"clientId":1,"ponSerialNumber":"1","transitionState":"success","tenancyId":3},
|
|
|
- {"clientId":1,"ponSerialNumber":"2","transitionState":"success","tenancyId":3}
|
|
|
+ {"clientId":1,"ponSerialNumber":"2","transitionState":"success","tenancyId":3},
|
|
|
+ {"clientId":1,"ponSerialNumber":"1","transitionState":"success","tenancyId":3}
|
|
|
]
|
|
|
|
|
|
')
|
|
|
->addArgument('base_url', InputArgument::REQUIRED, 'The base url of the FD3 Client.')
|
|
|
->addArgument('data_file.json', InputArgument::OPTIONAL, 'The data source from where to get data.', "ONU.json")
|
|
|
- ->addOption('uri', null, InputOption::VALUE_REQUIRED, 'uri after the base_url for the complete URL', 'api/onus.json')
|
|
|
- ->addOption('user', null, InputOption::VALUE_REQUIRED, 'The FD3 Username.', 'admin')
|
|
|
- ->addOption('pass', null, InputOption::VALUE_REQUIRED, 'The FD3 Password.', 'adminpass')
|
|
|
//->addOption('oauth_token', null, InputOption::VALUE_REQUIRED, 'The FD3 OAuth Client ID.', 'http://base.galvez.flowdat.com/oauth/v2/token')
|
|
|
//->addOption('client_id', null, InputOption::VALUE_REQUIRED, 'The FD3 OAuth Client ID.', '2_2giq1sosvyxwsgwswcw4s44w0o0go0wc0oo4ck4kgo008w80k0')
|
|
|
//->addOption('client_secret', null, InputOption::VALUE_REQUIRED, 'The FD3 OAuth Client Secret.', 'kuu06cynskgkc0swokkkg4gg8k84w0ks00cw00wk4ow480okg')
|
|
|
+ ->addOption('uri', null, InputOption::VALUE_REQUIRED, 'uri after the base_url for the complete URL', '/api/onus.json')
|
|
|
+ ->addOption('user', null, InputOption::VALUE_REQUIRED, 'The FD3 Username.', 'admin')
|
|
|
+ ->addOption('pass', null, InputOption::VALUE_REQUIRED, 'The FD3 Password.', 'adminpass')
|
|
|
;
|
|
|
}
|
|
|
|
|
@@ -53,6 +54,7 @@ class ImportONUCommand extends Command
|
|
|
|
|
|
$file = $input->getArgument("data_file.json");
|
|
|
|
|
|
+
|
|
|
$url = $base_url . $uri;
|
|
|
$client = new GuzzClient();
|
|
|
$parser = new \JsonCollectionParser\Parser();
|
|
@@ -76,26 +78,8 @@ class ImportONUCommand extends Command
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- private function getAccessToken($username, $password, $client_id, $client_secret, $url)
|
|
|
- {
|
|
|
- $body = ['grant_type' => 'password',
|
|
|
- 'username' => $username,
|
|
|
- 'password' => $password
|
|
|
- ];
|
|
|
-
|
|
|
- $client = new GuzzClient();
|
|
|
- $res = $client->request("POST", $url, [
|
|
|
- 'auth' => [$client_id, $client_secret],
|
|
|
- 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
|
|
|
- 'body' => http_build_query($body),
|
|
|
- ]);
|
|
|
- $body = $res->getBody();
|
|
|
-
|
|
|
- return json_decode($body, true);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
- * Retorna un auth token OAuth
|
|
|
+ * Retorna un token OAuth
|
|
|
*
|
|
|
* @param string $username
|
|
|
* @param string $password
|
|
@@ -105,6 +89,7 @@ class ImportONUCommand extends Command
|
|
|
*
|
|
|
* @return array
|
|
|
*/
|
|
|
+
|
|
|
private function getRefreshToken($token, $client_id, $client_secret, $url)
|
|
|
{
|
|
|
$body = ['grant_type' => 'refresh_token',
|
|
@@ -123,8 +108,22 @@ class ImportONUCommand extends Command
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ private function getAccessToken($username, $password, $client_id, $client_secret, $url = 'http://base.fd3.flowdat.com/oauth/v2/token')
|
|
|
+ {
|
|
|
+ $body = ['grant_type' => 'password',
|
|
|
+ 'client_id' => $client_id,
|
|
|
+ 'client_secret' => $client_secret,
|
|
|
+ 'username' => $username,
|
|
|
+ 'password' => $password];
|
|
|
+
|
|
|
+ $client = new GuzzClient();
|
|
|
+ $res = $client->request("POST", $url, [
|
|
|
+ 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
|
|
|
+ 'body' => http_build_query($body),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return json_decode($res->getBody(), true);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Guardo en session al OAuthUser
|
|
@@ -156,7 +155,6 @@ class ImportONUCommand extends Command
|
|
|
|
|
|
return CookieJar::fromArray([
|
|
|
$cookie->getName() => $cookie->getValue(),
|
|
|
- ], 'ftth.galvez.flowdat.com');
|
|
|
+ ], 'flowdat.com');
|
|
|
}
|
|
|
-
|
|
|
}
|