Skip to content

Commit 2f4f2aa

Browse files
committed
fix: improve structure
1 parent acd62ee commit 2f4f2aa

File tree

1 file changed

+80
-41
lines changed

1 file changed

+80
-41
lines changed

README.md

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ More examples on other services, configuration and authentication possibilities
9999

100100
## Authentication
101101

102-
To authenticate with the SDK, you need a [service account](https://docs.stackit.cloud/stackit/en/service-accounts-134415819.html) with appropriate permissions (e.g., `project.owner`). This service account can for example be created in the Portal, please check the documentation for further details.
102+
To authenticate with the SDK, you need a [service account](https://docs.stackit.cloud/stackit/en/service-accounts-134415819.html) with appropriate permissions (e.g., `project.owner`). You can create a service account through the STACKIT Portal.
103103

104104
### Authentication Methods
105105

@@ -115,69 +115,108 @@ The SDK supports two authentication methods:
115115
- Uses long-lived service account tokens
116116
- Simpler but less secure
117117

118-
### Configuration Options
118+
### Configuration Priority
119+
120+
The SDK searches for credentials in the following order:
121+
122+
1. Explicit configuration in code
123+
2. Environment variables
124+
3. Credentials file (`$HOME/.stackit/credentials.json`)
125+
126+
For each authentication method, the key flow is attempted first, followed by the token flow.
127+
128+
### Using the Key Flow
119129

120-
You can configure authentication using any of these methods:
130+
1. Create a service account key in the STACKIT Portal:
121131

122-
1. **Explicit Configuration in Code**
132+
- Navigate to `Service Accounts` → Select account → `Service Account Keys` → Create key
133+
- You can either let STACKIT generate the key pair or provide your own RSA key pair
134+
135+
2. Save the service account key JSON:
136+
137+
```json
138+
{
139+
"id": "uuid",
140+
"publicKey": "public key",
141+
"credentials": {
142+
"kid": "string",
143+
144+
"sub": "uuid",
145+
"aud": "string",
146+
"privateKey": "private key (if STACKIT-generated)"
147+
}
148+
// ... other fields ...
149+
}
150+
```
151+
152+
3. Configure authentication using any of these methods:
153+
154+
**A. Code Configuration**
123155

124156
```go
157+
// Using service account key file
125158
config.WithServiceAccountKeyPath("path/to/sa_key.json")
126-
config.WithToken("your-token")
159+
// Or using key content directly
160+
config.WithServiceAccountKey(keyJSON)
161+
162+
// Optional: For custom key pairs
163+
config.WithPrivateKeyPath("path/to/private.pem")
164+
// Or using private key content directly
165+
config.WithPrivateKey(privateKeyJSON)
127166
```
128167

129-
2. **Environment Variables**
168+
**B. Environment Variables**
130169

131170
```bash
171+
# Using service account key
132172
STACKIT_SERVICE_ACCOUNT_KEY_PATH=/path/to/sa_key.json
133-
STACKIT_SERVICE_ACCOUNT_TOKEN=your-token
173+
# or
174+
STACKIT_SERVICE_ACCOUNT_KEY=<sa-key-content>
175+
176+
# Optional: For custom key pairs
177+
STACKIT_PRIVATE_KEY_PATH=/path/to/private.pem
178+
# or
179+
STACKIT_PRIVATE_KEY=<private-key-content>
134180
```
135181

136-
3. **Credentials File**
137-
- Default location: `$HOME/.stackit/credentials.json`
138-
- Custom location: Set via `STACKIT_CREDENTIALS_PATH`
139-
- Format:
140-
```json
141-
{
142-
"STACKIT_SERVICE_ACCOUNT_KEY_PATH": "path/to/sa_key.json",
143-
"STACKIT_SERVICE_ACCOUNT_TOKEN": "your-token"
144-
}
145-
```
182+
**C. Credentials File** (`$HOME/.stackit/credentials.json`)
146183

147-
### Configuration Reference
184+
```json
185+
{
186+
"STACKIT_SERVICE_ACCOUNT_KEY_PATH": "/path/to/sa_key.json",
187+
"STACKIT_PRIVATE_KEY_PATH": "/path/to/private.pem"
188+
}
189+
```
148190

149-
1. **Explicit Configuration**
191+
### Using the Token Flow
150192

151-
- `config.WithServiceAccountKey(string)` - Set the service account key JSON directly
152-
- `config.WithServiceAccountKeyPath(string)` - Set the path to the service account key JSON file
153-
- `config.WithPrivateKey(string)` - Set the service account private key directly (for custom key pairs)
154-
- `config.WithPrivateKeyPath(string)` - Set the path to the service account private key file
155-
- `config.WithToken(string)` - Set the service account access token directly
193+
1. Create an access token in the STACKIT Portal:
156194

157-
2. **Environment Variables**
195+
- Navigate to `Service Accounts` → Select account → `Access Tokens` → Create token
158196

159-
- `STACKIT_SERVICE_ACCOUNT_KEY` - Service account key JSON as string
160-
- `STACKIT_SERVICE_ACCOUNT_KEY_PATH` - Path to service account key JSON file
161-
- `STACKIT_PRIVATE_KEY` - Service account private key as string
162-
- `STACKIT_PRIVATE_KEY_PATH` - Path to service account private key file
163-
- `STACKIT_SERVICE_ACCOUNT_TOKEN` - Service account access token
164-
- `STACKIT_CREDENTIALS_PATH` - Custom path to credentials file
197+
2. Configure authentication using any of these methods:
165198

166-
3. **Credentials File**
167-
- JSON file containing any of the above environment variable names as keys
168-
- Default location: `$HOME/.stackit/credentials.json`
199+
**A. Code Configuration**
169200

170-
### Configuration Priority
201+
```go
202+
config.WithToken("your-token")
203+
```
171204

172-
The SDK searches for credentials in the following order:
205+
**B. Environment Variables**
173206

174-
1. Explicit configuration in code
175-
2. Environment variables
176-
3. Credentials file
207+
```bash
208+
STACKIT_SERVICE_ACCOUNT_TOKEN=your-token
209+
```
177210

178-
For each authentication method, the key flow is attempted first, followed by the token flow.
211+
**C. Credentials File** (`$HOME/.stackit/credentials.json`)
212+
213+
```json
214+
{
215+
"STACKIT_SERVICE_ACCOUNT_TOKEN": "your-token"
216+
}
217+
```
179218

180-
Check the [authentication example](examples/authentication/authentication.go) for implementation details.
219+
For detailed implementation examples, see the [authentication example](examples/authentication/authentication.go).
181220

182221
## Reporting issues
183222

0 commit comments

Comments
 (0)