Skip to content

Commit 0a8ed92

Browse files
committed
chore: changelog updated
1 parent 45755f0 commit 0a8ed92

File tree

4 files changed

+120
-8
lines changed

4 files changed

+120
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file.
88

99
- Added option to pass credentials as dict object
1010

11+
### ⚙️ Miscellaneous Tasks
12+
13+
- Changelog updated
14+
1115
## [0.0.2] - 2025-01-02
1216

1317
### 🚀 Features

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,114 @@ except Exception as e:
368368
print(f"Transaction error: {e}")
369369
```
370370

371+
## 🚀 CI/CD Pipeline Integration
372+
373+
### 🔄 Using in GitHub Actions or Other CI/CD Pipelines
374+
375+
For CI/CD environments where you can't use traditional environment variables or service account files, you can pass the credentials directly as a JSON string:
376+
377+
```python
378+
from web3_google_hsm.accounts.gcp_kms_account import GCPKmsAccount
379+
from web3_google_hsm.config import BaseConfig
380+
import json
381+
382+
# Create config from environment variables
383+
config = BaseConfig(
384+
project_id="your-project-id",
385+
location_id="your-location",
386+
key_ring_id="your-keyring",
387+
key_id="your-key-id"
388+
)
389+
390+
# Load credentials from CI/CD secret
391+
credentials = json.loads(os.environ["GCP_ADC_CREDENTIALS_STRING"])
392+
393+
# Initialize account with both config and credentials
394+
account = GCPKmsAccount(config=config, credentials=credentials)
395+
396+
# or Let the class read the values from env variables
397+
account = GCPKmsAccount(credentials=credentials)
398+
399+
```
400+
401+
### 🔒 GitHub Actions Example
402+
403+
```yaml
404+
name: Deploy with HSM Signing
405+
406+
jobs:
407+
deploy:
408+
runs-on: ubuntu-latest
409+
steps:
410+
- uses: actions/checkout@v2
411+
412+
- name: Set up Python
413+
uses: actions/setup-python@v2
414+
with:
415+
python-version: '3.10'
416+
417+
- name: Install dependencies
418+
run: pip install web3-google-hsm
419+
420+
- name: Sign and Deploy
421+
env:
422+
GOOGLE_CLOUD_PROJECT: ${{ secrets.GCP_PROJECT_ID }}
423+
GOOGLE_CLOUD_REGION: ${{ secrets.GCP_REGION }}
424+
KEY_RING: ${{ secrets.GCP_KEYRING }}
425+
KEY_NAME: ${{ secrets.GCP_KEY_NAME }}
426+
GCP_ADC_CREDENTIALS_STRING: ${{ secrets.GCP_ADC_CREDENTIALS_STRING }}
427+
run: |
428+
python your_deployment_script.py
429+
```
430+
431+
### 📝 Example Deployment Script
432+
```python
433+
import os
434+
import json
435+
from web3_google_hsm.accounts.gcp_kms_account import GCPKmsAccount
436+
from web3_google_hsm.config import BaseConfig
437+
from web3_google_hsm.types.ethereum_types import Transaction
438+
439+
def deploy_contract():
440+
# Initialize with both config and credentials
441+
config = BaseConfig.from_env() # Uses environment variables
442+
credentials = json.loads(os.environ["GCP_ADC_CREDENTIALS_STRING"])
443+
444+
account = GCPKmsAccount(config=config, credentials=credentials)
445+
446+
# Your deployment logic here
447+
print(f"Deploying from address: {account.address}")
448+
449+
# Example transaction
450+
tx = Transaction(
451+
nonce=0,
452+
gas_price=2000000000,
453+
gas_limit=1000000,
454+
to="0x...",
455+
value=0,
456+
data="0x...",
457+
chain_id=1
458+
)
459+
460+
signed_tx = account.sign_transaction(tx)
461+
# Send transaction...
462+
463+
if __name__ == "__main__":
464+
deploy_contract()
465+
```
466+
467+
### 🔑 Required Secrets for CI/CD
468+
469+
Set these secrets in your CI/CD environment:
470+
471+
- `GCP_PROJECT_ID`: Your Google Cloud project ID
472+
- `GCP_REGION`: The region where your KMS resources are located
473+
- `GCP_KEYRING`: The name of your KMS key ring
474+
- `GCP_KEY_NAME`: The name of your KMS key
475+
- `GCP_ADC_CREDENTIALS_STRING`: Your service account credentials JSON as a string
476+
477+
478+
371479

372480
---
373481

tests/integration/accounts/test_gcp_credentials.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"GOOGLE_CLOUD_REGION": os.getenv("GOOGLE_CLOUD_REGION"),
1313
"KEY_RING": os.getenv("KEY_RING"),
1414
"KEY_NAME": os.getenv("KEY_NAME"),
15-
"GCP_CREDENTIALS_STRING": os.getenv("GCP_CREDENTIALS_STRING"),
16-
"GCP_CREDENTIALS_STRING": os.getenv("GCP_CREDENTIALS_STRING"),
15+
"GCP_ADC_CREDENTIALS_STRING": os.getenv("GCP_ADC_CREDENTIALS_STRING"),
16+
"GCP_ADC_CREDENTIALS_STRING": os.getenv("GCP_ADC_CREDENTIALS_STRING"),
1717
}
1818

1919
# Skip all tests if any required env var is missing
@@ -25,8 +25,8 @@
2525

2626
def test_account_initialization_with_both():
2727
"""Test initializing account with both config and credentials."""
28-
# Load credentials from GCP_CREDENTIALS_STRING env var
29-
credentials = json.loads(os.environ["GCP_CREDENTIALS_STRING"])
28+
# Load credentials from GCP_ADC_CREDENTIALS_STRING env var
29+
credentials = json.loads(os.environ["GCP_ADC_CREDENTIALS_STRING"])
3030

3131
# Create config from environment
3232
config = BaseConfig.from_env()
@@ -73,7 +73,7 @@ def test_fail_account_initialization_with_only_config(monkeypatch):
7373
"KEY_RING",
7474
"KEY_NAME",
7575
"GOOGLE_APPLICATION_CREDENTIALS",
76-
"GCP_CREDENTIALS_STRING"
76+
"GCP_ADC_CREDENTIALS_STRING"
7777
]
7878

7979
for env_var in env_vars_to_clear:
@@ -94,15 +94,15 @@ def test_fail_account_initialization_with_only_credentials(monkeypatch):
9494

9595
for env_var in env_vars_to_clear:
9696
monkeypatch.delenv(env_var, raising=False)
97-
credentials = json.loads(os.environ["GCP_CREDENTIALS_STRING"])
97+
credentials = json.loads(os.environ["GCP_ADC_CREDENTIALS_STRING"])
9898

9999
with pytest.raises(ValidationError):
100100
GCPKmsAccount(credentials=credentials)
101101

102102
def test_key_path_matches_config(monkeypatch):
103103
"""Test that the key path matches the config values."""
104104
# Load both config and credentials
105-
credentials = json.loads(os.environ["GCP_CREDENTIALS_STRING"])
105+
credentials = json.loads(os.environ["GCP_ADC_CREDENTIALS_STRING"])
106106

107107
config = BaseConfig.from_env()
108108
account = GCPKmsAccount(config=config, credentials=credentials)

tests/unit/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_fail_generate_missing_required_args(self, runner: CliRunner, monkeypatc
131131
"KEY_RING",
132132
"KEY_NAME",
133133
"GOOGLE_APPLICATION_CREDENTIALS",
134-
"GCP_CREDENTIALS_STRING"
134+
"GCP_ADC_CREDENTIALS_STRING"
135135
]
136136

137137
for env_var in env_vars_to_clear:

0 commit comments

Comments
 (0)