-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from mitre-attack/develop
Fix Discovery and Get API root Information endpoints
- Loading branch information
Showing
8 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ CERTBOT_LE_RSA_KEY_SIZE=4096 | |
# ********************************************************** | ||
# ***** CONTACT INFORMATION ******************************** | ||
# ********************************************************** | ||
TAXII_API_ROOT_PATH=api | ||
TAXII_API_ROOT_PATH=/api | ||
TAXII_API_ROOT_TITLE=ATT&CK Workbench TAXII 2.1 Server | ||
TAXII_API_ROOT_DESCRIPTION=Provides access to the latest version of ATT&CK data through a TAXII 2.1 compliant REST API | ||
TAXII_CONTACT=[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
@Injectable() | ||
export class SnakeCaseInterceptor implements NestInterceptor { | ||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { | ||
return next.handle().pipe( | ||
map(data => this.transform(data)) | ||
); | ||
} | ||
|
||
private transform(data: any) { | ||
if (Array.isArray(data)) { | ||
return data.map(item => this.transformToSnakeCase(item)); | ||
} | ||
return this.transformToSnakeCase(data); | ||
} | ||
|
||
private transformToSnakeCase(data: any) { | ||
if (typeof data !== 'object' || data === null) { | ||
return data; | ||
} | ||
|
||
const snakeCaseData = {}; | ||
for (const key in data) { | ||
if (Object.prototype.hasOwnProperty.call(data, key)) { | ||
const snakeKey = key.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`); | ||
snakeCaseData[snakeKey] = this.transform(data[key]); | ||
} | ||
} | ||
return snakeCaseData; | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
src/common/middleware/content-negotiation/supported-media-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
export enum SupportedMediaTypes { | ||
"application" = "application", | ||
Application = "application", | ||
} | ||
|
||
export enum SupportedMediaSubTypes { | ||
"taxii+json" = "taxii+json", | ||
TaxiiJson = "taxii+json", | ||
} | ||
|
||
export enum SupportedMediaVersion { | ||
V21 = "2.1", | ||
LATEST = "2.1", | ||
} | ||
|
||
export const DEFAULT_CONTENT_TYPE = `${SupportedMediaTypes.Application}/${SupportedMediaSubTypes.TaxiiJson};version=${SupportedMediaVersion.LATEST}` as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters