瀏覽代碼

Merge remote-tracking branch 'origin/FD3-176'

Luciano Andrade 7 年之前
父節點
當前提交
31dbb13948
共有 5 個文件被更改,包括 2066 次插入607 次删除
  1. 1 0
      tools/ONU.json
  2. 3 1
      tools/cmd.php
  3. 5 1
      tools/composer.json
  4. 2032 578
      tools/composer.lock
  5. 25 27
      tools/src/Command/ImportONUCommand.php

+ 1 - 0
tools/ONU.json

@@ -0,0 +1 @@
+[{"clientId":1,"ponSerialNumber":"1","transitionState":"success","tenancyId":3}]

+ 3 - 1
tools/cmd.php

@@ -11,11 +11,13 @@ $app->add(new FD3\Release());
 $app->add(new FD3\GetSource());
 $app->add(new FD3\MergeHostsFile());
 $app->add(new FD3\DockerInventory());
-$app->add(new FD3\ImportClient());
 $app->add(new FD3\ComposerRequireCommand());
 $app->add(new FD3\RunParallel());
 $app->add(new FD3\Command\ImportONUCommand());
 $app->add(new FD3\Command\MakeVersionCommand());
 $app->add(new FD3\Command\MakeSubversionCommand());
 
+$app->add(new FD3\ImportClient());
+$app->add(new FD3\Command\ImportONUCommand());
+
 $app->run();

+ 5 - 1
tools/composer.json

@@ -8,7 +8,11 @@
         "rlanvin/php-ip": "1.*",
         "guzzlehttp/guzzle": "~6.0",
         "maxakawizard/json-collection-parser": "^1.1",
-        "symfony/process": "^3.3"
+        "symfony/process": "^3.3",
+        "symfony/http-foundation": "3.3.*",
+        "symfony/security": "*",
+        "symfony/browser-kit": "*",
+        "hwi/oauth-bundle": "^0.5.3"
     },
     "autoload": {
         "psr-4": {"FD3\\": "src/"}

文件差異過大導致無法顯示
+ 2032 - 578
tools/composer.lock


+ 25 - 27
tools/src/Command/ImportONUCommand.php

@@ -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'); 
     }
-
 }