Skip to content

Commit 7c17061

Browse files
authored
Merge pull request #1 from OS2web/os2web_key
os2web_key
2 parents 43f2d2f + 0eb16ad commit 7c17061

17 files changed

+991
-1
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
charset = utf-8
11+
indent_style = space
12+
indent_size = 2

.github/workflows/pr.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
on: pull_request
2+
name: Review
3+
jobs:
4+
changelog:
5+
runs-on: ubuntu-latest
6+
name: Changelog should be updated
7+
strategy:
8+
fail-fast: false
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
with:
13+
fetch-depth: 2
14+
15+
- name: Git fetch
16+
run: git fetch
17+
18+
- name: Check that changelog has been updated.
19+
run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0
20+
21+
test-composer-files:
22+
name: Validate composer
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
php-versions: [ '8.1' ]
27+
dependency-version: [ prefer-lowest, prefer-stable ]
28+
steps:
29+
- uses: actions/checkout@master
30+
- name: Setup PHP, with composer and extensions
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php-versions }}
34+
extensions: json
35+
coverage: none
36+
tools: composer:v2
37+
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
38+
- name: Get composer cache directory
39+
id: composer-cache
40+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
41+
- name: Cache dependencies
42+
uses: actions/cache@v2
43+
with:
44+
path: ${{ steps.composer-cache.outputs.dir }}
45+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
46+
restore-keys: ${{ runner.os }}-composer-
47+
- name: Validate composer files
48+
run: |
49+
composer validate --strict composer.json
50+
# Check that dependencies resolve.
51+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
52+
- name: Check that composer file is normalized
53+
run: |
54+
composer normalize --dry-run
55+
56+
php-coding-standards:
57+
name: PHP coding standards
58+
runs-on: ubuntu-latest
59+
strategy:
60+
matrix:
61+
php-versions: [ '8.1' ]
62+
steps:
63+
- uses: actions/checkout@master
64+
- name: Setup PHP, with composer and extensions
65+
uses: shivammathur/setup-php@v2
66+
with:
67+
php-version: ${{ matrix.php-versions }}
68+
extensions: json
69+
coverage: none
70+
tools: composer:v2
71+
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
72+
- name: Get composer cache directory
73+
id: composer-cache
74+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
75+
- name: Cache dependencies
76+
uses: actions/cache@v2
77+
with:
78+
path: ${{ steps.composer-cache.outputs.dir }}
79+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
80+
restore-keys: ${{ runner.os }}-composer-
81+
- name: Install Dependencies
82+
run: |
83+
composer install --no-interaction --no-progress
84+
- name: PHPCS
85+
run: |
86+
composer coding-standards-check/phpcs
87+
88+
php-code-analysis:
89+
name: PHP code analysis
90+
runs-on: ubuntu-latest
91+
strategy:
92+
matrix:
93+
php-versions: [ '8.1' ]
94+
steps:
95+
- uses: actions/checkout@master
96+
- name: Setup PHP, with composer and extensions
97+
uses: shivammathur/setup-php@v2
98+
with:
99+
php-version: ${{ matrix.php-versions }}
100+
extensions: json
101+
coverage: none
102+
tools: composer:v2
103+
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
104+
- name: Get composer cache directory
105+
id: composer-cache
106+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
107+
- name: Cache dependencies
108+
uses: actions/cache@v2
109+
with:
110+
path: ${{ steps.composer-cache.outputs.dir }}
111+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
112+
restore-keys: ${{ runner.os }}-composer-
113+
- name: Code analysis
114+
run: |
115+
./scripts/code-analysis
116+
117+
coding-standards-markdown:
118+
name: Markdown coding standards
119+
runs-on: ubuntu-latest
120+
steps:
121+
- name: Checkout
122+
uses: actions/checkout@master
123+
124+
- name: Coding standards
125+
run: |
126+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'

.gitignore

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

.markdownlint.jsonc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"default": true,
3+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md
4+
"line-length": {
5+
"line_length": 120,
6+
"code_blocks": false,
7+
"tables": false
8+
},
9+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
10+
"no-duplicate-heading": {
11+
"siblings_only": true
12+
}
13+
}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
[Unreleased]: https://github.com/rimi-itk/os2web_key

README.md

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,134 @@
11
# OS2Web key
22

