keboola / kbc-manage-api-php-client
Keboola Management API Client
Installs: 22 867
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 13
Forks: 1
Open Issues: 2
Requires
- php: ^7.4|^8.0
- guzzlehttp/guzzle: ^7.0|^6.1
Requires (Dev)
- keboola/coding-standard: ^13.0
- keboola/phpunit-retry-annotations: ^0.3.0
- keboola/storage-api-client: ^12.0
- phpstan/phpdoc-parser: 1.5.1
- phpstan/phpstan: ^0.12.94
- phpstan/phpstan-phpunit: ^0.12.22
- phpunit/phpunit: ^7.0|^8.0
- dev-master
- 6.0.0
- 5.2.0
- 5.1.0
- 5.0.0
- 4.0.0
- 3.4.0
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.14.0
- 1.13.0
- 1.12.0
- 1.11.0
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- 0.0.2
- 0.0.1
- dev-jirka-add-manage-token-to-header
- dev-jirka-test-project-purge
- dev-erik-PS-3676
- dev-BC-2745-implement-and-test-adding-a-new-gcs-file-backend
- dev-KBC-1446-apache-brotli
- dev-zajca-kbc-1377
- dev-phpcs-update
- dev-kbc-932-delete-invitation-and-join-reuquest-when-project-purged
- dev-zajca-fix-sapi-client
- dev-zajca-better-debug
- dev-zajca-fix-addRemoveFeatureTest
- dev-zajca-kbc-801
- dev-zajca-kbc-728
- dev-zajca-kbc-541-disbale-staging-load-abs
- dev-revert-100-roman-update-apiary-tokens-response
- dev-KBC-377-new-privilege-can-use-direct-access
- dev-revert-93-zajca-kbc-177-synapse
- dev-zajca-kbc-177-synapse
- dev-revert-87-revert-85-ondra-list-project-templates
- dev-vojta-fs-tests
- dev-vojta-fs-rotate-credentials-apib
- dev-vojta-remove-user
- dev-erik-project-user-0
- dev-vojta-xdebug
This package is auto-updated.
Last update: 2023-01-24 10:45:12 UTC
README
Simple PHP wrapper library for Keboola Management REST API
Installation
Library is available as composer package. To start using composer in your project follow these steps:
Install composer
curl -s http://getcomposer.org/installer | php mv ./composer.phar ~/bin/composer # or /usr/local/bin/composer
Create composer.json file in your project root folder:
{ "require": { "php" : ">=5.4.0", "keboola/kbc-manage-api-php-client": "~0.0" } }
Install package:
composer install
Add autoloader in your bootstrap script:
require 'vendor/autoload.php';
Read more in Composer documentation
Usage examples
require 'vendor/autoload.php'; use Keboola\ManageApi\Client; $client = new Client([ 'token' => getenv('MY_MANAGE_TOKEN'), 'url' => 'https://connnection.keboola.com', ]); $project = $client->getProject(234);
Tests
The main purpose of these test is "black box" test driven development of Keboola Connection. These test guards the API implementation. You can run these tests only against non-production environments.
Tests requires valid Keboola Management API tokens and an endpoint URL of the API test environment.
Note: For automated tests, the tests are run again three times by default if they fail. For local development this would be quite annoying,
so you can disable this by creating new file phpunit-retry.xml
from phpunit-retry.xml.dist
Note: The test environment should be running a cronjob for token-expirator
otherwise the testTemporaryAccess
test will fail.
Create file .env
with environment variables`:
#REQUIRED - must be filled before running any test KBC_MANAGE_API_URL=https://connection.keboola.com KBC_MANAGE_API_TOKEN=your_token KBC_SUPER_API_TOKEN=your_token KBC_MANAGE_API_SUPER_TOKEN_WITH_PROJECTS_READ_SCOPE=super_token_with_projects_read_scope KBC_MANAGE_API_SUPER_TOKEN_WITHOUT_SCOPES=super_token_without_scopes KBC_MANAGE_API_SUPER_TOKEN_WITH_DELETED_PROJECTS_READ_SCOPE=super_token_with_deleted_projects_read_scope KBC_MANAGE_API_SUPER_TOKEN_WITH_UI_MANAGE_SCOPE=super_token_with_ui_manage_scope KBC_TEST_MAINTAINER_ID=2 KBC_TEST_ADMIN_EMAIL=email_of_another_admin_having_mfa_disabled KBC_TEST_ADMIN_TOKEN=token_of_another_admin_having_mfa_disabled KBC_TEST_ADMIN_WITH_MFA_EMAIL=email_of_another_admin_having_mfa_enabled KBC_TEST_ADMIN_WITH_MFA_TOKEN=token_of_another_admin_having_mfa_enabled # OPTIONAL - required only for running file storage test (tests are skipped by default) TEST_ABS_ACCOUNT_KEY= TEST_ABS_ACCOUNT_NAME= TEST_ABS_CONTAINER_NAME= TEST_ABS_REGION= TEST_ABS_ROTATE_ACCOUNT_KEY= TEST_S3_ROTATE_KEY= TEST_S3_ROTATE_SECRET= TEST_S3_FILES_BUCKET= TEST_S3_KEY= TEST_S3_REGION= TEST_S3_SECRET= TEST_GCS_KEYFILE_JSON= TEST_GCS_KEYFILE_ROTATE_JSON= TEST_GCS_FILES_BUCKET= TEST_GCS_REGION= # OPTIONAL - required only for running testCreateStorageBackend, you have to have new snowflake backend and fill credentials into following environment variables KBC_TEST_SNOWFLAKE_BACKEND_NAME= KBC_TEST_SNOWFLAKE_BACKEND_PASSWORD= KBC_TEST_SNOWFLAKE_HOST= KBC_TEST_SNOWFLAKE_WAREHOUSE= KBC_TEST_SNOWFLAKE_BACKEND_REGION=
Source newly created file and run tests:
docker-compose run --rm dev composer tests
Required variables
KBC_MANAGE_API_URL
- URL where Keboola Connection is runningKBC_MANAGE_API_TOKEN
- manage api token assigned to user with superadmin privileges. Can be created in Account Settings under the title Personal Access Tokens. User must have Multi-Factor Authentication disabled.KBC_SUPER_API_TOKEN
- can be created in manage-apps on the Tokens tabKBC_MANAGE_API_SUPER_TOKEN_WITH_UI_MANAGE_SCOPE
- can be created in manage-apps on the Tokens tab. Token must have "ui manage" scopeKBC_TEST_MAINTAINER_ID
-id
of maintainer. Please create a new maintainer dedicated to test suite. All maintainer's organizations and projects all purged before tests!KBC_TEST_ADMIN_EMAIL
- email address of another user without any organizationsKBC_TEST_ADMIN_TOKEN
- is also a Personal Access Token of user without superadmin privileges , but for a different user than that which hasKBC_MANAGE_API_TOKEN
. User must have Multi-Factor Authentication disabled.KBC_TEST_ADMIN_WITH_MFA_EMAIL
- email address of another user without any organizations and having Multi-Factor Authentication enabledKBC_TEST_ADMIN_WITH_MFA_TOKEN
- is also a Personal Access Token of user without superadmin privileges , but for a different user than that which hasKBC_MANAGE_API_TOKEN
orKBC_TEST_ADMIN_TOKEN
Optional variables
These variables are used for testing file storage. You have to copy these values from Azure and AWS portal.
TEST_ABS_ACCOUNT_KEY
- First secret key for Azure Storage accountTEST_ABS_ACCOUNT_NAME
- Name of Azure Storage accountTEST_ABS_CONTAINER_NAME
- Name of container created inside Azure Storage AccountTEST_ABS_REGION
- Name of region where Azure Storage Account is located. (Note: AWS region list is used)TEST_ABS_ROTATE_ACCOUNT_KEY
- Second secret key for Azure Storage accountTEST_S3_ROTATE_KEY
- Second AWS keyTEST_S3_ROTATE_SECRET
- Second AWS secretTEST_S3_FILES_BUCKET
- Name of file bucket on S3TEST_S3_KEY
- First AWS keyTEST_S3_REGION
- Region where your S3 is locatedTEST_S3_SECRET
- First AWS secretTEST_GCS_KEYFILE_JSON
- First GCS key file contents as json stringTEST_GCS_KEYFILE_ROTATE_JSON
- Second GCS key file contents as json string used for testing rotationTEST_GCS_FILES_BUCKET
- Name of file bucket on GCSTEST_GCS_REGION
- Region whare GCS is located
Variable prefixed with ROTATE are used for rotating credentials and they MUST be working credentials.
License
Build OpenAPI document
Currently, we mainly document APIs in apiary.apib file. But we want to move to OpenAPI format. By calling following commands, the apiary.apib file will be translated to OpenAPI format and stored in file openapi.yml. Then you can commit it. We should put it in CI.
You need to install apib2swagger
tool .
$ npm install -g apib2swagger
Then run following commands
$ cat apiary.apib | grep -v "X-KBC-ManageApiToken:" | apib2swagger -o openapi.yml -y --open-api-3 --info-title="Manage API"
$ php AdjustApi.php
MIT licensed, see LICENSE file.