Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7e2fc35

Browse files
authoredFeb 27, 2023
Merge pull request backstage#16519 from JosiahCraw/feature/add-proxy-support-for-techdocs-awsS3
feat: add support for HTTPS proxy for AWS S3 requests in Techdocs
2 parents a12106a + 8b36144 commit 7e2fc35

File tree

9 files changed

+56
-24
lines changed

9 files changed

+56
-24
lines changed
 

‎.changeset/wicked-lions-repeat.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@techdocs/cli': minor
3+
'@backstage/plugin-techdocs-node': minor
4+
---
5+
6+
Added support for an HTTPS proxy for techdocs AWS S3 requests

‎docs/features/techdocs/cli.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,28 @@ Usage: techdocs-cli publish [options]
176176
Publish generated TechDocs site to an external storage AWS S3, Google GCS, etc.
177177
178178
Options:
179-
--publisher-type <TYPE> (Required always) awsS3 | googleGcs | azureBlobStorage
180-
- same as techdocs.publisher.type in Backstage
181-
app-config.yaml
182-
--storage-name <BUCKET/CONTAINER NAME> (Required always) In case of AWS/GCS, use the bucket
183-
name. In case of Azure, use container name. Same as
184-
techdocs.publisher.[TYPE].bucketName
185-
--entity <NAMESPACE/KIND/NAME> (Required always) Entity uid separated by / in
186-
namespace/kind/name order (case-sensitive). Example:
187-
default/Component/myEntity
188-
--legacyUseCaseSensitiveTripletPaths Publishes objects with cased entity triplet prefix when set (e.g. namespace/Kind/name).
189-
Only use if your TechDocs backend is configured the same way
190-
--azureAccountName <AZURE ACCOUNT NAME> (Required for Azure) specify when --publisher-type
191-
azureBlobStorage
192-
--azureAccountKey <AZURE ACCOUNT KEY> Azure Storage Account key to use for authentication.
193-
If not specified, you must set AZURE_TENANT_ID,
194-
AZURE_CLIENT_ID & AZURE_CLIENT_SECRET as environment
195-
variables.
196-
--awsRoleArn <AWS ROLE ARN> Optional AWS ARN of role to be assumed.
197-
--awsEndpoint <AWS ENDPOINT> Optional AWS endpoint to send requests to.
198-
--awsS3ForcePathStyle Optional AWS S3 option to force path style.
199-
--directory <PATH> Path of the directory containing generated files to
200-
publish (default: "./site/")
201-
-h, --help display help for command
179+
--publisher-type <TYPE> (Required always) awsS3 | googleGcs | azureBlobStorage | openStackSwift - same as techdocs.publisher.type in Backstage app-config.yaml
180+
--storage-name <BUCKET/CONTAINER NAME> (Required always) In case of AWS/GCS, use the bucket name. In case of Azure, use container name. Same as
181+
techdocs.publisher.[TYPE].bucketName
182+
--entity <NAMESPACE/KIND/NAME> (Required always) Entity uid separated by / in namespace/kind/name order (case-sensitive). Example: default/Component/myEntity
183+
--legacyUseCaseSensitiveTripletPaths Publishes objects with cased entity triplet prefix when set (e.g. namespace/Kind/name). Only use if your TechDocs backend is configured
184+
the same way. (default: false)
185+
--azureAccountName <AZURE ACCOUNT NAME> (Required for Azure) specify when --publisher-type azureBlobStorage
186+
--azureAccountKey <AZURE ACCOUNT KEY> Azure Storage Account key to use for authentication. If not specified, you must set AZURE_TENANT_ID, AZURE_CLIENT_ID &
187+
AZURE_CLIENT_SECRET as environment variables.
188+
--awsRoleArn <AWS ROLE ARN> Optional AWS ARN of role to be assumed.
189+
--awsEndpoint <AWS ENDPOINT> Optional AWS endpoint to send requests to.
190+
--awsProxy <HTTPS Proxy> Optional Proxy to use for AWS requests.
191+
--awsS3sse <AWS SSE> Optional AWS S3 Server Side Encryption.
192+
--awsS3ForcePathStyle Optional AWS S3 option to force path style.
193+
--awsBucketRootPath <AWS BUCKET ROOT PATH> Optional sub-directory to store files in Amazon S3
194+
--osCredentialId <OPENSTACK SWIFT APPLICATION CREDENTIAL ID> (Required for OpenStack) specify when --publisher-type openStackSwift
195+
--osSecret <OPENSTACK SWIFT APPLICATION CREDENTIAL SECRET> (Required for OpenStack) specify when --publisher-type openStackSwift
196+
--osAuthUrl <OPENSTACK SWIFT AUTHURL> (Required for OpenStack) specify when --publisher-type openStackSwift
197+
--osSwiftUrl <OPENSTACK SWIFT SWIFTURL> (Required for OpenStack) specify when --publisher-type openStackSwift
198+
--gcsBucketRootPath <GCS BUCKET ROOT PATH> Optional sub-directory to store files in Google cloud storage
199+
--directory <PATH> Path of the directory containing generated files to publish (default: "./site/")
200+
-h, --help display help for command
202201
```
203202
204203
### Migrate content for case-insensitive access

‎docs/features/techdocs/configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ techdocs:
136136
# https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html#endpoint
137137
endpoint: ${AWS_ENDPOINT}
138138

139+
# (Optional) HTTPS proxy to use for S3 Requests
140+
# Defaults to using no proxy
141+
# This allows docs to be published and read from behind a proxy
142+
httpsProxy: ${HTTPS_PROXY}
143+
139144
# (Optional) Whether to use path style URLs when communicating with S3.
140145
# Defaults to false.
141146
# This allows providers like LocalStack, Minio and Wasabi (and possibly others) to be used to host tech docs.

‎packages/techdocs-cli/cli-report.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Options:
7777
--azureAccountKey <AZURE ACCOUNT KEY>
7878
--awsRoleArn <AWS ROLE ARN>
7979
--awsEndpoint <AWS ENDPOINT>
80+
--awsProxy <HTTPS Proxy>
8081
--awsS3sse <AWS SSE>
8182
--awsS3ForcePathStyle
8283
--awsBucketRootPath <AWS BUCKET ROOT PATH>

‎packages/techdocs-cli/src/commands/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ export function registerCommands(program: Command) {
173173
'--awsEndpoint <AWS ENDPOINT>',
174174
'Optional AWS endpoint to send requests to.',
175175
)
176+
.option(
177+
'--awsProxy <HTTPS Proxy>',
178+
'Optional Proxy to use for AWS requests.',
179+
)
176180
.option('--awsS3sse <AWS SSE>', 'Optional AWS S3 Server Side Encryption.')
177181
.option(
178182
'--awsS3ForcePathStyle',

‎packages/techdocs-cli/src/lib/PublisherConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export class PublisherConfig {
9494
...(opts.awsEndpoint && { endpoint: opts.awsEndpoint }),
9595
...(opts.awsS3ForcePathStyle && { s3ForcePathStyle: true }),
9696
...(opts.awsS3sse && { sse: opts.awsS3sse }),
97+
...(opts.awsProxy && { httpsProxy: opts.awsProxy }),
9798
},
9899
};
99100
}

‎plugins/techdocs-node/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@aws-sdk/client-s3": "^3.208.0",
4343
"@aws-sdk/credential-providers": "^3.208.0",
4444
"@aws-sdk/lib-storage": "^3.208.0",
45+
"@aws-sdk/node-http-handler": "^3.208.0",
4546
"@aws-sdk/types": "^3.208.0",
4647
"@azure/identity": "^2.1.0",
4748
"@azure/storage-blob": "^12.5.0",
@@ -58,6 +59,7 @@
5859
"express": "^4.17.1",
5960
"fs-extra": "10.1.0",
6061
"git-url-parse": "^13.0.0",
62+
"hpagent": "^1.2.0",
6163
"js-yaml": "^4.0.0",
6264
"json5": "^2.1.3",
6365
"mime-types": "^2.1.27",

‎plugins/techdocs-node/src/stages/publish/awsS3.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ import {
3232
S3Client,
3333
} from '@aws-sdk/client-s3';
3434
import { fromTemporaryCredentials } from '@aws-sdk/credential-providers';
35+
import { NodeHttpHandler } from '@aws-sdk/node-http-handler';
3536
import { Upload } from '@aws-sdk/lib-storage';
3637
import { AwsCredentialIdentityProvider } from '@aws-sdk/types';
38+
import { HttpsProxyAgent } from 'hpagent';
3739
import express from 'express';
3840
import fs from 'fs-extra';
3941
import JSON5 from 'json5';
@@ -150,6 +152,11 @@ export class AwsS3Publish implements PublisherBase {
150152
'techdocs.publisher.awsS3.endpoint',
151153
);
152154

155+
// AWS HTTPS proxy is an optional config. If missing, no proxy is used
156+
const httpsProxy = config.getOptionalString(
157+
'techdocs.publisher.awsS3.httpsProxy',
158+
);
159+
153160
// AWS forcePathStyle is an optional config. If missing, it defaults to false. Needs to be enabled for cases
154161
// where endpoint url points to locally hosted S3 compatible storage like Localstack
155162
const forcePathStyle = config.getOptionalBoolean(
@@ -162,6 +169,11 @@ export class AwsS3Publish implements PublisherBase {
162169
...(region && { region }),
163170
...(endpoint && { endpoint }),
164171
...(forcePathStyle && { forcePathStyle }),
172+
...(httpsProxy && {
173+
requestHandler: new NodeHttpHandler({
174+
httpsAgent: new HttpsProxyAgent({ proxy: httpsProxy }),
175+
}),
176+
}),
165177
});
166178

167179
const legacyPathCasing =

‎yarn.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ __metadata:
12111211
languageName: node
12121212
linkType: hard
12131213

1214-
"@aws-sdk/node-http-handler@npm:3.272.0":
1214+
"@aws-sdk/node-http-handler@npm:3.272.0, @aws-sdk/node-http-handler@npm:^3.208.0":
12151215
version: 3.272.0
12161216
resolution: "@aws-sdk/node-http-handler@npm:3.272.0"
12171217
dependencies:
@@ -8517,6 +8517,7 @@ __metadata:
85178517
"@aws-sdk/client-s3": ^3.208.0
85188518
"@aws-sdk/credential-providers": ^3.208.0
85198519
"@aws-sdk/lib-storage": ^3.208.0
8520+
"@aws-sdk/node-http-handler": ^3.208.0
85208521
"@aws-sdk/types": ^3.208.0
85218522
"@azure/identity": ^2.1.0
85228523
"@azure/storage-blob": ^12.5.0
@@ -8541,6 +8542,7 @@ __metadata:
85418542
express: ^4.17.1
85428543
fs-extra: 10.1.0
85438544
git-url-parse: ^13.0.0
8545+
hpagent: ^1.2.0
85448546
js-yaml: ^4.0.0
85458547
json5: ^2.1.3
85468548
mime-types: ^2.1.27

0 commit comments

Comments
 (0)
Please sign in to comment.