-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge stage prior to release v1.1.0 (#145)
* Feature/IOT_16_MulticastBackend (#132) * Made CRUD operationer for multicast. Tested with frontend. * Made CRUD for multicast in backend plus connection to chirpStack. * Changed chirpstack applicationID since there will always only be one. * Split multicast in two entities so it's easier to expand later. Made a new entity called lorawanMulticastDefinition which will contain the informations about a lorawan multicast * made functionality so devices now will be added to chirpstack if they are a lorawan device. Also made the update functionality, so a device will be removed if it's not a part of the new multicast * Send message. Possible to get current message queue and to overwrite it * Made validation for service profile. Devices should only be added to multicast if they alle have same service profile. * PR changes * PR changes - fixed pagination for multicast * PR Changes * PR Changes * Pr changes Co-authored-by: August Andersen <[email protected]> * Db migrations (#133) * Made migrations. Now it's nessesary to add migrations when changes are made in db. The command - npm run typeorm migration:generate -- -n <migrationName> - will generate a migration file if changes are made compared to the db. When you launch the app, a migration:run command will be called. This will apply the newly migration. If you want to revert a migration, npm run typeorm migration:revert can be called. It will revert the latest migration. If you are in doubt which migrations has been called or not, you can write npm run typeorm migration:show. This will show you the pending/fulfilled migrations. * Since migrations are made in prestart, no need to check on dist. * PR Changes * PR changes Co-authored-by: August Andersen <[email protected]> * Migrations changes in ormconfig file to make migrations possible in test environment * Initial migration (#134) * Initial migration * Fix proper linting ignore of migrations * Changed ormconfig.ts to .js so dist folder is created correctly. Minor changes in package.json. Removed multicast from initialmigration and made a seperate migration with multicast. Co-authored-by: augusthjerrild <[email protected]> * Feature/1220 api key (#136) * Init api key auth with hardcoded keys * Added TODOs. Throw 401 if api key is invalid * Fix roles metadata not set on class controller * Fetch api keys and sort. Prepare for create and update * Api key fetch and create done * Cleanup api key flow. Remove update flow for now * Validate api key access * Works - typeerror when building * Fixed circular dependency error * Added API guard to relevant controllers * Fix indentation. Delete unused auth api key request Co-authored-by: Aram Al-Sabti <[email protected]> Co-authored-by: nlg <[email protected]> * Fix roles in controllers where it was set on the whole class (#139) * Edit API keys (#138) * Add option for editing API key * Fix API keys with admin not having write access * Edit API key PR * Clean up API key * CVE-2019-18413. Patch for potential SQL injections (#137) * CVE-2019-18413. Patch for potential SQL injections * Fix request 400 on get applications by permission * Spell organization with British English ("z") * Simplified migration names * Optimize chirpstack calls when fetching devices (#143) * FIWARE datatarget (#141) * Fiware DataTarget Support * Migration for Fiware Datatarget * Fixing incorrect log message * PR Fixes * Optimize bulk import and the load on chirpstack (#140) * Adjust eslint * Modify bulk import create to take batches. Update missing * Remove restriction on devices belonging to the same application * Optimize chirpstack calls. Init updatemany endpoint. * Implement updateMany and cleanup * Fix device model not set. Cleanup code. Add comments * Refactor iot device helpers * Make device model error code more specific * Added comment every time invalid devices are filtered * Fixed issue when creating new IoT device with no device model * Fixed Fiware datatarget headers declarations and corresponding unit tests (#144) Co-authored-by: August Andersen <[email protected]> Co-authored-by: Aram Al-Sabti <[email protected]> Co-authored-by: nlg <[email protected]> Co-authored-by: Bartek <[email protected]>
- Loading branch information
1 parent
ba70c7f
commit 12485b4
Showing
122 changed files
with
3,506 additions
and
389 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 |
---|---|---|
|
@@ -4,3 +4,5 @@ node_modules | |
dist | ||
# don't lint nyc coverage output | ||
coverage | ||
src/migration/ | ||
.eslintrc.js |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
"type": "postgres", | ||
"host": process.env.DATABASE_HOSTNAME || "host.docker.internal", | ||
"port": parseInt(process.env.DATABASE_PORT, 10) || 5433, | ||
"username": process.env.DATABASE_USERNAME || "os2iot", | ||
"password": process.env.DATABASE_PASSWORD || "toi2so", | ||
"database": "os2iot", | ||
"synchronize": false, | ||
"logging": false, | ||
"entities": ["src/entities/*.ts"], | ||
"migrations": ["src/migration/*.ts"], | ||
"cli": { | ||
"migrationsDir": "src/migration" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { AuthGuard } from "@nestjs/passport"; | ||
import { ApiKeyStrategyName } from "./constants"; | ||
|
||
@Injectable() | ||
export class ApiKeyAuthGuard extends AuthGuard(ApiKeyStrategyName) {} |
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,56 @@ | ||
import { AuthenticatedUser } from "@dto/internal/authenticated-user"; | ||
import { ErrorCodes } from "@enum/error-codes.enum"; | ||
import { Injectable, UnauthorizedException } from "@nestjs/common"; | ||
import { PassportStrategy } from "@nestjs/passport"; | ||
import { AuthService } from "@services/user-management/auth.service"; | ||
import { PermissionService } from "@services/user-management/permission.service"; | ||
import { HeaderAPIKeyStrategy } from "passport-headerapikey"; | ||
import { ApiKeyHeader, ApiKeyStrategyName, HeaderApiVerifiedCallback } from "./constants"; | ||
|
||
const passReqToCallback = false; | ||
|
||
@Injectable() | ||
export class ApiKeyStrategy extends PassportStrategy( | ||
HeaderAPIKeyStrategy, | ||
ApiKeyStrategyName | ||
) { | ||
constructor( | ||
private authService: AuthService, | ||
private permissionService: PermissionService | ||
) { | ||
super( | ||
{ | ||
header: ApiKeyHeader, | ||
prefix: "", | ||
}, | ||
passReqToCallback | ||
); | ||
} | ||
|
||
async validate( | ||
apiKey: string, | ||
_done: HeaderApiVerifiedCallback | ||
): Promise<AuthenticatedUser> { | ||
const apiKeyDb = await this.authService.validateApiKey(apiKey); | ||
if (!apiKeyDb) { | ||
throw new UnauthorizedException(ErrorCodes.ApiKeyAuthFailed); | ||
} | ||
|
||
// Get the permissions and the UserID from the API Key instead of the user | ||
const permissions = await this.permissionService.findPermissionGroupedByLevelForApiKey( | ||
apiKeyDb.id | ||
); | ||
|
||
// const permissions = dbApiKey.permissions as Permission[]; | ||
const userId = apiKeyDb.systemUser.id; | ||
|
||
// Set the permissions and the userId on the returned user | ||
const user: AuthenticatedUser = { | ||
userId, | ||
username: apiKeyDb.systemUser.name, | ||
permissions, | ||
}; | ||
|
||
return user; | ||
} | ||
} |
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,11 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { AuthGuard } from "@nestjs/passport"; | ||
import { ApiKeyStrategyName, JwtStrategyName } from "./constants"; | ||
|
||
@Injectable() | ||
/** | ||
* Let authentication go through a chain of strategies. The first to succeed, redirect, or error will halt the chain | ||
* If a strategy fails (not errors! Ex. JWT token wasn't valid), then authentication proceeds to the next strategy. | ||
* Source: https://docs.nestjs.com/security/authentication#extending-guards | ||
*/ | ||
export class ComposeAuthGuard extends AuthGuard([JwtStrategyName, ApiKeyStrategyName]) {} |
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,13 @@ | ||
import { AuthenticatedUser } from "@dto/internal/authenticated-user"; | ||
|
||
export type HeaderApiVerifiedCallback = ( | ||
err: Error | null, | ||
user?: AuthenticatedUser, | ||
info?: Record<string, unknown> | ||
) => void; | ||
|
||
export const ApiKeyStrategyName = "api-key"; | ||
export const ApiKeyHeader = "X-API-KEY"; | ||
export const LocalStrategyName = "local"; | ||
export const JwtStrategyName = "jwt"; | ||
export const RolesMetaData = "roles"; |
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,5 +1,6 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { AuthGuard } from "@nestjs/passport"; | ||
import { JwtStrategyName } from "./constants"; | ||
|
||
@Injectable() | ||
export class JwtAuthGuard extends AuthGuard("jwt") {} | ||
export class JwtAuthGuard extends AuthGuard(JwtStrategyName) {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { AuthGuard } from "@nestjs/passport"; | ||
import { LocalStrategyName } from "./constants"; | ||
|
||
@Injectable() | ||
export class LocalAuthGuard extends AuthGuard("local") {} | ||
export class LocalAuthGuard extends AuthGuard(LocalStrategyName) {} |
Oops, something went wrong.