Skip to content

Commit

Permalink
Add CanCreateRepositoryAttribute (#362)
Browse files Browse the repository at this point in the history
* chore: bump runtime

* chore: bump backbone version

* feat: add CanCreateRepositoryAttribute

* fix: add CanCreateRepositoryAttributeResponse to openapi

* chore: add changes from backbone bump
  • Loading branch information
Milena-Czierlinski authored Feb 4, 2025
1 parent 74cdb7f commit 545f1e4
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .dev/appsettings.override.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
}
},
"Application": {
"didDomainName": "localhost"
"didDomainName": "localhost",
"maxNumberOfMessageRecipients": 5
}
},
"Files": {
Expand Down
2 changes: 1 addition & 1 deletion .dev/compose.backbone.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BACKBONE_VERSION=6.28.0
BACKBONE_VERSION=6.30.0
2 changes: 1 addition & 1 deletion .dev/compose.backbone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ services:
rabbitmq:
container_name: bkb-rabbitmq
hostname: rabbitmq
image: rabbitmq:3.12.10-management-alpine
image: rabbitmq:4.0.5-alpine

### seeds ###

Expand Down
66 changes: 30 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@js-soft/docdb-access-mongo": "1.2.0",
"@js-soft/node-logger": "1.2.0",
"@js-soft/ts-utils": "^2.3.3",
"@nmshd/runtime": "6.23.1",
"@nmshd/runtime": "6.24.2",
"@nmshd/typescript-ioc": "^3.2.4",
"@nmshd/typescript-rest": "^3.1.0",
"agentkeepalive": "4.6.0",
Expand Down Expand Up @@ -113,8 +113,8 @@
"@js-soft/eslint-config-ts": "1.6.13",
"@js-soft/license-check": "1.0.9",
"@nmshd/connector-sdk": "*",
"@nmshd/content": "6.23.1",
"@nmshd/core-types": "6.23.1",
"@nmshd/content": "6.24.2",
"@nmshd/core-types": "6.24.2",
"@nmshd/typescript-rest-swagger": "^1.4.1",
"@types/amqplib": "^0.10.6",
"@types/compression": "^1.7.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build:schemas:watch": "npx nodemon -e ts -w 'src/types' --exec 'npm run build:schemas'"
},
"dependencies": {
"@nmshd/content": "6.23.1",
"@nmshd/content": "6.24.2",
"axios": "^1.7.9",
"form-data": "^4.0.1",
"qs": "^6.14.0"
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/src/endpoints/AttributesEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
CanCreateRepositoryAttributeRequest,
CanCreateRepositoryAttributeResponse,
ConnectorAttribute,
ConnectorAttributeTagCollection,
ConnectorAttributes,
Expand All @@ -25,6 +27,10 @@ import {
import { Endpoint } from "./Endpoint";

export class AttributesEndpoint extends Endpoint {
public async canCreateRepositoryAttribute(request: CanCreateRepositoryAttributeRequest): Promise<ConnectorHttpResponse<CanCreateRepositoryAttributeResponse>> {
return await this.put("/api/v2/Attributes/CanCreate", request);
}

public async createRepositoryAttribute(request: CreateRepositoryAttributeRequest): Promise<ConnectorHttpResponse<ConnectorAttribute>> {
return await this.post("/api/v2/Attributes", request);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/types/attributes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export * from "./ConnectorAttributeTagCollection";
export * from "./IdentityAttributeQuery";
export * from "./IQLQuery";
export * from "./RelationshipAttributeQuery";
export * from "./requests/CanCreateRepositoryAttributeRequest";
export * from "./requests/CanCreateRepositoryAttributeResponse";
export * from "./requests/CreateRepositoryAttributeRequest";
export * from "./requests/DeleteOwnSharedAttributeAndNotifyPeerResponse";
export * from "./requests/DeletePeerSharedAttributeAndNotifyOwnerResponse";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AttributeValues } from "@nmshd/content";

export interface CanCreateRepositoryAttributeRequest {
content: {
value: AttributeValues.Identity.Json;
tags?: string[];
validFrom?: string;
validTo?: string;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type CanCreateRepositoryAttributeResponse =
| { isSuccess: true }
| {
isSuccess: false;
code: string;
message: string;
};
10 changes: 9 additions & 1 deletion src/modules/coreHttpApi/controllers/AttributesController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConsumptionServices, RuntimeErrors, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, DELETE, GET, POST, Path, PathParam, QueryParam, Return, ServiceContext } from "@nmshd/typescript-rest";
import { Accept, Context, DELETE, GET, POST, PUT, Path, PathParam, QueryParam, Return, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand All @@ -13,6 +13,14 @@ export class AttributesController extends BaseController {
super();
}

@PUT
@Path("CanCreate")
@Accept("application/json")
public async canCreateRepositoryAttribute(request: any): Promise<Envelope> {
const result = await this.consumptionServices.attributes.canCreateRepositoryAttribute(request);
return this.ok(result);
}

@POST
@Accept("application/json")
public async createRepositoryAttribute(request: any): Promise<Return.NewResource<Envelope>> {
Expand Down
77 changes: 77 additions & 0 deletions src/modules/coreHttpApi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,57 @@ paths:

# ------------------- Attributes -------------------

/api/v2/Attributes/CanCreate:
put:
operationId: canCreateRepositoryAttribute
description: "Checks if a Repository Attribute can be created with the given parameters."
tags:
- Attributes
requestBody:
content:
application/json:
schema:
additionalProperties: false
properties:
content:
type: object
additionalProperties: false
required:
- value
properties:
value:
$ref: "#/components/schemas/AttributeValue"
tags:
$ref: "#/components/schemas/IdentityAttributeContent_tags"
validFrom:
$ref: "#/components/schemas/AttributeContent_validFrom"
validTo:
$ref: "#/components/schemas/AttributeContent_validTo"
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
result:
nullable: false
$ref: "#/components/schemas/CanCreateRepositoryAttributeResponse"
required:
- result
headers:
X-Response-Duration-ms:
schema:
$ref: "#/components/schemas/HeaderContent_X-Response-Duration-ms"
X-Response-Time:
schema:
$ref: "#/components/schemas/HeaderContent_X-Response-Time"
401:
$ref: "#/components/responses/Unauthorized"
403:
$ref: "#/components/responses/Forbidden"

/api/v2/Attributes:
post:
operationId: createRepositoryAttribute
Expand Down Expand Up @@ -5049,6 +5100,32 @@ components:
required:
- displayNames

CanCreateRepositoryAttributeResponse:
type: object
properties:
isSuccess:
type: boolean
oneOf:
- properties:
isSuccess:
const: true
required:
- isSuccess
additionalProperties: false

- properties:
isSuccess:
const: false
code:
type: string
message:
type: string
required:
- isSuccess
- code
- message
additionalProperties: false

ConnectorHealth:
type: object
properties:
Expand Down
14 changes: 14 additions & 0 deletions test/attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ beforeEach(async () => {
});

describe("Attributes", () => {
test("should check if a repository attribute can be created", async () => {
const canCreateAttributeResponse = await client1.attributes.canCreateRepositoryAttribute({
content: {
value: {
"@type": "GivenName",
value: "AGivenName"
},
tags: ["content:edu.de"]
}
});

expect(canCreateAttributeResponse.result.isSuccess).toBe(true);
});

test("should create a repository attribute", async () => {
const createAttributeResponse = await client1.attributes.createRepositoryAttribute({
content: {
Expand Down

0 comments on commit 545f1e4

Please sign in to comment.