Exemplo n.º 1
0
 public function request($method, $segments, $data = array())
 {
     if (static::$debug) {
         Console::output("Client:request -> " . $method . " - " . $segments);
         print_r($data);
     }
     $client = new HTTPClient();
     $response = null;
     try {
         return $client->{$method}(self::$endpoint . $segments, array('headers' => $this->getHeaders(), 'body' => $data, 'exceptions' => $this->raiseExceptions))->json(array('object' => true));
     } catch (Exception $e) {
         $this->guzzleException($e);
     }
 }
Exemplo n.º 2
0
<?php

use Client\Client;
use Client\Project;
use Client\Console;
return array('arg0' => 'generate:schema', 'command' => 'generate:schema', 'description' => 'Generate schema definition config.', 'run' => function ($args) use($commands) {
    $dest = Project::root(Project::DIRECTORY_NAME) . '/schema.yaml';
    @mkdir(dirname($dest), 0777, true);
    $client = new Client();
    $client->setRaiseExceptions(false);
    $cached_schema = $client->get('apps/schema');
    $yaml = new Symfony\Component\Yaml\Dumper();
    if (file_exists($dest)) {
        Console::output("You already have a schema.yaml file.\n" . "Your changes will be lost.\n" . "Overwrite? [y/n]");
        $overwrite = Console::readline() == 'y';
        if (!$overwrite) {
            throw new Exception("Aborted.");
        }
    }
    // format schema dump before save
    $schema_dump = "";
    if (!empty($cached_schema)) {
        $schema_dump = str_replace('  ', ' ', $yaml->dump(json_decode(json_encode($cached_schema), true), 3));
        $schema_dump = preg_replace('/^([a-z0-9_]+):\\n/m', "\n\$0", $schema_dump);
    }
    file_put_contents($dest, $schema_dump . file_get_contents(__DIR__ . '/../../templates/schema.yaml'));
    echo "Schema dumped at '{$dest}'." . PHP_EOL;
    if ($editor = getenv('EDITOR')) {
        $descriptors = array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w'));
        $process = proc_open("{$editor} {$dest}", $descriptors, $pipes);
    }
Exemplo n.º 3
0
    // Generate security file
    $dest = Project::root(Project::DIRECTORY_NAME) . '/';
    @mkdir($dest, 0777, true);
    @mkdir($dest . 'config/', 0777, true);
    @mkdir($dest . 'credentials/', 0777, true);
    $default_config_files = array('security.yaml', 'packages.yaml', 'schedule.yaml', 'schema.yaml', 'config/config.yaml', 'config/config.environment.yaml');
    foreach ($default_config_files as $config_file) {
        $dest_file = $dest . $config_file;
        $template = file_get_contents(__DIR__ . '/../../templates/' . $config_file);
        // replace environment on file
        if (preg_match('/\\.environment\\./', $dest_file)) {
            $dest_file = preg_replace('/\\.(environment)\\./', '.' . Project::getEnvironment() . '.', $dest_file);
            $template = preg_replace('/{{environment}}/', Project::getEnvironment(), $template);
        }
        if (!file_exists($dest_file)) {
            Console::success('create ' . str_replace(Project::root(), "", $dest_file));
            file_put_contents($dest_file, $template);
        }
    }
    if (!$args['json']) {
        Project::createCredentialsDirectory();
        foreach ($app->keys as $key) {
            $credentials = array('app_id' => $key->app_id, 'key' => $key->key, 'type' => $key->type, 'endpoint' => Client::getEndpoint());
            $dest_file = Project::getCredentialsPath() . $key->type . '.json';
            file_put_contents($dest_file, json_encode($credentials));
            Console::success('create ' . str_replace(Project::root(), "", $dest_file));
        }
        Console::output('Application created successfully.');
    }
    return $app->keys;
});
Exemplo n.º 4
0
<?php

use Client\Client;
use Client\Project;
use Client\Console;
use Symfony\Component\Yaml\Yaml;
return array('arg0' => 'config', 'command' => 'config', 'description' => 'List all app configurations', 'run' => function ($args) {
    $client = new Client();
    $configs = $client->get("apps/configs");
    $project = Project::getConfig();
    if (!$args['json']) {
        foreach ($project as $key => $value) {
            Console::output($key . ': ' . $value);
        }
        Console::output(str_repeat('-', 37));
        if ($configs) {
            print Yaml::dump(json_decode(json_encode($configs), true), PHP_INT_MAX);
        } else {
            Console::output("No configurations found for: '{$project['name']}'.");
        }
    }
    return $configs;
});
Exemplo n.º 5
0
<?php

use Client\Client;
use Client\Project;
use Client\Console;
return array('arg0' => 'cache:clear', 'command' => 'cache:clear', 'description' => 'Clear application cache.', 'run' => function ($args) use($commands) {
    $client = new Client();
    $response = $client->delete("apps/cache");
    if ($response->success) {
        Console::output("Cache cleared successfully.");
    } else {
        throw new Exception("Some error ocurred when clearing the cache.");
    }
});
Exemplo n.º 6
0
    // remove auto-generated PHP files
    if (count($js_converted_modules) > 0) {
        foreach ($js_converted_modules as $module) {
            unlink($module);
        }
    }
    if (isset($stats->error)) {
        Console::error($stats->error);
    }
    if (isset($stats->schedule)) {
        Console::output("Schedule updated.");
    }
    if (isset($stats->schema) && $stats->schema > 0) {
        Console::output($stats->schema . " collection(s) migrated.");
    }
    if (isset($stats->modules)) {
        if ($stats->modules->removed > 0) {
            Console::output($stats->modules->removed . " module(s) removed.");
        }
        if ($stats->modules->updated > 0) {
            Console::output($stats->modules->updated . " module(s) updated.");
        }
        if ($stats->modules->uploaded > 0) {
            Console::output($stats->modules->uploaded . " module(s) uploaded.");
        }
    }
    if (isset($stats->packages) && !empty($stats->packages)) {
        Console::output("\nPackages:\n\t" . preg_replace("/\\n/", "\n\t", $stats->packages));
    }
    Console::success("Successfully deployed.");
});
Exemplo n.º 7
0
            //
            // Read or extract certificate file
            // --------------------------------
            //
            if (file_exists($value)) {
                Console::output("Reading certificate file...");
                $ext = pathinfo($value, PATHINFO_EXTENSION);
                if ($ext == 'p12') {
                    $results = array();
                    $worked = openssl_pkcs12_read(file_get_contents($value), $results, null);
                    if ($worked) {
                        $value = $results['cert'] . $results['pkey'];
                    } else {
                        Console::error(openssl_error_string());
                    }
                } else {
                    if ($ext == 'pem') {
                        $value = file_get_contents($value);
                    }
                }
            }
            array_push($configs_to_add, array('name' => $name, 'value' => $value));
        }
    }
    foreach ($configs_to_add as $config) {
        Utils::array_set($configs, $config['name'], $config['value']);
    }
    $dumper = new Symfony\Component\Yaml\Dumper();
    file_put_contents($config_file, str_replace("  ", " ", $dumper->dump($configs, 10)));
    Console::output("Written successfully at: '{$config_file}'");
});