Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4060847
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/README b/README
index 4c2b85c..c78801b 100644
--- a/README
+++ b/README
@@ -1,51 +1,52 @@
___ ___ ___ ___ ___
/ /\ / /\ /__/\ /__/| / /\
/ /::| / /:/_ | |::\ | |:| / /:/_
/ /:/:| / /:/ /\ | |:|:\ | |:| / /:/ /\
/ /:/|:|__ / /:/ /:/_ __|__|:|\:\ __| |:| / /:/ /:/_
/__/:/ |:| /\ /__/:/ /:/ /\ /__/::::| \:\ /__/\_|:|____ /__/:/ /:/ /\
\__\/ |:|/:/ \ \:\/:/ /:/ \ \:\~~\__\/ \ \:\/:::::/ \ \:\/:/ /:/
| |:/:/ \ \::/ /:/ \ \:\ \ \::/~~~~ \ \::/ /:/
| |::/ \ \:\/:/ \ \:\ \ \:\ \ \:\/:/
| |:/ \ \::/ \ \:\ \ \:\ \ \::/
|__|/ ___ \__\/ ___ \__\/ \__\/ ___ \__\/ ___
/ /\ /__/\ ___ /__/\ / /\
/ /::\ \ \:\ /__/| \ \:\ / /:/_
/ /:/\:\ \__\:\ | |:| \ \:\ / /:/ /\
/ /:/~/:/ ___ / /::\ | |:| _____\__\:\ / /:/ /:/_
/__/:/ /:/___ /__/\ /:/\:\ __|__|:| /__/::::::::\ /__/:/ /:/ /\
\ \:\/:::::/ \ \:\/:/__\/ /__/::::\ \ \:\~~\~~\/ \ \:\/:/ /:/
\ \::/~~~~ \ \::/ ~\~~\:\ \ \:\ ~~~ \ \::/ /:/
\ \:\ \ \:\ \ \:\ \ \:\ \ \:\/:/
\ \:\ \ \:\ \__\/ \ \:\ \ \::/
\__\/ \__\/ \__\/ \__\/
Support tools for a Docker <--> Phabricator bridge.
This account is used by deployment scripts to build
Docker containers for exotic Nasqueron applications.
Available scripts:
------------------
+ * getconfig ........ retrieves a configuration file in rOPS
* getcredentials ... retrieves a credential stored on DevCentral
* getpublickeys .... fetches SSH public key allowed to use this account
* Makefile ......... runs getpublickeys to populate .ssh/authorized_keys
Data:
-----
* servers.json ..... the list of servers allowed to use this account
Authentication:
---------------
For each server needing to use this account, create a SSH key, store in
on DevCentral, give access to it to the NasqDDS group, allow retrieval
through conduit and update the servers.json file.
Reinstallation:
---------------
0. Ensure arc and jq are available on the server
1. Create a new unix account, 'zr'
2. Pull this repository directly in the home directory
3. Install an arc certificate in ~/.arcrc
4. Run 'make'
diff --git a/bin/getconfig b/bin/getconfig
new file mode 100755
index 0000000..d35a990
--- /dev/null
+++ b/bin/getconfig
@@ -0,0 +1,17 @@
+#!/usr/bin/env php
+<?php
+#
+# Gets configuration from Nasqueron operations repository
+#
+# Usage: getconfig <configuration file>
+#
+
+require getenv('HOME') . '/lib/GetConfiguration.php';
+
+if ($argc == 1) {
+ $file = "php://stdin";
+} else {
+ $file = 'https://raw.githubusercontent.com/nasqueron/operations/master/config/' . $argv[1] . '.tmpl';
+}
+
+GetConfiguration::Run($file);
diff --git a/lib/GetConfiguration.php b/lib/GetConfiguration.php
new file mode 100644
index 0000000..298be88
--- /dev/null
+++ b/lib/GetConfiguration.php
@@ -0,0 +1,80 @@
+<?php
+
+/**
+ * Zemke-Rhyne
+ * Support tools for a Docker <--> Phabricator bridge
+ *
+ * (c) Sébastien Santoro aka Dereckson, 2015
+ * Released under BSD license.
+ */
+
+/**
+ * Class GetConfiguration
+ *
+ * Allows to get configuration from a template
+ */
+class GetConfiguration {
+ ///
+ /// Properties
+ ///
+
+ /**
+ * The configuration template content
+ * @var string
+ */
+ public $template;
+
+ ///
+ /// Templating methods
+ ///
+
+ /**
+ * Prints configuration from specified configuration template
+ * replacing expressions by relevant variables and credentials.
+ *
+ * @return string the configuration
+ */
+ public function printConfiguration () {
+ echo static::substituteTemplateVariables($this->template);
+ }
+
+ /**
+ * Substitutes template variables in the specified text
+ *
+ * @param string $text The template text
+ * @return string The substitued text
+ */
+ public static function substituteTemplateVariables ($text) {
+ $text = static::substituteExec($text);
+ return $text;
+ }
+
+ /**
+ * Substitutes %%`command`%% by the output of the command.
+ *
+ * @param string $text The template text
+ * @return string The substitued text
+ */
+ public static function substituteExec ($text) {
+ return preg_replace_callback(
+ '/%%`(.*)`%%/',
+ function ($matches) {
+ return trim(`$matches[1]`);
+ },
+ $text
+ );
+ }
+
+ ///
+ /// Script procedural code
+ ///
+
+ /**
+ * Runs the script
+ */
+ public static function run ($file) {
+ $instance = new self;
+ $instance->template = file_get_contents($file);
+ $instance->printConfiguration();
+ }
+}
diff --git a/tests/GetConfigurationTest.php b/tests/GetConfigurationTest.php
new file mode 100644
index 0000000..0eaeac5
--- /dev/null
+++ b/tests/GetConfigurationTest.php
@@ -0,0 +1,42 @@
+<?php
+
+require '../lib/GetConfiguration.php';
+
+class GetConfigurationTest extends PHPUnit_Framework_TestCase {
+
+ public function testPrintConfiguration () {
+ $this->expectOutputString('foo');
+ $instance = new GetConfiguration();
+ $instance->template = 'foo';
+ $instance->printConfiguration();
+ }
+
+ public function testSubstituteTemplateVariables () {
+ //Empty string
+ $this->assertEquals('', GetConfiguration::substituteTemplateVariables(''));
+
+ //Equivalent to an empty string
+ $this->assertEquals('', GetConfiguration::substituteTemplateVariables(null));
+ $this->assertEquals('', GetConfiguration::substituteTemplateVariables(false));
+
+ //Nothing to substitute
+ $this->assertEquals('foo', GetConfiguration::substituteTemplateVariables('foo'));
+ }
+
+ /**
+ * @requires OS Linux|BSD|CYGWIN|Darwin
+ */
+ public function testSubstituteExec () {
+ $this->assertEquals('', GetConfiguration::substituteExec(''));
+
+ $template = '%%`echo -n ""`%%';
+ $this->assertEquals('', GetConfiguration::substituteExec($template));
+
+ $template = '%%`echo ""`%%';
+ $this->assertEquals('', GetConfiguration::substituteExec($template));
+
+ $template = 'File is %%`ls GetConfigurationTest.php`%%.';
+ $this->assertEquals('File is GetConfigurationTest.php.', GetConfiguration::substituteExec($template));
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jan 28, 08:15 (6 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2380167
Default Alt Text
(6 KB)
Attached To
Mode
rZR Zemke-Rhyne
Attached
Detach File
Event Timeline
Log In to Comment