From c607f27443c5f0ed5315e7b7123f63396172a775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Nov=C3=A1k?= Date: Thu, 20 Jun 2024 14:22:36 +0200 Subject: [PATCH 1/8] PST-1643 fix code style --- src/Config/BaseConfig.php | 2 +- src/Manifest/ManifestManager.php | 4 ++-- .../ManifestManager/Options/OutTableManifestOptions.php | 0 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 src/Manifest/ManifestManager/Options/OutTableManifestOptions.php diff --git a/src/Config/BaseConfig.php b/src/Config/BaseConfig.php index c30ca55f..152afb00 100644 --- a/src/Config/BaseConfig.php +++ b/src/Config/BaseConfig.php @@ -31,7 +31,7 @@ class BaseConfig implements ConfigInterface */ public function __construct( array $config, - ?ConfigurationInterface $configDefinition = null + ?ConfigurationInterface $configDefinition = null, ) { $this->setConfigDefinition($configDefinition); $this->setConfig($config); diff --git a/src/Manifest/ManifestManager.php b/src/Manifest/ManifestManager.php index 5148646b..f686a4f6 100644 --- a/src/Manifest/ManifestManager.php +++ b/src/Manifest/ManifestManager.php @@ -20,7 +20,7 @@ class ManifestManager private string $dataDir; public function __construct( - string $dataDir + string $dataDir, ) { $this->dataDir = $dataDir; } @@ -36,7 +36,7 @@ final public function getManifestFilename(string $fileName): string public function writeFileManifest( string $fileName, - OutFileManifestOptions $options + OutFileManifestOptions $options, ): void { $tableManifestName = $this->getManifestFilename($fileName); $this->internalWriteFileManifest($tableManifestName, $options->toArray()); diff --git a/src/Manifest/ManifestManager/Options/OutTableManifestOptions.php b/src/Manifest/ManifestManager/Options/OutTableManifestOptions.php new file mode 100644 index 00000000..e69de29b From 416aab07a86311885c950b382a2bd214d3d2c3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Nov=C3=A1k?= Date: Thu, 20 Jun 2024 16:01:11 +0200 Subject: [PATCH 2/8] PST-1643 unification of parameter naming in examples --- README.md | 14 +++++++------- example/Component.php | 16 +++++++++++++--- example/MyConfig.php | 4 ++-- example/MyConfigDefinition.php | 4 ++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1127416e..976ec295 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ class Component extends \Keboola\Component\BaseComponent // get parameters $parameters = $this->getConfig()->getParameters(); - // get value of customKey.customSubkey parameter and fail if missing - $customParameter = $this->getConfig()->getValue(['parameters', 'customKey', 'customSubkey']); + // get value of customKey.customSubKey parameter and fail if missing + $customParameter = $this->getConfig()->getValue(['parameters', 'customKey', 'customSubKey']); // get value with default value if not present $customParameterOrNull = $this->getConfig()->getValue(['parameters', 'customKey'], 'someDefaultValue'); @@ -109,17 +109,17 @@ To implement a sync action ### Custom getters in config -You might want to add getter methods for custom parameters in the config. That way you don't need to remember exact keys (`parameters.errorCount.maximumAllowed`), but instead use a method to retrieve the value (`$config->getMaximumAllowedErrorCount()`). +You might want to add getter methods for custom parameters in the config. That way you don't need to remember exact keys (`parameters.customKey.customSubKey`), but instead use a method to retrieve the value (`$config->getCustomSubKey()`). Simply create your own `Config` class, that extends `BaseConfig` and override `\Keboola\Component\BaseComponent::getConfigClass()` method to return your new class name. ```php class MyConfig extends \Keboola\Component\Config\BaseConfig { - public function getMaximumAllowedErrorCount() + public function getCustomSubKey() { $defaultValue = 0; - return $this->getValue(['parameters', 'errorCount', 'maximumAllowed'], $defaultValue); + return $this->getValue(['parameters', 'customKey', 'customSubKey'], $defaultValue); } } ``` @@ -149,10 +149,10 @@ class MyConfigDefinition extends \Keboola\Component\Config\BaseConfigDefinition $parametersNode ->isRequired() ->children() - ->arrayNode('errorCount') + ->arrayNode('customKey') ->isRequired() ->children() - ->integerNode('maximumAllowed') + ->integerNode('customSubKey') ->isRequired(); return $parametersNode; } diff --git a/example/Component.php b/example/Component.php index 8eb9642f..f164ebe7 100644 --- a/example/Component.php +++ b/example/Component.php @@ -15,11 +15,11 @@ protected function run(): void // get parameters $parameters = $this->getConfig()->getParameters(); - // get value of customKey.customSubkey parameter and fail if missing - $customParameter = $this->getConfig()->getValue(['parameters', 'customKey', 'customSubkey']); + // get value of customKey.customSubKey parameter and fail if missing + $customParameter = $this->getConfig()->getValue(['parameters', 'customKey', 'customSubKey']); // get value with default value if not present - $customParameterOrNull = $this->getConfig()->getValue(['parameters', 'customKey'], 'someDefaultValue'); + $customParameterOrNull = $this->getConfig()->getValue(['parameters', 'anotherCustomKey'], 'someDefaultValue'); // get manifest for input file $fileManifest = $this->getManifestManager()->getFileManifest('input-file.csv'); @@ -53,4 +53,14 @@ protected function getSyncActions(): array { return ['custom' => 'customSyncAction']; } + + protected function getConfigDefinitionClass(): string + { + return MyConfigDefinition::class; + } + + protected function getConfigClass(): string + { + return MyConfig::class; + } } diff --git a/example/MyConfig.php b/example/MyConfig.php index 3876066a..efed322f 100644 --- a/example/MyConfig.php +++ b/example/MyConfig.php @@ -8,9 +8,9 @@ class MyConfig extends BaseConfig { - public function getMaximumAllowedErrorCount(): int + public function getCustomSubKey(): int { $defaultValue = 0; - return $this->getIntValue(['parameters', 'errorCount', 'maximumAllowed'], $defaultValue); + return $this->getIntValue(['parameters', 'customKey', 'customSubKey'], $defaultValue); } } diff --git a/example/MyConfigDefinition.php b/example/MyConfigDefinition.php index cb966056..68037e5e 100644 --- a/example/MyConfigDefinition.php +++ b/example/MyConfigDefinition.php @@ -15,10 +15,10 @@ protected function getParametersDefinition(): ArrayNodeDefinition $parametersNode ->isRequired() ->children() - ->arrayNode('errorCount') + ->arrayNode('customKey') ->isRequired() ->children() - ->integerNode('maximumAllowed') + ->integerNode('customSubKey') ->isRequired(); return $parametersNode; } From 9cd52ceaa99d430cd5d612ba929680c6b55957fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Nov=C3=A1k?= Date: Mon, 24 Jun 2024 13:09:37 +0200 Subject: [PATCH 3/8] PST-1643 add deploy.sh --- deploy.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 deploy.sh diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 00000000..1ec535e0 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +# Obtain the component repository and log in +docker pull quay.io/keboola/developer-portal-cli-v2:latest +export REPOSITORY=`docker run --rm \ + -e KBC_DEVELOPERPORTAL_USERNAME \ + -e KBC_DEVELOPERPORTAL_PASSWORD \ + quay.io/keboola/developer-portal-cli-v2:latest \ + ecr:get-repository ${KBC_DEVELOPERPORTAL_VENDOR} ${KBC_DEVELOPERPORTAL_APP}` +eval $(docker run --rm \ + -e KBC_DEVELOPERPORTAL_USERNAME \ + -e KBC_DEVELOPERPORTAL_PASSWORD \ + quay.io/keboola/developer-portal-cli-v2:latest \ + ecr:get-login ${KBC_DEVELOPERPORTAL_VENDOR} ${KBC_DEVELOPERPORTAL_APP}) + +# Push to the repository +docker tag ${APP_IMAGE}:latest ${REPOSITORY}:${TRAVIS_TAG} +docker tag ${APP_IMAGE}:latest ${REPOSITORY}:latest +docker push ${REPOSITORY}:${TRAVIS_TAG} +docker push ${REPOSITORY}:latest + +# Update the tag in Keboola Developer Portal -> Deploy to KBC +if echo ${TRAVIS_TAG} | grep -c '^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$' +then + docker run --rm \ + -e KBC_DEVELOPERPORTAL_USERNAME \ + -e KBC_DEVELOPERPORTAL_PASSWORD \ + quay.io/keboola/developer-portal-cli-v2:latest \ + update-app-repository ${KBC_DEVELOPERPORTAL_VENDOR} ${KBC_DEVELOPERPORTAL_APP} ${TRAVIS_TAG} ecr ${REPOSITORY} +else + echo "Skipping deployment to KBC, tag ${TRAVIS_TAG} is not allowed." +fi \ No newline at end of file From bcfcdff0d293c32f2780452363afdced2838f243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Nov=C3=A1k?= Date: Tue, 25 Jun 2024 13:00:01 +0200 Subject: [PATCH 4/8] PST-1643 fix trailing comma in declaration --- src/Config/BaseConfig.php | 2 +- src/Manifest/ManifestManager.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Config/BaseConfig.php b/src/Config/BaseConfig.php index 152afb00..c30ca55f 100644 --- a/src/Config/BaseConfig.php +++ b/src/Config/BaseConfig.php @@ -31,7 +31,7 @@ class BaseConfig implements ConfigInterface */ public function __construct( array $config, - ?ConfigurationInterface $configDefinition = null, + ?ConfigurationInterface $configDefinition = null ) { $this->setConfigDefinition($configDefinition); $this->setConfig($config); diff --git a/src/Manifest/ManifestManager.php b/src/Manifest/ManifestManager.php index f686a4f6..5148646b 100644 --- a/src/Manifest/ManifestManager.php +++ b/src/Manifest/ManifestManager.php @@ -20,7 +20,7 @@ class ManifestManager private string $dataDir; public function __construct( - string $dataDir, + string $dataDir ) { $this->dataDir = $dataDir; } @@ -36,7 +36,7 @@ final public function getManifestFilename(string $fileName): string public function writeFileManifest( string $fileName, - OutFileManifestOptions $options, + OutFileManifestOptions $options ): void { $tableManifestName = $this->getManifestFilename($fileName); $this->internalWriteFileManifest($tableManifestName, $options->toArray()); From 2de03b9f823e69a936ce7d5239936a746ba060b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Nov=C3=A1k?= Date: Tue, 25 Jun 2024 13:20:47 +0200 Subject: [PATCH 5/8] PST-1643 change dockerfile to run example --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9d557f17..cd78aa76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,4 +26,4 @@ RUN composer install $COMPOSER_FLAGS --no-scripts --no-autoloader COPY . . RUN composer install $COMPOSER_FLAGS -CMD composer ci +CMD php ./example/run.php From b812f4cbb210e5fa672287ba426d36b85d9b5cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Nov=C3=A1k?= Date: Tue, 25 Jun 2024 13:29:44 +0200 Subject: [PATCH 6/8] PST-1643 fix code style after rebase --- phpcs.xml | 1 - src/Config/BaseConfig.php | 2 +- src/Manifest/ManifestManager.php | 4 ++-- .../Options/OutTable/ManifestOptionsSchema.php | 2 +- .../Options/OutTable/Serializer/LegacyManifestNormalizer.php | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 569e0d70..bd581db0 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -4,7 +4,6 @@ - */src/Kernel.php diff --git a/src/Config/BaseConfig.php b/src/Config/BaseConfig.php index c30ca55f..152afb00 100644 --- a/src/Config/BaseConfig.php +++ b/src/Config/BaseConfig.php @@ -31,7 +31,7 @@ class BaseConfig implements ConfigInterface */ public function __construct( array $config, - ?ConfigurationInterface $configDefinition = null + ?ConfigurationInterface $configDefinition = null, ) { $this->setConfigDefinition($configDefinition); $this->setConfig($config); diff --git a/src/Manifest/ManifestManager.php b/src/Manifest/ManifestManager.php index 5148646b..f686a4f6 100644 --- a/src/Manifest/ManifestManager.php +++ b/src/Manifest/ManifestManager.php @@ -20,7 +20,7 @@ class ManifestManager private string $dataDir; public function __construct( - string $dataDir + string $dataDir, ) { $this->dataDir = $dataDir; } @@ -36,7 +36,7 @@ final public function getManifestFilename(string $fileName): string public function writeFileManifest( string $fileName, - OutFileManifestOptions $options + OutFileManifestOptions $options, ): void { $tableManifestName = $this->getManifestFilename($fileName); $this->internalWriteFileManifest($tableManifestName, $options->toArray()); diff --git a/src/Manifest/ManifestManager/Options/OutTable/ManifestOptionsSchema.php b/src/Manifest/ManifestManager/Options/OutTable/ManifestOptionsSchema.php index 45d6b521..06666adf 100644 --- a/src/Manifest/ManifestManager/Options/OutTable/ManifestOptionsSchema.php +++ b/src/Manifest/ManifestManager/Options/OutTable/ManifestOptionsSchema.php @@ -31,7 +31,7 @@ public function __construct( bool $nullable = true, bool $primaryKey = false, ?string $description = null, - ?array $metadata = null + ?array $metadata = null, ) { $this->setName($name); if ($dataTypes !== null) { diff --git a/src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php b/src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php index d04cd532..e8db71c3 100644 --- a/src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php +++ b/src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php @@ -172,7 +172,7 @@ private function setTableMetadata(ManifestOptions $manifestOptions, array $data) private function setSchema( ManifestOptions $manifestOptions, array $data, - ?string $metadataBackend + ?string $metadataBackend, ): void { $schema = []; @@ -226,7 +226,7 @@ private function setMetadata( array &$metadata, ?string &$description, bool &$primaryKey, - bool &$isNullable + bool &$isNullable, ): void { if ($meta['key'] === 'KBC.description') { $description = $meta['value']; From 99e0a35962f051ebdc749ca7a2d862d715052a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Nov=C3=A1k?= Date: Tue, 25 Jun 2024 13:51:46 +0200 Subject: [PATCH 7/8] PST-1643 remove empty file --- src/Manifest/ManifestManager/Options/OutTableManifestOptions.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/Manifest/ManifestManager/Options/OutTableManifestOptions.php diff --git a/src/Manifest/ManifestManager/Options/OutTableManifestOptions.php b/src/Manifest/ManifestManager/Options/OutTableManifestOptions.php deleted file mode 100644 index e69de29b..00000000 From 9c4a2fa896dea447cc460b2c0ff5ebc54edfc01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Nov=C3=A1k?= Date: Tue, 25 Jun 2024 13:52:24 +0200 Subject: [PATCH 8/8] PST-1643 remove deploy.sh --- deploy.sh | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 deploy.sh diff --git a/deploy.sh b/deploy.sh deleted file mode 100644 index 1ec535e0..00000000 --- a/deploy.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -set -e - -# Obtain the component repository and log in -docker pull quay.io/keboola/developer-portal-cli-v2:latest -export REPOSITORY=`docker run --rm \ - -e KBC_DEVELOPERPORTAL_USERNAME \ - -e KBC_DEVELOPERPORTAL_PASSWORD \ - quay.io/keboola/developer-portal-cli-v2:latest \ - ecr:get-repository ${KBC_DEVELOPERPORTAL_VENDOR} ${KBC_DEVELOPERPORTAL_APP}` -eval $(docker run --rm \ - -e KBC_DEVELOPERPORTAL_USERNAME \ - -e KBC_DEVELOPERPORTAL_PASSWORD \ - quay.io/keboola/developer-portal-cli-v2:latest \ - ecr:get-login ${KBC_DEVELOPERPORTAL_VENDOR} ${KBC_DEVELOPERPORTAL_APP}) - -# Push to the repository -docker tag ${APP_IMAGE}:latest ${REPOSITORY}:${TRAVIS_TAG} -docker tag ${APP_IMAGE}:latest ${REPOSITORY}:latest -docker push ${REPOSITORY}:${TRAVIS_TAG} -docker push ${REPOSITORY}:latest - -# Update the tag in Keboola Developer Portal -> Deploy to KBC -if echo ${TRAVIS_TAG} | grep -c '^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$' -then - docker run --rm \ - -e KBC_DEVELOPERPORTAL_USERNAME \ - -e KBC_DEVELOPERPORTAL_PASSWORD \ - quay.io/keboola/developer-portal-cli-v2:latest \ - update-app-repository ${KBC_DEVELOPERPORTAL_VENDOR} ${KBC_DEVELOPERPORTAL_APP} ${TRAVIS_TAG} ecr ${REPOSITORY} -else - echo "Skipping deployment to KBC, tag ${TRAVIS_TAG} is not allowed." -fi \ No newline at end of file