Ejemplo n.º 1
0
 private function assertTrustedResource(Resource $resource, RunConfiguration $runConfiguration, UserConfiguration $userConfiguration)
 {
     if ($resource instanceof LocalResource || $runConfiguration->isTrusted() || in_array($resource->getMetadata()->getOwner(), $userConfiguration->getTrustedUsers()) || in_array($resource->getSignature(), $userConfiguration->getTrustedSignatures())) {
         return;
     }
     throw new TrustException($resource);
 }
Ejemplo n.º 2
0
    private function getRemoteBootstrap(Resource $resource)
    {
        $template = <<<TEMPLATE
{{ head }}
?>{{ code }}

TEMPLATE;
        return strtr($template, array('{{ head }}' => $this->getHead(), '{{ code }}' => $resource->getContent()));
    }
Ejemplo n.º 3
0
 public function parseResource(Resource $resource)
 {
     preg_match(self::MELODY_PATTERN, $resource->getContent(), $matches);
     if (!$matches) {
         throw new ParseException('Impossible to parse the content of the document.');
     }
     try {
         return Yaml::parse($matches['config']);
     } catch (YamlException $e) {
         throw new ParseException('The front matter is not a valid Yaml.', 0, $e);
     }
 }
Ejemplo n.º 4
0
    private function confirmTrust(Resource $resource, InputInterface $input, OutputInterface $output)
    {
        $dialog = $this->getHelperSet()->get('dialog');
        $message = <<<EOT
<comment>You are running an untrusted resource</comment>
  <info>URL:            </info> %s
  <info>Revision:       </info> #%d
  <info>Owner:          </info> %s
  <info>Created at:     </info> %s
  <info>Last update:    </info> %s

EOT;
        $output->writeln(sprintf($message, $resource->getMetadata()->getUri(), $resource->getMetadata()->getRevision(), $resource->getMetadata()->getOwner(), $resource->getMetadata()->getCreatedAt()->format(\DateTime::RSS), $resource->getMetadata()->getUpdatedAt()->format(\DateTime::RSS)));
        $actions = array('abort', 'continue', 'show-code');
        $defaultAction = 'abort';
        $actionLabels = array_map(function ($action) use($defaultAction) {
            if ($action === $defaultAction) {
                return sprintf('<%1$s>%2$s</%1$s>', 'default', $action);
            }
            return $action;
        }, $actions);
        $defaultStyle = clone $output->getFormatter()->getStyle('question');
        $defaultStyle->setOptions(array('reverse'));
        $output->getFormatter()->setStyle('default', $defaultStyle);
        $question = new Question(sprintf('<question>What do you want to do (%s)?</question> ', implode(', ', $actionLabels)), $defaultAction);
        $question->setAutocompleterValues($actions);
        $action = $this->getHelper('question')->ask($input, $output, $question);
        if ($action === 'show-code') {
            $output->writeln(PHP_EOL . $resource->getContent() . PHP_EOL);
            return $dialog->askConfirmation($output, '<question>Do you want to continue [y/N]?</question> ', false);
        }
        return $action === 'continue';
    }