Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents 46826a8 + 431ab48 commit a0e2045
Show file tree
Hide file tree
Showing 20 changed files with 532 additions and 96 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/manual-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Manual Release
# Triggers a merge from main->release, which will then trigger a release
# from the release branch.
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
merge-to-release-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main

- name: Merge main -> release
uses: devmasx/merge-branch@master
with:
type: now
from_branch: main
target_branch: release
github_token: ${{ secrets.MOMENTO_MACHINE_USER_GITHUB_TOKEN }}
67 changes: 67 additions & 0 deletions .github/workflows/on-push-to-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: On push to release

on:
push:
branches: [ release ]

jobs:
release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release.outputs.release }}
steps:
- uses: actions/checkout@v3
- name: Set release
id: semrel
uses: go-semantic-release/action@v1
with:
github-token: ${{ secrets.MOMENTO_MACHINE_USER_GITHUB_TOKEN }}
allow-initial-development-versions: true
force-bump-patch-version: true
# For whatever reason, this silly tool won't let you do releases from branches
# other than the default branch unless you pass this flag, which doesn't seem
# to actually have anything to do with CI:
# https://github.com/go-semantic-release/semantic-release/blob/master/cmd/semantic-release/main.go#L173-L194
# https://github.com/go-semantic-release/condition-github/blob/4c8af3fc516151423fff2f77eb08bf7082570676/pkg/condition/github.go#L42-L44
custom-arguments: "--no-ci"

- name: Output release
id: release
run: echo "::set-output name=release::${{ steps.semrel.outputs.version }}"

test:
runs-on: ubuntu-latest
env:
TEST_AUTH_TOKEN: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
TEST_CACHE_NAME: php-integration-test-cache

steps:
- uses: actions/checkout@v3

- name: Verify README generation
uses: momentohq/standards-and-practices/github-actions/oss-readme-template@gh-actions-v1
with:
project_status: official
project_stability: alpha
project_type: sdk
sdk_language: PHP
usage_example_path: ./examples/example.php

