protected function execute(InputInterface $input, OutputInterface $output)
 {
     $sapiToken = $input->getArgument('sapiToken');
     $storageApi = new Client(['token' => $sapiToken, 'userAgent' => $this->componentName]);
     $encryptionKey = $input->getArgument('encryptionKey');
     $encryptor = new Encryptor($encryptionKey);
     // Init new SYS bucket
     $configuration = new Configuration($this->componentName, $encryptor);
     $configuration->setStorageApi($storageApi);
     try {
         $configuration->create();
     } catch (\Exception $e) {
         // do nothing, bucket probably exists
     }
     // Get configuration
     $sysBucketId = 'sys.c-ex-google-analytics';
     if (!$storageApi->bucketExists($sysBucketId)) {
         throw new \Exception("No SYS bucket found");
     }
     $accounts = $configuration->getAccounts();
     /** @var Account $account */
     foreach ($accounts as $account) {
         $cfg = $this->renameItems($account->getConfiguration());
         $account->setConfiguration($cfg);
         $account->save();
     }
 }
 protected function setUp()
 {
     self::$client = static::createClient();
     $container = self::$client->getContainer();
     $sapiToken = $container->getParameter('storage_api.test.token');
     $sapiUrl = $container->getParameter('storage_api.test.url');
     self::$client->setServerParameters(array('HTTP_X-StorageApi-Token' => $sapiToken));
     $this->storageApi = new SapiClient(['token' => $sapiToken, 'url' => $sapiUrl, 'userAgent' => 'ex-google-analytics']);
     /** @var Encryptor $encryptor */
     $encryptor = $container->get('syrup.encryptor');
     $this->configuration = new Configuration($this->componentName, $encryptor);
     $this->configuration->setStorageApi($this->storageApi);
     try {
         $this->configuration->create();
     } catch (\Exception $e) {
         // bucket exists
     }
     // Cleanup
     $sysBucketId = $this->configuration->getSysBucketId();
     $tableId = $sysBucketId . '.' . 'test';
     if ($this->storageApi->tableExists($tableId)) {
         $this->storageApi->dropTable($tableId);
     }
 }
 /**
  * @param Request $request
  * @return JsonResponse
  */
 public function postConfigsAction(Request $request)
 {
     $params = $this->getPostJson($request);
     $this->checkParams(array('name'), $params);
     try {
         $this->getConfiguration()->exists();
     } catch (ConfigurationException $e) {
         $this->configuration->create();
     }
     $params['accountName'] = $params['name'];
     unset($params['name']);
     if (null != $this->getConfiguration()->getAccountBy('accountId', $this->configuration->getIdFromName($params['accountName']))) {
         throw new ConfigurationException('Account already exists');
     }
     $account = $this->getConfiguration()->addAccount($params);
     return $this->createJsonResponse(array('id' => $account->getAccountId(), 'name' => $account->getAccountName(), 'description' => $account->getDescription()));
 }