summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--bin/compile10
-rw-r--r--bin/iac4
-rwxr-xr-xbin/phpiac6
-rw-r--r--composer.json21
-rw-r--r--composer.lock211
-rw-r--r--index.php5
-rw-r--r--src/Command/RunCommand.php6
-rw-r--r--src/Module/Module.php6
-rw-r--r--src/Module/Modules/AptModule.php54
-rw-r--r--src/Module/Modules/UserModule.php70
-rw-r--r--src/Task.php29
12 files changed, 236 insertions, 187 deletions
diff --git a/.gitignore b/.gitignore
index 9c7e18a..57872d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1 @@
/vendor/
-iac.phar
diff --git a/bin/compile b/bin/compile
deleted file mode 100644
index a36967e..0000000
--- a/bin/compile
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env php
-<?php
-
-unlink(getcwd() . '/iac.phar');
-#chdir(dirname(__DIR__));
-#exec('composer install --no-dev');
-
-$phar = new Phar('iac.phar');
-$phar->setStub(Phar::createDefaultStub());
-$phar->buildFromDirectory(dirname(__DIR__), '/(src|vendor|index\.php)/');
diff --git a/bin/iac b/bin/iac
deleted file mode 100644
index b645010..0000000
--- a/bin/iac
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env php
-<?php
-
-require dirname(__DIR__) . '/index.php';
diff --git a/bin/phpiac b/bin/phpiac
new file mode 100755
index 0000000..3e2b520
--- /dev/null
+++ b/bin/phpiac
@@ -0,0 +1,6 @@
+#!/usr/bin/env php
+<?php
+
+require dirname(__DIR__) . '/vendor/autoload.php';
+
+\PHPIAC\IAC::getInstance();
diff --git a/composer.json b/composer.json
index f1b9ba7..f850f87 100644
--- a/composer.json
+++ b/composer.json
@@ -1,5 +1,5 @@
{
- "name": "dweipert/php-iac",
+ "name": "php-iac/php-iac",
"type": "library",
"license": "AGPL-3.0-only",
"authors": [
@@ -10,17 +10,30 @@
],
"require": {
"php": "^8.0",
- "symfony/console": "^5.2",
"petrknap/php-singleton": "^1.0",
- "phpseclib/phpseclib": "^3.0"
+ "php-iac/modules": "*",
+ "php-iac/role": "*",
+ "phpseclib/phpseclib": "^3.0",
+ "symfony/console": "^5.2"
},
"autoload": {
"psr-4": {
"PHPIAC\\": "src"
}
},
+ "repositories": [
+ {
+ "type": "path",
+ "url": "../modules"
+ },
+ {
+ "type": "path",
+ "url": "../role"
+ }
+ ],
+ "minimum-stability": "dev",
"bin": [
- "bin/iac"
+ "bin/phpiac"
],
"scripts": {
"compile": "@php -dphar.readonly=0 bin/compile"
diff --git a/composer.lock b/composer.lock
index 4536647..d26cd7d 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "aa317bad874c3a475803c6d7057df553",
+ "content-hash": "285150783eb4290e52f7b0565a82c352",
"packages": [
{
"name": "paragonie/constant_time_encoding",
@@ -169,17 +169,78 @@
"time": "2016-09-22T07:59:18+00:00"
},
{
+ "name": "php-iac/modules",
+ "version": "dev-main",
+ "dist": {
+ "type": "path",
+ "url": "../modules",
+ "reference": "d4d5ae3bb6566311b2d42cf888e463b62f6cf0dc"
+ },
+ "require": {
+ "php": "^8.0"
+ },
+ "require-dev": {
+ "php-iac/php-iac": "*"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "PHPIAC\\Modules\\": "src"
+ }
+ },
+ "authors": [
+ {
+ "name": "Daniel Weipert",
+ "email": "code@drogueronin.de"
+ }
+ ],
+ "transport-options": {
+ "relative": true
+ }
+ },
+ {
+ "name": "php-iac/role",
+ "version": "dev-main",
+ "dist": {
+ "type": "path",
+ "url": "../role",
+ "reference": "a8ddac7859f7139ce13d244c7dd39fae6ed07db0"
+ },
+ "require": {
+ "php": "^8.0"
+ },
+ "require-dev": {
+ "php-iac/modules": "*",
+ "php-iac/php-iac": "*"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "PHPIAC\\Role\\": "src"
+ }
+ },
+ "authors": [
+ {
+ "name": "Daniel Weipert",
+ "email": "code@drogueronin.de"
+ }
+ ],
+ "transport-options": {
+ "relative": true
+ }
+ },
+ {
"name": "phpseclib/phpseclib",
- "version": "3.0.7",
+ "version": "3.0.x-dev",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
- "reference": "d369510df0ebd5e1a5d0fe3d4d23c55fa87a403d"
+ "reference": "d9615a6fb970d9933866ca8b4036ec3407b020b6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/d369510df0ebd5e1a5d0fe3d4d23c55fa87a403d",
- "reference": "d369510df0ebd5e1a5d0fe3d4d23c55fa87a403d",
+ "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/d9615a6fb970d9933866ca8b4036ec3407b020b6",
+ "reference": "d9615a6fb970d9933866ca8b4036ec3407b020b6",
"shasum": ""
},
"require": {
@@ -261,7 +322,7 @@
],
"support": {
"issues": "https://github.com/phpseclib/phpseclib/issues",
- "source": "https://github.com/phpseclib/phpseclib/tree/3.0.7"
+ "source": "https://github.com/phpseclib/phpseclib/tree/3.0"
},
"funding": [
{
@@ -277,11 +338,11 @@
"type": "tidelift"
}
],
- "time": "2021-04-06T14:00:11+00:00"
+ "time": "2021-04-19T03:20:48+00:00"
},
{
"name": "psr/container",
- "version": "1.1.1",
+ "version": "1.1.x-dev",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
@@ -323,26 +384,27 @@
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
- "source": "https://github.com/php-fig/container/tree/1.1.1"
+ "source": "https://github.com/php-fig/container/tree/1.1.x"
},
"time": "2021-03-05T17:36:06+00:00"
},
{
"name": "symfony/console",
- "version": "v5.2.6",
+ "version": "5.x-dev",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "35f039df40a3b335ebf310f244cb242b3a83ac8d"
+ "reference": "1d077bd682f7c0794d5f5b794b16e2b30febec6b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/35f039df40a3b335ebf310f244cb242b3a83ac8d",
- "reference": "35f039df40a3b335ebf310f244cb242b3a83ac8d",
+ "url": "https://api.github.com/repos/symfony/console/zipball/1d077bd682f7c0794d5f5b794b16e2b30febec6b",
+ "reference": "1d077bd682f7c0794d5f5b794b16e2b30febec6b",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
+ "symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php73": "^1.8",
"symfony/polyfill-php80": "^1.15",
@@ -374,6 +436,7 @@
"symfony/lock": "",
"symfony/process": ""
},
+ "default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
@@ -406,7 +469,75 @@
"terminal"
],
"support": {
- "source": "https://github.com/symfony/console/tree/v5.2.6"
+ "source": "https://github.com/symfony/console/tree/v5.3.0-BETA1"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-04-16T17:36:28+00:00"
+ },
+ {
+ "name": "symfony/deprecation-contracts",
+ "version": "dev-main",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/deprecation-contracts.git",
+ "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627",
+ "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.1"
+ },
+ "default-branch": true,
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-main": "2.4-dev"
+ },
+ "thanks": {
+ "name": "symfony/contracts",
+ "url": "https://github.com/symfony/contracts"
+ }
+ },
+ "autoload": {
+ "files": [
+ "function.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "A generic function and convention to trigger deprecation notices",
+ "homepage": "https://symfony.com",
+ "support": {
+ "source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0"
},
"funding": [
{
@@ -422,11 +553,11 @@
"type": "tidelift"
}
],
- "time": "2021-03-28T09:42:18+00:00"
+ "time": "2021-03-23T23:28:01+00:00"
},
{
"name": "symfony/polyfill-ctype",
- "version": "v1.22.1",
+ "version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
@@ -444,6 +575,7 @@
"suggest": {
"ext-ctype": "For best performance"
},
+ "default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
@@ -505,7 +637,7 @@
},
{
"name": "symfony/polyfill-intl-grapheme",
- "version": "v1.22.1",
+ "version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
@@ -523,6 +655,7 @@
"suggest": {
"ext-intl": "For best performance"
},
+ "default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
@@ -586,7 +719,7 @@
},
{
"name": "symfony/polyfill-intl-normalizer",
- "version": "v1.22.1",
+ "version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
@@ -604,6 +737,7 @@
"suggest": {
"ext-intl": "For best performance"
},
+ "default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
@@ -670,7 +804,7 @@
},
{
"name": "symfony/polyfill-mbstring",
- "version": "v1.22.1",
+ "version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
@@ -688,6 +822,7 @@
"suggest": {
"ext-mbstring": "For best performance"
},
+ "default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
@@ -750,7 +885,7 @@
},
{
"name": "symfony/polyfill-php73",
- "version": "v1.22.1",
+ "version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php73.git",
@@ -765,6 +900,7 @@
"require": {
"php": ">=7.1"
},
+ "default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
@@ -829,7 +965,7 @@
},
{
"name": "symfony/polyfill-php80",
- "version": "v1.22.1",
+ "version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
@@ -844,6 +980,7 @@
"require": {
"php": ">=7.1"
},
+ "default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
@@ -912,29 +1049,30 @@
},
{
"name": "symfony/service-contracts",
- "version": "v2.2.0",
+ "version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/symfony/service-contracts.git",
- "reference": "d15da7ba4957ffb8f1747218be9e1a121fd298a1"
+ "reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/service-contracts/zipball/d15da7ba4957ffb8f1747218be9e1a121fd298a1",
- "reference": "d15da7ba4957ffb8f1747218be9e1a121fd298a1",
+ "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb",
+ "reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
- "psr/container": "^1.0"
+ "psr/container": "^1.1"
},
"suggest": {
"symfony/service-implementation": ""
},
+ "default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.2-dev"
+ "dev-main": "2.4-dev"
},
"thanks": {
"name": "symfony/contracts",
@@ -971,7 +1109,7 @@
"standards"
],
"support": {
- "source": "https://github.com/symfony/service-contracts/tree/master"
+ "source": "https://github.com/symfony/service-contracts/tree/v2.4.0"
},
"funding": [
{
@@ -987,20 +1125,20 @@
"type": "tidelift"
}
],
- "time": "2020-09-07T11:33:47+00:00"
+ "time": "2021-04-01T10:43:52+00:00"
},
{
"name": "symfony/string",
- "version": "v5.2.6",
+ "version": "5.x-dev",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
- "reference": "ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572"
+ "reference": "01454c66c88a6bb4449dcdeb913e463e075f331b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/string/zipball/ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572",
- "reference": "ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572",
+ "url": "https://api.github.com/repos/symfony/string/zipball/01454c66c88a6bb4449dcdeb913e463e075f331b",
+ "reference": "01454c66c88a6bb4449dcdeb913e463e075f331b",
"shasum": ""
},
"require": {
@@ -1017,6 +1155,7 @@
"symfony/translation-contracts": "^1.1|^2",
"symfony/var-exporter": "^4.4|^5.0"
},
+ "default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
@@ -1054,7 +1193,7 @@
"utf8"
],
"support": {
- "source": "https://github.com/symfony/string/tree/v5.2.6"
+ "source": "https://github.com/symfony/string/tree/v5.3.0-BETA1"
},
"funding": [
{
@@ -1070,12 +1209,12 @@
"type": "tidelift"
}
],
- "time": "2021-03-17T17:12:15+00:00"
+ "time": "2021-03-17T17:12:23+00:00"
}
],
"packages-dev": [],
"aliases": [],
- "minimum-stability": "stable",
+ "minimum-stability": "dev",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
diff --git a/index.php b/index.php
deleted file mode 100644
index 92972cf..0000000
--- a/index.php
+++ /dev/null
@@ -1,5 +0,0 @@
-<?php
-
-require __DIR__ . '/vendor/autoload.php';
-
-\PHPIAC\IAC::getInstance();
diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php
index 145b2d5..6d8d2c9 100644
--- a/src/Command/RunCommand.php
+++ b/src/Command/RunCommand.php
@@ -30,14 +30,14 @@ class RunCommand extends Command
}
$commands = [];
- foreach ($config['tasks'] as $taskName => $task) {
+ foreach ($config['tasks'] as $task) {
/**@var Task $task*/
if (! $task->module->checkState()) {
- $output->writeln($taskName . ': Adding commands from ' . get_class($task->module));
+ $output->writeln($task->getName() . ': Adding commands from ' . get_class($task->module));
array_push($commands, ...$task->module->getCommands());
}
else {
- $output->writeln($taskName . ': Skipping commands from ' . get_class($task->module));
+ $output->writeln($task->getName() . ': Skipping commands from ' . get_class($task->module));
}
}
diff --git a/src/Module/Module.php b/src/Module/Module.php
new file mode 100644
index 0000000..51672f9
--- /dev/null
+++ b/src/Module/Module.php
@@ -0,0 +1,6 @@
+<?php
+
+namespace PHPIAC\Module;
+
+abstract class Module implements ModuleInterface
+{}
diff --git a/src/Module/Modules/AptModule.php b/src/Module/Modules/AptModule.php
deleted file mode 100644
index ccf4892..0000000
--- a/src/Module/Modules/AptModule.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-namespace PHPIAC\Module\Modules;
-
-use PHPIAC\Module\ModuleInterface;
-use PHPIAC\Module\State;
-use phpseclib3\Net\SSH2;
-
-class AptModule implements ModuleInterface
-{
- /**
- * AptModule constructor.
- *
- * @param string $package
- * @param string $state
- */
- public function __construct(
- private string $package,
- private string $state = State::PRESENT
- ) {}
-
- /**
- * @inheritDoc
- */
- public function checkState(): bool
- {
- global $ssh;
- /**@var SSH2 $ssh*/
- $ssh->enablePTY();
-
- $ssh->exec("dpkg -l $this->package | grep 'ii'");
- $dpkg = $ssh->read();
-
- $state = match ($this->state) {
- State::PRESENT => str_starts_with($dpkg, 'ii'),
- State::ABSENT => str_contains($dpkg, 'no packages found'),
- };
-
- $ssh->disablePTY();
-
- return $state;
- }
-
- /**
- * @inheritDoc
- */
- public function getCommands(): array
- {
- return match ($this->state) {
- State::PRESENT => ["sudo apt install -y $this->package"],
- State::ABSENT => ["sudo apt remove -y $this->package"],
- };
- }
-}
diff --git a/src/Module/Modules/UserModule.php b/src/Module/Modules/UserModule.php
deleted file mode 100644
index 1749b58..0000000
--- a/src/Module/Modules/UserModule.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-
-namespace PHPIAC\Module\Modules;
-
-use PHPIAC\Module\ModuleInterface;
-use PHPIAC\Module\State;
-use phpseclib3\Net\SSH2;
-
-class UserModule implements ModuleInterface
-{
- /**
- * UserModule constructor.
- *
- * @param string $name
- * @param array $options
- * @param string $state
- */
- public function __construct(
- private string $name,
- private array $options = [],
- private string $state = State::PRESENT
- ) {
- $this->options = array_replace([
- 'append' => false,
- 'create_home' => true,
- 'groups' => [],
- 'shell' => '/bin/bash',
- ], $options);
- }
-
- /**
- * @inheritDoc
- */
- public function checkState(): bool
- {
- global $ssh;
- /**@var SSH2 $ssh*/
- $ssh->enablePTY();
-
- $ssh->exec("cat /etc/passwd | grep $this->name:");
- $hasUser = $ssh->read();
-
- $state = match ($this->state) {
- State::PRESENT => str_starts_with($hasUser, "$this->name:"),
- State::ABSENT => empty($hasUser),
- };
-
- $ssh->disablePTY();
-
- return $state;
- }
-
- /**
- * @inheritDoc
- */
- public function getCommands(): array
- {
- return match ($this->state) {
- State::PRESENT => [
- "sudo adduser $this->name --quiet" .
- " --shell " . $this->options['shell'] .
- ($this->options['create_home'] ? '' : ' --no-create-home'),
- "sudo usermod -" . ($this->options['append'] ? 'a' : '') . "G " . implode(',', $this->options['groups']) . " $this->name"
- ],
- State::ABSENT => [
- "sudo apt remove -y $this->package",
- ],
- };
- }
-}
diff --git a/src/Task.php b/src/Task.php
index a5698ea..8bb68e8 100644
--- a/src/Task.php
+++ b/src/Task.php
@@ -6,6 +6,7 @@ use PHPIAC\Module\ModuleInterface;
class Task
{
+ public string $name = '';
public ModuleInterface $module;
/**
@@ -14,6 +15,34 @@ class Task
public function __construct() {}
/**
+ * @param string $name
+ *
+ * @return $this
+ */
+ public function setName(string $name): self
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getName(): string
+ {
+ if (! empty($this->name)) {
+ return $this->name;
+ }
+
+ $moduleReflection = new \ReflectionClass($this->module);
+ $firstProperty = $moduleReflection->getProperties()[0];
+ $firstProperty->setAccessible(true);
+
+ return $moduleReflection->getShortName() . ' - ' . $firstProperty->getValue($this->module);
+ }
+
+ /**
* @param ModuleInterface $module
*
* @return $this