- name: Commitlint and Other Shared Build Steps
uses: momentohq/standards-and-practices/github-actions/shared-build@gh-actions-v1
env:
GITHUB_TOKEN: ${{ secrets.MOMENTO_MACHINE_USER_GITHUB_TOKEN }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: grpc
tools: composer

- name: Install dependencies
run: composer install

- name: Run tests
run: php vendor/phpunit/phpunit/phpunit --configuration phpunit.xml

2 changes: 1 addition & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Momento Serverless Cache の PHP クライアント SDK:従来のキャッシ
### 必要条件

- Momento Auth Token が必要です。[Momento CLI](https://github.com/momentohq/momento-cli)を使って生成できます。
- 少なくとも PHP 7
- 少なくとも PHP 8.0
- grpc PHP エクステンション。 インストール方法はこちらの[gRPC docs](https://github.com/grpc/grpc/blob/v1.46.3/src/php/README.md)を参考にしてください。

**IDE に関する注意事項**: [PhpStorm](https://www.jetbrains.com/phpstorm/)[Microsoft Visual Studio Code](https://code.visualstudio.com/)の様な PHP 開発をサポートできる IDE が必要となります。
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Japanese: [日本語](README.ja.md)
### Requirements

- A Momento Auth Token is required, you can generate one using the [Momento CLI](https://github.com/momentohq/momento-cli)
- At least PHP 7
- At least PHP 8.0
- The grpc PHP extension. See the [gRPC docs](https://github.com/grpc/grpc/blob/v1.46.3/src/php/README.md) section on installing the extension.

**IDE Notes**: You'll most likely want to use an IDE that supports PHP development, such as [PhpStorm](https://www.jetbrains.com/phpstorm/) or [Microsoft Visual Studio Code](https://code.visualstudio.com/).
Expand Down
2 changes: 1 addition & 1 deletion README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Japanese: [日本語](README.ja.md)
### Requirements

- A Momento Auth Token is required, you can generate one using the [Momento CLI](https://github.com/momentohq/momento-cli)
- At least PHP 7
- At least PHP 8.0
- The grpc PHP extension. See the [gRPC docs](https://github.com/grpc/grpc/blob/v1.46.3/src/php/README.md) section on installing the extension.

**IDE Notes**: You'll most likely want to use an IDE that supports PHP development, such as [PhpStorm](https://www.jetbrains.com/phpstorm/) or [Microsoft Visual Studio Code](https://code.visualstudio.com/).
Expand Down
71 changes: 37 additions & 34 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
{
"name": "momentohq/client-sdk-php",
"type": "library",
"autoload": {
"psr-4": {
"Momento\\": "src/",
"Cache_client\\": "types/Cache_client/",
"Control_client\\": "types/Control_client/",
"Auth\\": "types/Auth/",
"GPBMetadata\\": "types/GPBMetadata"
},
"files": [
"src/Utilities/_DataValidation.php"
],
"classmap": [
"src/Cache/CacheOperationTypes/CacheOperationTypes.php",
"src/Cache/Errors/Errors.php"
]
"name": "momentohq/client-sdk-php",
"type": "library",
"autoload": {
"psr-4": {
"Momento\\": "src/",
"Cache_client\\": "types/Cache_client/",
"Control_client\\": "types/Control_client/",
"Auth\\": "types/Auth/",
"GPBMetadata\\": "types/GPBMetadata"
},
"autoload-dev": {
"psr-4": { "Momento\\Tests\\": "tests/" }
},
"require": {
"php": ">=7.4",
"google/protobuf": "3.21.5",
"grpc/grpc": "1.42.0",
"ext-grpc": "*"
},
"require-dev": {
"composer/composer" : "^2.4.1",
"phpunit/phpunit": "^9.5.23"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
"files": [
"src/Utilities/_DataValidation.php"
],
"classmap": [
"src/Cache/CacheOperationTypes/CacheOperationTypes.php",
"src/Cache/Errors/Errors.php"
]
},
"autoload-dev": {
"psr-4": {
"Momento\\Tests\\": "tests/"
}
},
"require": {
"php": ">=8.0",
"ext-grpc": "*",
"firebase/php-jwt": "^6.3",
"google/protobuf": "3.21.5",
"grpc/grpc": "1.42.0"
},
"require-dev": {
"composer/composer": "^2.4.1",
"phpunit/phpunit": "^9.5.23"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
}
}
64 changes: 63 additions & 1 deletion composer.lock

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

25 changes: 18 additions & 7 deletions src/Auth/AuthUtils.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
<?php
declare(strict_types=1);

namespace Momento\Auth;

use Firebase\JWT\JWT;
use Momento\Cache\Errors\InvalidArgumentError;


class AuthUtils
{

private static function throwBadAuthToken() {
private static function throwBadAuthToken()
{
throw new InvalidArgumentError('Invalid Momento auth token.');
}

public static function parseAuthToken(string $authToken) : array {
$exploded = explode (".", $authToken);
public static function parseAuthToken(string $authToken): object
{
$exploded = explode(".", $authToken);
if (count($exploded) != 3) {
self::throwBadAuthToken();
}
list($header, $payload, $signature) = $exploded;
$token = json_decode(base64_decode($payload), true);
if ($token === null) {

try {
list($header, $payload, $signature) = $exploded;
$payload = JWT::jsonDecode(JWT::urlsafeB64Decode($payload));
} catch (\Exception) {
self::throwBadAuthToken();
}

if ($payload === null) {
self::throwBadAuthToken();
}
return $token;
return $payload;
}

}
14 changes: 8 additions & 6 deletions src/Auth/EnvMomentoTokenProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Momento\Auth;

use Momento\Auth\AuthUtils;
Expand All @@ -15,26 +17,26 @@ class EnvMomentoTokenProvider implements ICredentialProvider
public function __construct(string $envVariableName)
{
$authToken = getenv($envVariableName);
if (isNullOrEmpty($authToken)) {
if ($authToken === false || isNullOrEmpty($authToken)) {
throw new InvalidArgumentError("Environment variable $envVariableName is empty or null.");
}
$payload = AuthUtils::parseAuthToken($authToken);
$this->authToken = $authToken;
$this->controlEndpoint = $payload["cp"];
$this->cacheEndpoint = $payload["c"];
$this->controlEndpoint = $payload->cp;
$this->cacheEndpoint = $payload->c;
}

public function getAuthToken() : string
public function getAuthToken(): string
{
return $this->authToken;
}

public function getCacheEndpoint() : string
public function getCacheEndpoint(): string
{
return $this->cacheEndpoint;
}

public function getControlEndpoint() : string
public function getControlEndpoint(): string
{
return $this->controlEndpoint;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Auth/ICredentialProvider.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php
declare(strict_types=1);

namespace Momento\Auth;

interface ICredentialProvider
{
public function getAuthToken() : string;
public function getControlEndpoint() : string;
public function getAuthToken(): string;

public function getControlEndpoint(): string;

public function getCacheEndpoint() : string;
}
Loading

0 comments on commit a0e2045

Please sign in to comment.