示例#1
0
 /**
  * Handle the command
  *
  * @return mixed
  */
 public function fire()
 {
     parent::fire();
     $_request = PortableServiceRequest::makeImport($this->argument('instance-id'), $this->argument('snapshot'), array_merge(['owner-id' => $this->argument('owner-id')], $this->getOptions()));
     $_job = new ImportJob($_request);
     $_result = $this->dispatch($_job);
     return [$_result, $_job];
 }
示例#2
0
 public function fire()
 {
     parent::fire();
     try {
         $_instance = $this->_findInstance($this->argument('instance-id'));
         $this->writeln('token: ' . $_instance->generateToken());
         return true;
     } catch (ModelNotFoundException $_ex) {
         $this->error('Instance not found.');
         return false;
     }
 }
示例#3
0
 /** @inheritdoc */
 public function fire()
 {
     parent::fire();
     if ($this->option('create') && $this->option('show')) {
         throw new \InvalidArgumentException('The --create and --show commands are mutually exclusive. You may choose one or the other, but not both.');
     }
     $this->job = new ManifestJob($this->argument('cluster-id'), $this->argument('web-server-id'), ServerTypes::WEB);
     $this->job->setInput($this->input)->setOutput($this->output)->setOwner($this->option('owner-id'), $this->option('owner-type'))->setShowManifest($this->option('show'))->setCreateManifest($this->option('create'))->setNoKeys($this->option('no-keys'));
     $_output = $this->argument('output-file');
     $this->job->setOutputFile(!empty($_output) ? $_output : null);
     $this->dispatch($this->job);
     return $this->job->getResult();
 }
示例#4
0
 /**
  * Handle the command
  *
  * @return mixed
  */
 public function fire()
 {
     parent::fire();
     $_instanceId = $this->argument('instance-id');
     //	Check the name here for quicker response...
     if (false === ($_instanceName = Instance::isNameAvailable($_instanceId)) || is_numeric($_instanceName[0])) {
         $this->error('The name of your instance cannot be "' . $_instanceId . '".  It is either currently in-use, or otherwise invalid.');
         exit(1);
     }
     $_ownerType = OwnerTypes::USER;
     $_ownerId = $this->argument('owner-id');
     $_guestLocation = $this->argument('guest-location');
     $_owner = $this->_locateOwner($_ownerId, $_ownerType);
     $this->writeln('Provisioning instance <comment>"' . $_instanceId . '"</comment>.');
     return \Queue::push(new ProvisionJob($_instanceId, ['guest-location' => $_guestLocation, 'owner-id' => $_owner->id, 'owner-type' => $_ownerType ?: OwnerTypes::USER, 'cluster-id' => $this->option('cluster-id')]));
 }
示例#5
0
 /**
  * Handle the command
  *
  * @return mixed
  */
 public function fire()
 {
     parent::fire();
     switch ($_command = trim(strtolower($this->argument('operation')))) {
         case 'create':
         case 'update':
         case 'delete':
             if (empty($_mountId = $this->argument('mount-id'))) {
                 throw new \InvalidArgumentException('No "mount-id" provided.');
             }
             return $this->{'_' . $_command . 'Mount'}($this->argument('mount-id'));
         case 'show':
             return $this->showMounts();
     }
     throw new \InvalidArgumentException('The "' . $_command . '" operation is not valid');
 }
