Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Fixes #86: Add several ways to create a client. Deprecate old ways. #87

Merged
merged 5 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Environment variables can be set from a .env file placed in the location you
# run client scripts from. One can also be placed in the ACSF gfs mount for
# each environment.
#
# The AH_* variables should be removed when running on Acquia environments.
#
# The username of the user the API key belongs to.
ACSF_API_USERNAME=api.user
# The API key to access the API with.
# https://docs.acquia.com/site-factory/extend/api/#obtaining-your-api-key
ACSF_API_KEY=abc123
# The ACSF site group.
AH_SITE_GROUP=example
# The ACSF environment.
AH_SITE_ENVIRONMENT=01dev
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
.idea/*
/vendor/
.phpcs-cache
.phpunit.result.cache

# macOS

# General
.DS_Store
.AppleDouble
.LSOverride
.env

# Icon must end with two \r
Icon
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Example scripts are available in the [examples](examples/) folder.

require 'vendor/autoload.php';

use swichers\Acsf\Client\ServiceLoader;
use swichers\Acsf\Client\ClientFactory;

$base_config = [
'username' => 'example.user',
Expand All @@ -45,8 +45,7 @@ Example scripts are available in the [examples](examples/) folder.
'environment' => 'live',
];

$client = ServiceLoader::buildFromConfig(['acsf.client.connection' => $base_config])
->get('acsf.client');
$client = ClientFactory::createFromArray($base_config);

// Check the service status.
print_r($client->getAction('Status')->ping());
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"symfony/dependency-injection": "^4.3",
"symfony/finder": "^4.3",
"symfony/http-client": "^4.3",
"symfony/yaml": "^4.3"
"symfony/yaml": "^4.3",
"symfony/dotenv": "^4.4"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0 || ^0.6.0",
Expand Down
76 changes: 74 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/.gitignore

This file was deleted.

8 changes: 4 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Library Usage Examples

This folder contains some examples of how to use the library to script ACSF
deployments and associated tasks. To use these examples rename the
`example.config.php` file to `config.php` and add your ACSF credentials.

deployments and associated tasks. To use these examples copy the `.env.dist`
file to `.env` in this folder. Then edit and configure each value in that file.
```sh
cp example.config.php config.php
cp ../.env.dist .env
```

## Files
Expand Down
17 changes: 4 additions & 13 deletions examples/backport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
declare(strict_types = 1);

use swichers\Acsf\Client\Endpoints\Entity\EntityInterface;
use swichers\Acsf\Client\ServiceLoader;
use swichers\Acsf\Client\ClientFactory;

require 'config.php';
require '../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

// The environment to backport to.
define('TARGET_ENV', $argv[1] ?? '');
Expand All @@ -36,15 +35,7 @@

$start_time = new DateTime();

$base_config = [
'username' => API_USERNAME,
'api_key' => API_KEY,
'site_group' => ACSF_SITE_GROUP,
];

$client = ServiceLoader::buildFromConfig(
['acsf.client.connection' => ['environment' => SOURCE_ENV] + $base_config]
)->get('acsf.client');
$client = ClientFactory::createFromEnvironment(SOURCE_ENV);

$sites = $client->getAction('Sites')->listAll();
$site_ids = array_column($sites['sites'], 'id');
Expand Down Expand Up @@ -80,7 +71,7 @@ function (EntityInterface $task, $task_status) {
);

// Change to the target environment.
$client->setConfig(['environment' => TARGET_ENV] + $base_config);
$client->setEnvironment(TARGET_ENV);

$refs = $client->getAction('Vcs')->list(['stack_id' => STACK_ID]);
if (!in_array(DEPLOY_REF, $refs['available'])) {
Expand Down
15 changes: 3 additions & 12 deletions examples/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

declare(strict_types = 1);

use swichers\Acsf\Client\ClientFactory;
use swichers\Acsf\Client\Endpoints\Entity\EntityInterface;
use swichers\Acsf\Client\ServiceLoader;

require 'config.php';
require '../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

// The environment to back up.
define('TARGET_ENV', $argv[1] ?? '');
Expand All @@ -30,15 +29,7 @@

$start_time = new DateTime();

$base_config = [
'username' => API_USERNAME,
'api_key' => API_KEY,
'site_group' => ACSF_SITE_GROUP,
];

$client = ServiceLoader::buildFromConfig(
['acsf.client.connection' => ['environment' => TARGET_ENV] + $base_config]
)->get('acsf.client');
$client = ClientFactory::createFromEnvironment(TARGET_ENV);

$client->getAction('Sites')->backupAll(
['components' => ['database']],
Expand Down
15 changes: 3 additions & 12 deletions examples/cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

declare(strict_types = 1);

use swichers\Acsf\Client\ServiceLoader;
use swichers\Acsf\Client\ClientFactory;

require 'config.php';
require '../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

// The environment to redeploy code on.
define('TARGET_ENV', $argv[1] ?? '');
Expand All @@ -30,15 +29,7 @@

$start_time = new DateTime();

$base_config = [
'username' => API_USERNAME,
'api_key' => API_KEY,
'site_group' => ACSF_SITE_GROUP,
];

$client = ServiceLoader::buildFromConfig(
['acsf.client.connection' => ['environment' => TARGET_ENV] + $base_config]
)->get('acsf.client');
$client = ClientFactory::createFromEnvironment(TARGET_ENV);

printf("Clearing site caches.\n");
$client->getAction('Sites')->clearCaches();
Expand Down
17 changes: 4 additions & 13 deletions examples/deploy-uat.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

declare(strict_types = 1);

use swichers\Acsf\Client\ClientFactory;
use swichers\Acsf\Client\ClientInterface;
use swichers\Acsf\Client\Endpoints\Entity\EntityInterface;
use swichers\Acsf\Client\ServiceLoader;

require 'config.php';
require '../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

// The code reference to deploy to uat.
define('DEPLOY_REF', $argv[1] ?? '');
Expand All @@ -38,15 +37,7 @@

$start_time = new DateTime();

$base_config = [
'username' => API_USERNAME,
'api_key' => API_KEY,
'site_group' => ACSF_SITE_GROUP,
];

$client = ServiceLoader::buildFromConfig(
['acsf.client.connection' => ['environment' => 'live'] + $base_config]
)->get('acsf.client');
$client = ClientFactory::createFromEnvironment('live');

$task_id = start_production_backport($client, TARGET_ENV);
if (FALSE === $task_id) {
Expand All @@ -66,7 +57,7 @@ function (EntityInterface $task, array $task_status) {
);

// Swap to the destination environment.
$client->setConfig(['environment' => TARGET_ENV] + $base_config);
$client->setEnvironment(TARGET_ENV);

$refs = $client->getAction('Vcs')->list(['stack_id' => STACK_ID]);
if (!in_array(DEPLOY_REF, $refs['available'])) {
Expand Down
16 changes: 3 additions & 13 deletions examples/deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

declare(strict_types = 1);

use swichers\Acsf\Client\ClientFactory;
use swichers\Acsf\Client\Endpoints\Entity\EntityInterface;
use swichers\Acsf\Client\ServiceLoader;

require 'config.php';
require '../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

// The environment to deploy to.
define('TARGET_ENV', $argv[1] ?? '');
Expand All @@ -34,16 +33,7 @@

$start_time = new DateTime();

$base_config = [
'username' => API_USERNAME,
'api_key' => API_KEY,
'site_group' => ACSF_SITE_GROUP,
'environment' => TARGET_ENV,
];

$client = ServiceLoader::buildFromConfig(
['acsf.client.connection' => $base_config]
)->get('acsf.client');
$client = ClientFactory::createFromEnvironment(TARGET_ENV);

$refs = $client->getAction('Vcs')->list(['stack_id' => STACK_ID]);
if (!in_array(DEPLOY_REF, $refs['available'])) {
Expand Down
15 changes: 0 additions & 15 deletions examples/example.config.php

This file was deleted.

15 changes: 3 additions & 12 deletions examples/redeploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

declare(strict_types = 1);

use swichers\Acsf\Client\ClientFactory;
use swichers\Acsf\Client\Endpoints\Entity\EntityInterface;
use swichers\Acsf\Client\ServiceLoader;

require 'config.php';
require '../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

// The environment to redeploy code on.
define('TARGET_ENV', $argv[1] ?? '');
Expand All @@ -34,15 +33,7 @@

$start_time = new DateTime();

$base_config = [
'username' => API_USERNAME,
'api_key' => API_KEY,
'site_group' => ACSF_SITE_GROUP,
];

$client = ServiceLoader::buildFromConfig(
['acsf.client.connection' => ['environment' => TARGET_ENV] + $base_config]
)->get('acsf.client');
$client = ClientFactory::createFromEnvironment(TARGET_ENV);

$refs = $client->getAction('Vcs')->list(['stack_id' => STACK_ID]);
printf("Redeploying code: %s\n", $refs['current']);
Expand Down
Loading