public function createAction()
 {
     $applicationConfig = $this->getServiceLocator()->get('config');
     $config = $applicationConfig['zf-oauth2-doctrine']['default'];
     $console = $this->getServiceLocator()->get('console');
     $objectManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console.');
     }
     if (!$client) {
         $console->write("Client not found", Color::RED);
         return;
     }
     $client = $objectManager->getRepository($config['mapping']['Client']['entity'])->find($this->getRequest()->getParam('id'));
     // Get public key path
     $publicKeyPath = '';
     while (!file_exists($publicKeyPath)) {
         $publicKeyPath = Prompt\Line::prompt("Public key path: ", false, 255);
     }
     $publicKey = file_get_contents($publicKeyPath);
     // Get private key path
     $privateKeyPath = '';
     while (!file_exists($privateKeyPath)) {
         $privateKeyPath = Prompt\Line::prompt("Private key path: ", false, 255);
     }
     $privateKey = file_get_contents($privateKeyPath);
     $options = array(0 => 'HS256', 1 => 'HS384', 2 => 'HS512', 3 => 'RS256', 4 => 'RS384', 5 => 'RS512');
     $encryptionAlgorithm = Prompt\Select::prompt("Encryption Algorithm: ", $options, false, false);
     $publicKeyEntity = new Entity\PublicKey();
     $publicKeyEntity->setClient($client);
     $publicKeyEntity->setPublicKey($publicKey);
     $publicKeyEntity->setPrivateKey($privateKey);
     $publicKeyEntity->setEncryptionAlgorithm($options[$encryptionAlgorithm]);
     $objectManager->persist($publicKeyEntity);
     $objectManager->flush();
     $console->write("Public key created\n", Color::GREEN);
 }
 public function addAction()
 {
     /** @var \Zend\Console\Request $request */
     $request = $this->getRequest();
     /** @var \Continuous\DeployAgent\Application\Application $application */
     $application = $this->getServiceLocator()->get('application/application');
     // provider param
     if ($request->getParam('provider')) {
         /** @var \Continuous\DeployAgent\Provider\Continuousphp $provider */
         $provider = $this->getServiceLocator()->get('provider/' . $request->getParam('provider'));
     } else {
         $providers = ["continuousphp"];
         $providerKey = Select::prompt("Select a provider:", $providers);
         /** @var \Continuous\DeployAgent\Provider\Continuousphp $provider */
         $provider = $this->getServiceLocator()->get('provider/' . $providers[$providerKey]);
     }
     $application->setProvider($provider);
     // token param
     if (!($token = $request->getParam('token'))) {
         $token = Line::prompt("Enter a valid continuousphp access token: ");
     }
     $provider->setToken($token);
     // project param
     if ($request->getParam('repository-provider') && $request->getParam('repository')) {
         $provider->setRepositoryProvider($request->getParam('repository-provider'))->setRepository($request->getParam('repository'));
     } else {
         $this->getConsole()->writeLine('Querying API for your projects...', ColorInterface::LIGHT_CYAN);
         $projects = $provider->getProjects();
         $projectOptions = [];
         foreach ($projects as $entry) {
             $projectOptions[] = $entry['_embedded']['provider']['uniqueIdentifier'] . '/' . $entry['url'];
         }
         if ($projectOptions) {
             $projectKey = Select::prompt("Select a project:", $projectOptions, false, true);
             $project = $projects[$projectKey];
             $provider->setProject($project);
         } else {
             $this->getConsole()->writeLine('There is no project to setup in your continuousphp account', ColorInterface::LIGHT_RED);
             return false;
         }
     }
     // pipeline param
     if (!($reference = $request->getParam('pipeline'))) {
         $this->getConsole()->writeLine('Querying API for your project pipelines...', ColorInterface::LIGHT_CYAN);
         $referenceOptions = $provider->getReferences();
         $referenceKey = Select::prompt("Select a pipeline:", $referenceOptions, false, true);
         $reference = $referenceOptions[$referenceKey];
     }
     $provider->setReference($reference);
     // name param
     if (!($name = $request->getParam('name'))) {
         $name = Line::prompt("Enter an application name: ");
     }
     $application->setName($name);
     // destination param
     if (!($path = $request->getParam('path'))) {
         $path = Line::prompt("Enter the application path: ");
     }
     $application->setPath($path);
     /** @var \Continuous\DeployAgent\Application\ApplicationManager $applicationManager */
     $applicationManager = $this->getServiceLocator()->get('application/application-manager');
     $applicationManager->persist($application);
     return false;
 }
 public function updateAction()
 {
     $applicationConfig = $this->getServiceLocator()->get('config');
     $config = $applicationConfig['zf-oauth2-doctrine']['default'];
     $console = $this->getServiceLocator()->get('console');
     $objectManager = $this->getServiceLocator()->get($config['object_manager']);
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console.');
     }
     $clientEntity = $objectManager->getRepository($config['mapping']['Client']['entity'])->find($this->getRequest()->getParam('id'));
     if (!$clientEntity) {
         $console->write("Client not found", Color::RED);
         return;
     }
     // Get the User
     while (true) {
         if ($clientEntity->getUser()) {
             $console->write("Current Value: " . $clientEntity->getUser()->getId() . "\n", Color::CYAN);
         } else {
             $console->write("Current Value: none\n", Color::CYAN);
         }
         $userId = Prompt\Line::prompt("User ID.  Not required. ? for list: ", true, 255);
         if ($userId == '?') {
             $users = $objectManager->getRepository($config['mapping']['User']['entity'])->findAll();
             foreach ($users as $user) {
                 $console->write($user->getId() . "\t" . $user->getEmail() . "\n", Color::CYAN);
             }
             continue;
         }
         if ($userId) {
             $user = $objectManager->getRepository($config['mapping']['User']['entity'])->find($userId);
             if (!$user) {
                 $console->write("User ID {$userId} not found.\n", Color::RED);
                 continue;
             }
             $clientEntity->setUser($user);
         }
         break;
     }
     // Get the client id
     $clientId = '';
     while (!$clientId) {
         $console->write("Current Value: " . $clientEntity->getClientId() . "\n", Color::CYAN);
         $clientId = Prompt\Line::prompt("Client ID: ", false, 255);
         $client = $objectManager->getRepository($config['mapping']['Client']['entity'])->findOneBy(array('clientId' => $clientId));
         if ($client && $client->getId() !== $clientEntity->getId()) {
             $console->write('Client ID ' . $clientId . ' already exists', Color::RED);
             $clientId = '';
         }
     }
     $clientEntity->setClientId($clientId);
     // Get the client secret
     $secret = '';
     $secretVerify = false;
     while ($secret !== $secretVerify) {
         $secretPrompt = new Prompt\Password("Secret: ");
         $secret = $secretPrompt->show();
         $secretPrompt = new Prompt\Password("Verify Secret: ");
         $secretVerify = $secretPrompt->show();
         if ($secret !== $secretVerify) {
             $console->write("Password verification does not match.  Please try again.\n", Color::YELLOW);
             continue;
         }
         $bcrypt = new Bcrypt();
         $bcrypt->setCost(14);
         $clientEntity->setSecret($bcrypt->create($secret));
     }
     // Get the Redirect URI
     $console->write("Current Value: " . $clientEntity->getRedirectUri() . "\n", Color::CYAN);
     $redirectUri = Prompt\Line::prompt("Redirect URI.  Not required: ", true, 255);
     $clientEntity->setRedirectUri($redirectUri);
     // Get Grant Type(s)
     $console->write("Current Value: " . implode(',', $clientEntity->getGrantType()) . "\n", Color::CYAN);
     $console->write("Default Grant Types\n", Color::YELLOW);
     $console->write("authorization_code\n", Color::CYAN);
     $console->write("access_token\n", Color::CYAN);
     $console->write("refresh_token\n", Color::CYAN);
     $console->write("urn:ietf:params:oauth:grant-type:jwt-bearer\n", Color::CYAN);
     $grantType = Prompt\Line::prompt("Grant Types, comma delimited.  Not required: ", true, 255);
     $clientEntity->setGrantType(explode(',', $grantType));
     // Add scope(s)
     $clientScopes = new ArrayCollection();
     while (true) {
         if (sizeof($clientEntity->getScope())) {
             $console->write("Current Scope(s)\n", Color::YELLOW);
             foreach ($clientEntity->getScope() as $scope) {
                 $console->write($scope->getScope() . "\n", Color::CYAN);
             }
         }
         $scopeArray = $objectManager->getRepository($config['mapping']['Scope']['entity'])->findBy(array(), array('id' => 'ASC'));
         $scopes = new ArrayCollection();
         foreach ($scopeArray as $scope) {
             if (!$clientScopes->contains($scope)) {
                 $scopes->add($scope);
             }
         }
         $options = array(0 => 'Done Selecting Scopes');
         foreach ($scopes as $scope) {
             $options[$scope->getId()] = $scope->getScope();
         }
         if (!$options) {
             $console->write("No Scopes exist.\n", Color::RED);
             break;
         }
         if (sizeof($clientScopes)) {
             $console->write("Selected Scopes\n", Color::YELLOW);
             foreach ($clientScopes as $scope) {
                 $console->write($scope->getScope() . "\n", Color::CYAN);
             }
         }
         $answer = Prompt\Select::prompt('Select Scope(s): ', $options, false, false);
         if (!$answer) {
             foreach ($clientEntity->getScope() as $scope) {
                 $scope->removeClient($clientEntity);
                 $clientEntity->removeScope($scope);
             }
             foreach ($clientScopes as $scope) {
                 $scope->addClient($clientEntity);
                 $clientEntity->addScope($scope);
             }
             break;
         } else {
             foreach ($scopes as $scope) {
                 if ($scope->getId() == $answer) {
                     $clientScopes->add($scope);
                     echo "{$answer} selected\n";
                     break;
                 }
             }
         }
     }
     $objectManager->flush();
     $console->write("Client updated\n", Color::GREEN);
 }
