Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/support for scw zerodev #273

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
JWT_SECRET_KEY="secret"
NODE_ENV="development"
WEB3_PROVIDER_URI="http://contracts.nevermined.localnet"
ELASTIC_NODE="http://localhost:9200"
ELASTIC_INDEX_NAME_PREFIX="marketplace-index-prefix"
ELASTIC_USERNAME="elastic"
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/postman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- uses: nevermined-io/[email protected]
with:
token: ${{ secrets.API_TOKEN_GITHUB }}
node: 'false'
marketplace: 'false'

- name: Running elasticsearch
run: |
docker run \
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- uses: nevermined-io/[email protected]
with:
token: ${{ secrets.API_TOKEN_GITHUB }}
node: 'false'
marketplace: 'false'

- name: Install dependencies
run: |
yarn
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 4 October 2022

- remove use of dynamic strict in the es mapping [`#93`](https://github.com/nevermined-io/marketplace-api/pull/93)
- Added new _nvm config mapping [`#92`](https://github.com/nevermined-io/marketplace-api/pull/92)
- Added new \_nvm config mapping [`#92`](https://github.com/nevermined-io/marketplace-api/pull/92)
- switch to yarn [`#91`](https://github.com/nevermined-io/marketplace-api/pull/91)
- rename `Nvm` to `NvmConfig` [`9b12183`](https://github.com/nevermined-io/marketplace-api/commit/9b12183e30364061c6b019f174cf6bb11ffd2b14)

Expand Down
1 change: 1 addition & 0 deletions config/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
NODE_ENV: 'staging',
JWT_SECRET_KEY: process.env.JWT_SECRET_KEY,
JWT_EXPIRY_KEY: process.env.JWT_EXPIRY_KEY,
WEB3_PROVIDER_URI: process.env.WEB3_PROVIDER_URI,
server: {
port: process.env.PORT || 3100,
},
Expand Down
1 change: 1 addition & 0 deletions config/local.js.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
NODE_ENV: process.env.NODE_ENV,
JWT_SECRET_KEY: 'secret',
JWT_EXPIRY_KEY: '60m',
WEB3_PROVIDER_URI: 'http://contracts.nevermined.localnet',
server: {
port: 3100,
},
Expand Down
1 change: 1 addition & 0 deletions config/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
NODE_ENV: 'production',
JWT_SECRET_KEY: process.env.JWT_SECRET_KEY,
JWT_EXPIRY_KEY: process.env.JWT_EXPIRY_KEY,
WEB3_PROVIDER_URI: process.env.WEB3_PROVIDER_URI,
API_VERSION: process.env.API_VERSION,
server: {
port: process.env.PORT || 3100,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@nestjs/platform-express": "^10.1.3",
"@nestjs/swagger": "^7.0.0",
"@nestjs/typeorm": "^10.0.0",
"@nevermined-io/passport-nevermined": "^0.2.0",
"@nevermined-io/passport-nevermined": "^0.3.0",
"@sideway/address": "^5.0.0",
"@sideway/formula": "^3.0.1",
"@sideway/pinpoint": "^2.0.0",
Expand Down
5 changes: 2 additions & 3 deletions src/assets/asset.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,8 @@ export class AssetController {
async getDDOMetadata(@Param('did') did: string): Promise<AttributesDto> {
const assetSource = await this.assetService.findOneById(did)

const metada = GetAssetDto.fromSource(assetSource).service?.find(
(s) => s.attributes,
)?.attributes
const metada = GetAssetDto.fromSource(assetSource).service?.find((s) => s.attributes)
?.attributes

if (!metada) {
throw new NotFoundException(`Asset with did ${did} doesn't have metada`)
Expand Down
13 changes: 9 additions & 4 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { Permission } from '../permissions/permission.entity'
import { JWTPayload, Strategy } from '@nevermined-io/passport-nevermined'
import { Request } from 'express'
import { JwtPayload } from 'jsonwebtoken'
import { ConfigService } from '../shared/config/config.service'

@Injectable()
export class AuthService {
constructor(
private jwtService: JwtService,
private userProfileService: UserProfileService,
private permissionService: PermissionService,
private configService: ConfigService,
) {}

/**
Expand Down Expand Up @@ -67,12 +69,15 @@ export class AuthService {
userId: string,
): Promise<LoginDto> {
let payload: JwtPayload
const strategy = new Strategy((result: JWTPayload) => {
payload = result
}, undefined)
const strategy = new Strategy(
{ web3ProviderUri: this.configService.get('WEB3_PROVIDER_URI') },
(result: JWTPayload) => {
payload = result
},
)

try {
strategy.authenticate({ body: clientAssertionDto } as Request)
await strategy.authenticate({ body: clientAssertionDto } as Request)
} catch (error) {
throw new UnauthorizedException(
`The 'client_assertion' is invalid: ${(error as Error).message}`,
Expand Down
7 changes: 7 additions & 0 deletions src/auth/nvm.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { Strategy, JWTPayload } from '@nevermined-io/passport-nevermined'
import { ConfigService } from '../shared/config/config.service'

@Injectable()
export class NeverminedStrategy extends PassportStrategy(Strategy) {
constructor(configService: ConfigService) {
super({
web3ProviderUri: configService.get('WEB3_PROVIDER_URI'),
})
}

async validate(payload: JWTPayload): Promise<JWTPayload> {
return payload
}
Expand Down
2 changes: 2 additions & 0 deletions src/shared/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const DOTENV_SCHEMA = Joi.object({
.default('development'),
JWT_SECRET_KEY: Joi.string().required().error(new Error('JWT_SECRET_KEY is required!')),
JWT_EXPIRY_KEY: Joi.string().default('60m'),
WEB3_PROVIDER_URI: Joi.string().required().error(new Error('WEB3_PROVIDER_URI is required!')),
server: Joi.object({
port: Joi.number().default(3000),
}),
Expand Down Expand Up @@ -47,6 +48,7 @@ type DotenvSchemaKeys =
| 'database.url'
| 'JWT_SECRET_KEY'
| 'JWT_EXPIRY_KEY'
| 'WEB3_PROVIDER_URI'
| 'security.enableHttpsRedirect'
| 'elasticsearch.node'
| 'elasticsearch.prefix'
Expand Down
Loading