Skip to content

Commit 9ab4ae4

Browse files
authored
Merge pull request #5 from pixelandtonic/cloud-refactor
2.0 Refactor
2 parents 043fe55 + dc44634 commit 9ab4ae4

34 files changed

+2855
-831
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: ci
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
jobs:
6+
ecs:
7+
name: ECS
8+
uses: craftcms/.github/.github/workflows/ecs.yml@v1
9+
with:
10+
php_version: '8.0'
11+
phpstan:
12+
name: PHPStan
13+
uses: craftcms/.github/.github/workflows/phpstan.yml@v1
14+
with:
15+
php_version: '8.0'
16+
phpunit:
17+
runs-on: ubuntu-latest
18+
name: PHPUnit
19+
steps:
20+
- uses: actions/checkout@v1
21+
22+
- name: Validate composer.json
23+
run: composer validate
24+
25+
- name: Cache dependencies
26+
uses: actions/cache@v1
27+
with:
28+
path: ~/.composer/cache/files
29+
key: dependencies-composer-${{ hashFiles('composer.json') }}
30+
31+
- name: Install dependencies
32+
run: composer install --prefer-dist --no-progress --no-suggest
33+
34+
- name: Setup DynamoDB
35+
run: docker-compose up -d dynamodb
36+
37+
- name: Create DynamoDB tables
38+
run: make tables
39+
env:
40+
AWS_REGION: local
41+
AWS_ACCESS_KEY_ID: local
42+
AWS_SECRET_ACCESS_KEY: local
43+
44+
- name: Run test suite
45+
run: composer run-script test
46+
47+
notify-slack:
48+
name: Notify Slack
49+
needs: [ecs, phpstan, phpunit]
50+
if: ${{ always() }}
51+
uses: craftcms/.github/.github/workflows/notify-slack.yml@v1
52+
with:
53+
success: ${{ needs.ecs.result == 'success' && needs.phpstan.result == 'success' && needs.phpunit.result == 'success' }}
54+
failure_text_prefix: <!subteam^SGFL9NKNZ>
55+
secrets:
56+
token: ${{ secrets.GITHUB_TOKEN }}
57+
slack_webhook_url: ${{ secrets.SLACK_CRAFT_WEBHOOK_URL }}

.github/workflows/run-tests.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
# Add to path for GUIs (Tower, etc.)
5+
PATH="/usr/local/bin:$PATH"
6+
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh
7+
8+
npx lint-staged

.lintstagedrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"**/*.php": [
3+
"./vendor/bin/ecs check --ansi --fix",
4+
"./vendor/bin/phpstan analyse"
5+
],
6+
"*": "prettier --ignore-unknown --write"
7+
}

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
vendor/*
3+
build/*

.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"bracketSpacing": false,
4+
"vueIndentScriptAndStyle": true
5+
}

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Release Notes for Yii2 DynamoDB
22

3+
## 2.0.0 - 2022-04-22
4+
5+
## Changed
6+
7+
- Composer packages has moved from `pixelandtonic/yii2-dynamodb` to `craftcms/dynamodb`.
8+
- Namespaces have changed from `pixelandtonic\dynamodb\drivers\*` to `crafcms\dynamodb\*.`
9+
- All components now share a `dynamoDb` property, which is a `craftcms\dynamodb\DynamoDbConnection` instance or configuration.
10+
- Replaced `pixelandtonic\dynamodb\WithDynamoDbClient` with `craftcms\dynamodb\DynamoDbConnection`. Several properties have changed.
11+
- Replaced `pixelandtonic\dynamodb\WithDynamoDbClient::keyPrefix` with `craftcms\dynamodb\DynamoDbConnection::formatKey`.
12+
- A key prefix is no longer added by default to any components. You may add this to any using `craftcms\dynamodb\DynamoDbConnection::formatKey`.
13+
- The default partition key is now `PK`, not `id`.
14+
15+
## Added
16+
17+
- Added `craftcms\dynamodb\DynamoDbConnection::partitionKeyAttribute` and `craftcms\dynamodb\DynamoDbConnection::sortKeyAttribute` to allow for compound keys.
18+
- Added `craftcms\dynamodb\DynamoDbConnection::consistentRead`
19+
- Added `craftcms\dynamodb\DynamoDbConnection::batchConfig`
20+
- Added [TTL support](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html) via `craftcms\dynamodb\DynamoDbConnection::ttl` and `craftcms\dynamodb\DynamoDbConnection::ttlAttribute`.
21+
- Added automatic TTL and garbage collection to the session component.
22+
23+
## Fixed
24+
25+
- Fixed an issue where an `AWS_REGION` would not automatically get used if present.
26+
- Fixed an issue where the session component would not register itself as a session handler.
27+
328
## 1.0.0 - 2020-11-03
429

530
## Added

Makefile

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,36 @@ ENDPOINT_URL ?= http://localhost:8000
66
AWS_ACCESS_KEY_ID = local
77
AWS_SECRET_ACCESS_KEY = local
88

9-
tables:
9+
configure:
10+
aws configure set aws_access_key_id ${AWS_ACCESS_KEY_ID}
11+
aws configure set aws_secret_access_key ${AWS_SECRET_ACCESS_KEY}
12+
cache:
1013
aws --endpoint-url=${ENDPOINT_URL} --region=${REGION} \
11-
dynamodb create-table --table-name=${CACHE_TABLE_NAME} \
12-
--attribute-definitions=AttributeName=id,AttributeType=S \
13-
--key-schema=AttributeName=id,KeyType=HASH \
14-
--billing-mode=PAY_PER_REQUEST && \
14+
dynamodb create-table --table-name ${CACHE_TABLE_NAME} \
15+
--attribute-definitions \
16+
AttributeName=PK,AttributeType=S \
17+
AttributeName=SK,AttributeType=S \
18+
--key-schema \
19+
AttributeName=PK,KeyType=HASH \
20+
AttributeName=SK,KeyType=RANGE \
21+
--provisioned-throughput \
22+
ReadCapacityUnits=5,WriteCapacityUnits=5
23+
sessions:
1524
aws --endpoint-url=${ENDPOINT_URL} --region=${REGION} \
16-
dynamodb create-table --table-name=${SESSION_TABLE_NAME} \
17-
--attribute-definitions=AttributeName=id,AttributeType=S \
18-
--key-schema=AttributeName=id,KeyType=HASH \
19-
--billing-mode=PAY_PER_REQUEST && \
20-
aws --endpoint-url=${ENDPOINT_URL} --region=${REGION} \
21-
dynamodb create-table --table-name=${QUEUE_TABLE_NAME} \
22-
--attribute-definitions=AttributeName=id,AttributeType=S \
23-
--key-schema=AttributeName=id,KeyType=HASH \
24-
--billing-mode=PAY_PER_REQUEST
25+
dynamodb create-table --table-name=${SESSION_TABLE_NAME} \
26+
--attribute-definitions \
27+
AttributeName=id,AttributeType=S \
28+
--key-schema \
29+
AttributeName=id,KeyType=HASH \
30+
--provisioned-throughput \
31+
ReadCapacityUnits=5,WriteCapacityUnits=5
32+
queue:
33+
aws --endpoint-url=${ENDPOINT_URL} --region=${REGION} \
34+
dynamodb create-table --table-name=${QUEUE_TABLE_NAME} \
35+
--attribute-definitions \
36+
AttributeName=PK,AttributeType=S \
37+
--key-schema \
38+
AttributeName=PK,KeyType=HASH \
39+
--provisioned-throughput \
40+
ReadCapacityUnits=5,WriteCapacityUnits=5
41+
tables: configure cache sessions queue

README.md

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Yii2 DynamoDB Cache, Session, and Queue Driver Implementation
1+
# DynamoDB Cache, Session, and Queue for Yii 2
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/pixelandtonic/yii2-dynamodb.svg?style=flat-square)](https://packagist.org/packages/pixelandtonic/yii2-dynamodb)
4-
[![Total Downloads](https://img.shields.io/packagist/dt/pixelandtonic/yii2-dynamodb.svg?style=flat-square)](https://packagist.org/packages/pixelandtonic/yii2-dynamodb)
5-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/pixelandtonic/yii2-dynamodb/run-tests?label=tests)](https://github.com/pixelandtonic/yii2-dynamodb/actions?query=workflow%3Arun-tests+branch%3Amaster)
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/craftcms/yii2-dynamodb.svg?style=flat-square)](https://packagist.org/packages/craftcms/yii2-dynamodb)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/craftcms/yii2-dynamodb.svg?style=flat-square)](https://packagist.org/packages/craftcms/yii2-dynamodb)
5+
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/craftcms/yii2-dynamodb/run-tests?label=tests)](https://github.com/pixelandtonic/yii2-dynamodb/actions?query=workflow%3Aci+branch%3Amaster)
66

77
Easily use DynamoDB as a [cache](https://www.yiiframework.com/doc/guide/2.0/en/caching-overview), [session](https://www.yiiframework.com/doc/guide/2.0/en/runtime-sessions-cookies), or [queue](https://github.com/yiisoft/yii2-queue) using this library in your Yii2 or Craft CMS projects.
88

@@ -13,12 +13,12 @@ Easily use DynamoDB as a [cache](https://www.yiiframework.com/doc/guide/2.0/en/c
1313
You can install the package via composer:
1414

1515
```bash
16-
composer require pixelandtonic/yii2-dynamodb
16+
composer require craftcms/yii2-dynamodb
1717
```
1818

1919
## Usage
2020

21-
This package provides three drivers for DynamoDB; caching, sessions, and queuing.
21+
This package provides three Yii components for DynamoDB: cache, session, and queue.
2222

2323
### Cache Component
2424

@@ -40,7 +40,7 @@ aws dynamodb create-table --table-name=my-app-cache-table \
4040
In your `app.php`, configure the `cache` component to use the driver.
4141

4242
```php
43-
use \pixelandtonic\dynamodb\drivers\DynamoDbCache;
43+
use craftcms\dynamodb\DynamoDbCache;
4444

4545
return [
4646
'bootstrap' => [
@@ -49,13 +49,19 @@ return [
4949
'components' => [
5050
'cache' => [
5151
'class' => DynamoDbCache::class,
52-
'table' => 'my-app-cache-table',
53-
'tableIdAttribute' => 'id', // optional: defaults to id
54-
'tableDataAttribute' => 'data', // optional: defaults to data
55-
'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
56-
'key' => '<key>', // optional: defaults to AWS_ACCESS_KEY_ID env var
57-
'secret' => '<secret>', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
58-
'region' => '<region>', // optional: defaults to AWS_REGION env var
52+
'dataAttribute' => 'data', // optional: defaults to data
53+
'dynamoDb' => [
54+
'table' => 'my-app-cache-table',
55+
'partitionKeyAttribute' => 'id', // optional: defaults to 'PK'
56+
'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
57+
'region' => '<region>', // optional: defaults to AWS_REGION env var
58+
'ttl' => 60*60*24, // optional: number of seconds until items are considered expired
59+
'ttlAttribute' => 'expires' // optional: defaults to 'TTL'
60+
'credentials' => [
61+
'key' => '<key>', // optional: defaults to AWS_ACCESS_KEY_ID env var
62+
'secret' => '<secret>', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
63+
],
64+
],
5965
],
6066
],
6167
];
@@ -81,7 +87,7 @@ aws dynamodb create-table --table-name=my-app-session-table \
8187
In your `app.php`, configure the `session` component to use the driver.
8288

8389
```php
84-
use \pixelandtonic\dynamodb\drivers\DynamoDbSession;
90+
use craftcms\dynamodb\DynamoDbSession;
8591

8692
return [
8793
'bootstrap' => [
@@ -90,13 +96,19 @@ return [
9096
'components' => [
9197
'session' => [
9298
'class' => DynamoDbSession::class,
93-
'table' => 'my-app-session-table',
94-
'tableIdAttribute' => 'id', // optional: defaults to id
95-
'tableDataAttribute' => 'data', // optional: defaults to data
96-
'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
97-
'key' => '<key>', // optional: defaults to AWS_ACCESS_KEY_ID env var
98-
'secret' => '<secret>', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
99-
'region' => '<region>', // optional: defaults to AWS_REGION env var
99+
'dataAttribute' => 'data', // optional: defaults to data
100+
'dynamoDb' => [
101+
'table' => 'my-app-session-table',
102+
'partitionKeyAttribute' => 'id', // optional: defaults to 'PK'
103+
'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
104+
'region' => '<region>', // optional: defaults to AWS_REGION env var
105+
'ttl' => 60*60*24, // optional: number of seconds until items are considered expired
106+
'ttlAttribute' => 'expires' // optional: defaults to 'TTL'
107+
'credentials' => [
108+
'key' => '<key>', // optional: defaults to AWS_ACCESS_KEY_ID env var
109+
'secret' => '<secret>', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
110+
],
111+
],
100112
],
101113
],
102114
];
@@ -122,7 +134,7 @@ aws dynamodb create-table --table-name=my-app-queue-table \
122134
In your `app.php`, configure the `queue` component to use the driver.
123135

124136
```php
125-
use \pixelandtonic\dynamodb\drivers\DynamoDbQueue;
137+
use craftcms\dynamodb\DynamoDbQueue;
126138

127139
return [
128140
'bootstrap' => [
@@ -131,13 +143,18 @@ return [
131143
'components' => [
132144
'queue' => [
133145
'class' => DynamoDbQueue::class,
134-
'table' => 'my-app-queue-table',
135-
'tableIdAttribute' => 'id', // optional: defaults to id
136-
'tableDataAttribute' => 'data', // optional: defaults to data
137-
'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
138-
'key' => '<key>', // optional: defaults to AWS_ACCESS_KEY_ID env var
139-
'secret' => '<secret>', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
140-
'region' => '<region>', // optional: defaults to AWS_REGION env var
146+
'dynamoDb' => [
147+
'table' => 'my-app-queue-table',
148+
'partitionKeyAttribute' => 'id', // optional: defaults to 'PK'
149+
'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
150+
'region' => '<region>', // optional: defaults to AWS_REGION env var
151+
'ttl' => 60*60*24, // optional: number of seconds until items are considered expired
152+
'ttlAttribute' => 'expires' // optional: defaults to 'TTL'
153+
'credentials' => [
154+
'key' => '<key>', // optional: defaults to AWS_ACCESS_KEY_ID env var
155+
'secret' => '<secret>', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
156+
],
157+
],
141158
],
142159
],
143160
];
@@ -152,14 +169,15 @@ Tests run against local DynamoDB tables using Docker. To run tests, you must run
152169
3. Create the DynamoDB tables for the [cache](#create-dynamodb-cache-table), [session](#create-dynamodb-session-table), and [queue](#create-dynamodb-queue-table)
153170
4. Run the test suite with `vendor/bin/phpunit --testdox`
154171

155-
To make the setup and testing easier, you can run the following Composer scripts:
172+
To make the setup and testing easier, you can run the following Composer scripts:
156173

157174
1. `composer run setup`
158175
2. `composer run test`
159176

160177
## Credits
161178

162179
- [Jason McCallister](https://github.com/jasonmccallister)
180+
- [Tim Kelty](https://github.com/timkelty)
163181
- [All Contributors](../../contributors)
164182

165183
## License

0 commit comments

Comments
 (0)