3-
Key stuff for OS2Web.
3+
Key types and providers for OS2Web built on the [Key module](https://www.drupal.org/project/key).
4+
5+
## Installation
6+
7+
``` shell
8+
composer require os2web/os2web_key
9+
drush pm:install os2web_key
10+
```
11+
12+
## Key types
13+
14+
### Certificate
15+
16+
This key type handles [PKCS 12](https://en.wikipedia.org/wiki/PKCS_12) or [Privacy-Enhanced Mail
17+
(PEM)](https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail) certificate with an optional password (passphrase).
18+
19+
Use in a form:
20+
21+
``` php
22+
$form['key'] => [
23+
'#type' => 'key_select',
24+
'#key_filters' => [
25+
'type' => 'os2web_key_certificate',
26+
],
27+
];
28+
```
29+
30+
The [`KeyHelper`](https://github.com/OS2web/os2web_key/blob/main/src/KeyHelper.php) can be used to get
31+
the actual certificates (parts):
32+
33+
``` php
34+
<?php
35+
36+
use Drupal\os2web_key\KeyHelper;
37+
use Drupal\key\KeyRepositoryInterface;
38+
39+
// Use dependency injection for this.
40+
/** @var KeyRepositoryInterface $repository */
41+
$repository = \Drupal::service('key.repository');
42+
/** @var KeyHelper $helper */
43+
$helper = \Drupal::service(KeyHelper::class);
44+
45+
// Use `drush key:list` to list your keys.
46+
$key = $repository->getKey('my_key');
47+
[
48+
// Passwordless certificate.
49+
CertificateKeyType::CERT => $certificate,
50+
CertificateKeyType::PKEY => $privateKey,
51+
] = $helper->getCertificates($key);
52+
53+
```
54+
55+
**Note**: The parsed certificate has no password.
56+
57+
### OpenID Connect (OIDC)
58+
59+
Example use in a form:
60+
61+
``` php
62+
$form['key'] => [
63+
'#type' => 'key_select',
64+
'#key_filters' => [
65+
'type' => 'os2web_key_oidc,
66+
],
67+
];
68+
```
69+
70+
Get the OIDC config:
71+
72+
``` php
73+
<?php
74+
75+
use Drupal\key\KeyRepositoryInterface;
76+
use Drupal\os2web_key\Plugin\KeyType\OidcKeyType;
77+
78+
// Use dependency injection for this.
79+
/** @var KeyRepositoryInterface $repository */
80+
$repository = \Drupal::service('key.repository');
81+
82+
$key = $repository->getKey('openid_connect_ad');
83+
[
84+
OidcKeyType::DISCOVERY_URL => $discoveryUrl,
85+
OidcKeyType::CLIENT_ID => $clientId,
86+
OidcKeyType::CLIENT_SECRET => $clientSecret,
87+
] = $helper->getOidcValues($key);
88+
```
89+
90+
See [the Key Developer Guide](https://www.drupal.org/docs/contributed-modules/key/developer-guide) for details and more
91+
examples.
92+
93+
## Providers
94+
95+
### `@todo` Azure Key Vault
96+
97+
<https://azure.microsoft.com/en-us/products/key-vault>
98+
99+
### `@todo` Infisical
100+
101+
<https://infisical.com/>
102+
103+
## Coding standards
104+
105+
Our coding are checked by GitHub Actions (cf. [.github/workflows/pr.yml](.github/workflows/pr.yml)). Use the commands
106+
below to run the checks locally.
107+
108+
### PHP
109+
110+
```shell
111+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer install
112+
# Fix (some) coding standards issues
113+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer coding-standards-apply
114+
# Check that code adheres to the coding standards
115+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer coding-standards-check
116+
```
117+
118+
### Markdown
119+
120+
```shell
121+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md' --fix
122+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'
123+
```
124+
125+
## Code analysis
126+
127+
We use [PHPStan](https://phpstan.org/) for static code analysis.
128+
129+
Running statis code analysis on a standalone Drupal module is a bit tricky, so we use a helper script to run the
130+
analysis:
131+
132+
```shell
133+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm ./scripts/code-analysis
134+
```

composer.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "os2web/os2web_key",
3+
"description": "OS2Web key",
4+
"license": "EUPL-1.2",
5+
"type": "drupal-module",
6+
"authors": [
7+
{
8+
"name": "Mikkel Ricky",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": "^8.1",
14+
"ext-openssl": "*",
15+
"drupal/core": "^9 || ^10",
16+
"drupal/key": "^1.17"
17+
},
18+
"require-dev": {
19+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
20+
"drupal/coder": "^8.3",
21+
"ergebnis/composer-normalize": "^2.42",
22+
"mglaman/phpstan-drupal": "^1.2",
23+
"phpstan/extension-installer": "^1.3",
24+
"phpstan/phpstan-deprecation-rules": "^1.1"
25+
},
26+
"repositories": [
27+
{
28+
"type": "composer",
29+
"url": "https://packages.drupal.org/8"
30+
}
31+
],
32+
"config": {
33+
"allow-plugins": {
34+
"dealerdirect/phpcodesniffer-composer-installer": true,
35+
"ergebnis/composer-normalize": true,
36+
"phpstan/extension-installer": true
37+
},
38+
"sort-packages": true
39+
},
40+
"scripts": {
41+
"coding-standards-apply": [
42+
"@coding-standards-apply/phpcs"
43+
],
44+
"coding-standards-apply/phpcs": [
45+
"phpcbf --standard=phpcs.xml.dist"
46+
],
47+
"coding-standards-check": [
48+
"@coding-standards-check/phpcs"
49+
],
50+
"coding-standards-check/phpcs": [
51+
"phpcs --standard=phpcs.xml.dist"
52+
]
53+
}
54+
}

os2web_key.info.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: 'OS2Web key'
2+
type: module
3+
description: 'Key stuff for OS2Web'
4+
package: 'OS2web'
5+
core_version_requirement: ^9 || ^10

os2web_key.services.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
logger.channel.os2web_key:
3+
parent: logger.channel_base
4+
arguments: [ 'os2web_key' ]
5+
6+
Drupal\os2web_key\KeyHelper:
7+
arguments:
8+
- '@logger.channel.os2web_key'

phpcs.xml.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="PHP_CodeSniffer">
3+
<description>PHP Code Sniffer configuration</description>
4+
5+
<file>.</file>
6+
<exclude-pattern>vendor/</exclude-pattern>
7+
8+
<!-- Show progress of the run -->
9+
<arg value="p"/>
10+
<arg value="s"/>
11+
12+
<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,yml"/>
13+
<config name="drupal_core_version" value="10"/>
14+
15+
<rule ref="Drupal">
16+
<!-- We want to be able to use "package" and "version" in our custom modules -->
17+
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Project"/>
18+
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Version"/>
19+
</rule>
20+
21+
<rule ref="DrupalPractice"/>
22+
</ruleset>

0 commit comments

Comments
 (0)