示例#6
0
 /**
  * Fire the command
  *
  * @return bool
  */
 public function fire()
 {
     parent::fire();
     try {
         $_service = Facades\Blueprint::service();
         $_blueprint = $_service->make($this->argument('instance-id'), ['commit' => !$this->option('no-commit'), 'user' => ['email' => $this->argument('admin-email'), 'password' => $this->argument('admin-password'), 'remember_me' => false]]);
         if ($this->option('dump')) {
             $this->writeln(json_encode($_blueprint, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
         }
         return true;
     } catch (ModelNotFoundException $_ex) {
         $this->error('The instance-id "' . $this->argument('instance-id') . '" was not found.');
     } catch (\Exception $_ex) {
         $this->error($_ex->getMessage());
     }
     return false;
 }
示例#7
0
 /**
  * Handle the command
  *
  * @return mixed
  */
 public function fire()
 {
     parent::fire();
     $_clusterId = $this->argument('cluster-id');
     switch ($_command = trim(strtolower($this->argument('operation')))) {
         case 'create':
         case 'update':
         case 'delete':
             return $this->{'_' . $_command . 'Cluster'}($_clusterId);
         case 'add':
         case 'remove':
             return $this->{'_' . $_command . 'Server'}($_clusterId, $this->option('server-id'));
         case 'show':
             return $this->showServers($_clusterId);
     }
     throw new \InvalidArgumentException('The command "' . $_command . '" is invalid');
 }
 /** @inheritdoc */
 public function fire()
 {
     parent::fire();
     $this->setOutputPrefix('[' . $this->name . ']');
     if ($this->option('all')) {
         $this->info('Migrating <comment>all</comment> instances');
         $_results = $this->migrateAllInstances();
     } elseif (null !== ($_instanceId = $this->argument('instance-id'))) {
         $this->info('Migrating instance "<comment>' . $_instanceId . '</comment>"');
         $_results = [$_instanceId => $this->migrateSingleInstance($_instanceId)];
     } else {
         $this->error('You must specify an <instance-id> or use the "--all" option.');
         return 1;
     }
     $_file = storage_path(date('YmdHis') . '-migrate-instance.json');
     if (false === JsonFile::encodeFile($_file, $_results)) {
         $this->error('Error storing results to file.');
     }
     return 0;
 }
示例#9
0
 /** @inheritdoc */
 public function fire()
 {
     parent::fire();
     $this->setOutputPrefix('[' . $this->name . ']');
     $_instanceId = $this->argument('instance-id');
     if ($this->option('destroy')) {
         InstanceCapsule::unmake($_instanceId);
         $this->info('* Instance "<comment>' . $_instanceId . '</comment>" capsule destroyed.');
         return 0;
     }
     $this->info('Encapsulating instance "<comment>' . $_instanceId . '</comment>"');
     try {
         $_capsule = InstanceCapsule::make($_instanceId, false);
         $this->info('* Instance "<comment>' . $_instanceId . '</comment>" encapsulated in <comment>' . $_capsule->getCapsulePath() . '</comment>.');
         return 0;
     } catch (ModelNotFoundException $_ex) {
         $this->error('The instance "' . $_instanceId . '" does not exist.');
         return 1;
     }
 }
示例#10
0
 /** @inheritdoc */
 public function fire()
 {
     parent::fire();
     if (empty($_git = $this->shell('which git'))) {
         $this->error('"git" does not appear to be installed on this system. It is required for this command');
         return 1;
     }
     $_currentBranch = $this->shell($_git . ' rev-parse --abbrev-ref HEAD');
     if (0 != $this->shell($_git . ' remote update >/dev/null 2>&1')) {
         $this->error('Error retrieving update from remote origin.');
         return 1;
     }
     $_current = $this->shell($_git . ' rev-parse HEAD');
     $_remote = $this->shell($_git . ' rev-parse origin/' . $_currentBranch);
     if ($_current == $_remote) {
         $this->info('Your installation is up-to-date (revision: <comment>' . $_current . '</comment>)');
         return 0;
     }
     $this->info('Upgrading to revision <comment>' . $_remote . '</comment>');
     if (0 != $this->shell($_git . ' pull -q --ff-only origin ' . $_currentBranch, true)) {
         $this->error('Error while pulling current revision. Reverting.');
         if (0 != $this->shell($_git . ' revert --hard ' . $_current)) {
             $this->error('Error while reverting to prior version.');
         }
         return 1;
     }
     if (!$this->option('no-composer')) {
         $this->info('Updating composer dependencies');
         $this->shell('composer --quiet --no-interaction --no-ansi update');
     }
     if (!$this->option('no-clear')) {
         $this->info('Clearing caches...');
         $this->shell('php artisan -q config:clear');
         $this->shell('php artisan -q cache:clear');
         $this->shell('php artisan -q route:clear');
         $this->shell('php artisan -q clear-compiled');
         $this->shell('php artisan -q optimize');
         $this->shell('php artisan -q vendor:publish--tag =public --force');
     }
     return 0;
 }
示例#11
0
 /**
  * Handle the command
  *
  * @return mixed
  */
 public function fire()
 {
     parent::fire();
     $_command = new RegisterJob($this->argument('owner-id'), strtolower($this->argument('owner-type')));
     \Queue::push($_command);
     $_result = $_command->getResult();
     if (empty($_result) || null === ($_id = IfSet::getDeep($_result, 'success', 'id'))) {
         $this->error('Results not found for request. Please try again.');
         return 1;
     }
     try {
         /** @type AppKey $_key */
         $_key = AppKey::findOrFail($_id);
     } catch (ModelNotFoundException $_ex) {
         $this->error('The key has been misplaced. Please try again.');
         return 2;
     }
     $this->writeln('<info>Key pair id "' . $_id . '" created. Please keep secure.</info>');
     $this->writeln('    <comment>client_id</comment>: <info>' . $_key->client_id . '</info>');
     $this->writeln('<comment>client_secret</comment>: <info>' . $_key->client_secret . '</info>');
     return 0;
 }
示例#12
0
    /**
     * Handle the command
     *
     * @return mixed
     */
    public function fire()
    {
        parent::fire();
        $this->config = config('commands.setup');
        //  1. Make sure it's a clean install
        if (0 != ServiceUser::count()) {
            if ($this->option('force')) {
                $this->writeln('system has users. <comment>--force</comment> override in place.');
                $this->_backupServiceUsers();
            } else {
                $this->writeln('system has users. use --force to override.', 'error');
                return 1;
            }
        }
        //  1.5 Generate an API secret and stick it in config for AppKey
        \Config::set('dfe.security.console-api-key', $_apiSecret = $this->option('api-secret') ?: $this->_generateApiSecret());
        //  2. Create initial admin user
        try {
            //  Delete all users
            /** @noinspection PhpUndefinedMethodInspection */
            DB::table('service_user_t')->delete();
            //  Add our new user
            $_user = ServiceUser::create(['first_name_text' => 'System', 'last_name_text' => 'Administrator', 'nickname_text' => 'Admin', 'email_addr_text' => $this->argument('admin-email'), 'password_text' => \Hash::make($this->option('admin-password')), 'active_ind' => 1]);
            if (empty($_user)) {
                throw new \Exception('Invalid response from user::create');
            }
            $this->writeln('user <comment>' . $this->argument('admin-email') . '</comment> created.', 'info');
            //  Register
            if (false === License::registerAdmin($_user)) {
                $this->writeln('Error while registering installation');
            }
        } catch (\Exception $_ex) {
            $this->writeln('Error while creating admin user: '******'error');
            return 1;
        }
        //  2. Check permissions and required directories
        $_paths = config('commands.setup.required-directories', []);
        foreach ($_paths as $_path) {
            if (!Disk::ensurePath($_path)) {
                $this->writeln('Unable to create directory: ' . $_path, 'error');
            }
        }
        //  3. Create console and dashboard API key sets
        $_consoleKey = AppKey::createKey(0, OwnerTypes::CONSOLE, ['server_secret' => $_apiSecret]);
        $_dashboardKey = AppKey::createKey(0, OwnerTypes::DASHBOARD, ['server_secret' => $_apiSecret]);
        //  4. Generate .dfe.cluster.json file
        ClusterManifest::make(base_path('database/dfe'), ['cluster-id' => config('dfe.cluster-id'), 'default-domain' => config('provisioning.default-domain'), 'signature-method' => config('dfe.signature-method'), 'storage-root' => config('provisioning.storage-root'), 'console-api-url' => config('dfe.security.console-api-url'), 'console-api-key' => $_apiSecret, 'client-id' => $_dashboardKey->client_id, 'client-secret' => $_dashboardKey->client_secret]);
        //  5.  Make a console environment
        $config = <<<INI
DFE_CONSOLE_API_KEY={$_apiSecret}
DFE_CONSOLE_API_CLIENT_ID={$_consoleKey->client_id}
DFE_CONSOLE_API_CLIENT_SECRET={$_consoleKey->client_secret}
INI;
        $this->_writeFile('console.env', $config);
        //  6.  Make a dashboard config file...
        $config = <<<INI
DFE_CONSOLE_API_KEY={$_apiSecret}
DFE_CONSOLE_API_CLIENT_ID={$_dashboardKey->client_id}
DFE_CONSOLE_API_CLIENT_SECRET={$_dashboardKey->client_secret}
INI;
        return $this->_writeFile('dashboard.env', $config);
    }
示例#13
0
 /**
  * Handle the command
  *
  * @return mixed
  */
 public function fire()
 {
     parent::fire();
     return \Queue::push(new DeprovisionJob($this->argument('instance-id'), ['cluster-id' => $this->option('cluster-id')]));
 }