Added apikey config for StackOverflow backend
Signed-off-by: Matt Mulligan <mmulligan03@gmail.com>
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# @backstage/plugin-stack-overflow-backend
|
||||
|
||||
## 0.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Added apiKey configuration to prevent encoding the key value
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -15,6 +15,16 @@ stackoverflow:
|
||||
baseUrl: https://api.stackexchange.com/2.2 # alternative: your internal stack overflow instance
|
||||
```
|
||||
|
||||
### Stack Overflow for Teams (private stack overflow instance)
|
||||
|
||||
If you have a private stack overflow instance you will need to supply an API key as well. You can read more about how to set this up by going to [Stack Overflows Help Page](https://stackoverflow.help/en/articles/4385859-stack-overflow-for-teams-api)
|
||||
|
||||
```yaml
|
||||
stackoverflow:
|
||||
baseUrl: https://api.stackexchange.com/2.2 # alternative: your internal stack overflow instance
|
||||
apiKey: $STACK_OVERFLOW_API_KEY
|
||||
```
|
||||
|
||||
## Areas of Responsibility
|
||||
|
||||
This stack overflow backend plugin is primarily responsible for the following:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@backstage/plugin-stack-overflow-backend",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
|
||||
@@ -52,6 +52,7 @@ export type StackOverflowQuestionsCollatorFactoryOptions = {
|
||||
baseUrl?: string;
|
||||
requestParams: StackOverflowQuestionsRequestParams;
|
||||
logger: Logger;
|
||||
config: Config;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,12 +66,14 @@ export class StackOverflowQuestionsCollatorFactory
|
||||
protected requestParams: StackOverflowQuestionsRequestParams;
|
||||
private readonly baseUrl: string | undefined;
|
||||
private readonly logger: Logger;
|
||||
private readonly config: Config;
|
||||
public readonly type: string = 'stack-overflow';
|
||||
|
||||
private constructor(options: StackOverflowQuestionsCollatorFactoryOptions) {
|
||||
this.baseUrl = options.baseUrl;
|
||||
this.requestParams = options.requestParams;
|
||||
this.logger = options.logger;
|
||||
this.config = options.config;
|
||||
}
|
||||
|
||||
static fromConfig(
|
||||
@@ -80,7 +83,11 @@ export class StackOverflowQuestionsCollatorFactory
|
||||
const baseUrl =
|
||||
config.getOptionalString('stackoverflow.baseUrl') ||
|
||||
'https://api.stackexchange.com/2.2';
|
||||
return new StackOverflowQuestionsCollatorFactory({ ...options, baseUrl });
|
||||
return new StackOverflowQuestionsCollatorFactory({
|
||||
...options,
|
||||
baseUrl,
|
||||
config,
|
||||
});
|
||||
}
|
||||
|
||||
async getCollator() {
|
||||
@@ -93,12 +100,16 @@ export class StackOverflowQuestionsCollatorFactory
|
||||
`No stackoverflow.baseUrl configured in your app-config.yaml`,
|
||||
);
|
||||
}
|
||||
|
||||
const params = qs.stringify(this.requestParams, {
|
||||
arrayFormat: 'comma',
|
||||
addQueryPrefix: true,
|
||||
});
|
||||
|
||||
const res = await fetch(`${this.baseUrl}/questions${params}`);
|
||||
const apiKey = this.config.getOptionalString('stackoverflow.apiKey');
|
||||
const apiKeyParam = apiKey ? `${params ? '&' : '?'}key=${apiKey}` : '';
|
||||
|
||||
const res = await fetch(`${this.baseUrl}/questions${params}${apiKeyParam}`);
|
||||
const data = await res.json();
|
||||
|
||||
for (const question of data.items) {
|
||||
|
||||
Reference in New Issue
Block a user