Пример #4
0
 public function createAction()
 {
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('This action can only be used from a console!');
     }
     try {
         $console = Console::getInstance();
     } catch (ConsoleException $e) {
         throw new \RuntimeException('This action can only be used from a console!');
     }
     $this->setValidatorService($this->getServiceLocator()->get('loslicense.validator'));
     $outputFile = $request->getParam('outputFile', null);
     $writer = new \LosLicense\Config\Writer\PhpArray();
     $writer->setUseBracketArraySyntax(true);
     $options = ['Trial', 'Personal', 'Standard'];
     $type = Select::prompt('License type?', $options, false, true);
     $valid_from = Line::prompt("\nValid from (Enter to not set one) YYYY-MM-DD HH:II:SS ? ", true, 20);
     $valid_until = Line::prompt("\nValid until (Enter to not set one) YYYY-MM-DD HH:II:SS ? ", true, 20);
     $customer = Line::prompt("\nCustomer? ", true, 100);
     $options = $this->getServiceLocator()->get('loslicense.options');
     $features = $options->getFeatures();
     $checked = Checkbox::prompt("\nFeatures? (Enter to finish) ", array_keys($features), true, true);
     $sign = false;
     if (Confirm::prompt("\nSign the license? [y/n] ", 'y', 'n')) {
         $sign = true;
     }
     if (Confirm::prompt("\nConfirm the license creation? [y/n] ", 'y', 'n')) {
         $config = new \Zend\Config\Config([], true);
         if ($type == 0) {
             $config->type = License::LICENSE_TRIAL;
             $license = new TrialLicense();
         } elseif ($type == 1) {
             $config->type = License::LICENSE_PERSONAL;
             $license = new PersonalLicense();
         } else {
             $config->type = License::LICENSE_STANDARD;
             $license = new StandardLicense();
         }
         $license->setType($config->type);
         if (!empty($valid_from)) {
             $from = new \DateTime($valid_from);
             $config->valid_from = $from->format('Y-m-d H:i:s');
             $license->setValidFrom($config->valid_from);
         }
         if (!empty($valid_until)) {
             $until = new \DateTime($valid_until);
             $config->valid_until = $until->format('Y-m-d H:i:s');
             $license->setValidUntil($config->valid_until);
         }
         if (!empty($customer)) {
             $config->customer = $customer;
             $license->setCustomer($config->customer);
         }
         if (!empty($checked)) {
             $config->features = [];
             $licenseFeatures = [];
             foreach ($features as $feature => $value) {
                 if (in_array($feature, $checked)) {
                     if ($value === null) {
                         $config->features->{$feature} = null;
                         $licenseFeatures[$feature] = null;
                     } else {
                         $config->features->{$feature} = $value;
                         $licenseFeatures[$feature] = $value;
                     }
                 }
             }
             $license->setFeatures($licenseFeatures);
         }
         if ($sign) {
             $signature = $this->getValidatorService()->signLicense($license);
             $config->signature = $signature;
         }
         if ($outputFile) {
             $writer->toFile($outputFile, $config);
         } else {
             echo $writer->toString($config);
         }
         $console->writeLine("License created", Color::GREEN);
     }
 }
Пример #5
0
 protected function getCacheName()
 {
     $caches = $this->getCaches();
     if (count($caches) === 0) {
         throw new \Exception('No abstract caches registerd to select');
     }
     if (count($caches) === 1) {
         return key($caches);
     }
     $options = array_keys($caches);
     // Increase the keys by 1 since arrays are zero-based keys
     array_unshift($options, null);
     unset($options[0]);
     $answer = ConsoleSelect::prompt('You have multiple caches defined, please select one', $options);
     return $options[$answer];
 }