Skip to content

Commit 4af7443

Browse files
committed
Add RBAC on delete twin graph endpoint
1 parent eeb442e commit 4af7443

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

doc/Apis/TwingraphApi.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ All URIs are relative to *https://dev.api.cosmotech.com*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7-
[**delete**](TwingraphApi.md#delete) | **DELETE** /delete/{graphId} |
7+
[**delete**](TwingraphApi.md#delete) | **DELETE** /organizations/{organization_id}/delete/{graphId} |
88
[**importGraph**](TwingraphApi.md#importGraph) | **POST** /organizations/{organization_id}/import |
99
[**query**](TwingraphApi.md#query) | **POST** /organizations/{organization_id}/query |
1010

1111

1212
<a name="delete"></a>
1313
# **delete**
14-
> delete(graphId)
14+
> delete(organization\_id, graphId)
1515
1616

1717

@@ -21,6 +21,7 @@ Method | HTTP request | Description
2121

2222
Name | Type | Description | Notes
2323
------------- | ------------- | ------------- | -------------
24+
**organization\_id** | **String**| the Organization identifier | [default to null]
2425
**graphId** | **String**| the Graph Identifier | [default to null]
2526

2627
### Return type

doc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Class | Method | HTTP request | Description
8888
*SolutionApi* | [**updateSolution**](Apis/SolutionApi.md#updatesolution) | **PATCH** /organizations/{organization_id}/solutions/{solution_id} | Update a solution
8989
*SolutionApi* | [**updateSolutionRunTemplate**](Apis/SolutionApi.md#updatesolutionruntemplate) | **PATCH** /organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id} | Update the specified Solution Run Template
9090
*SolutionApi* | [**uploadRunTemplateHandler**](Apis/SolutionApi.md#uploadruntemplatehandler) | **POST** /organizations/{organization_id}/solutions/{solution_id}/runtemplates/{run_template_id}/handlers/{handler_id}/upload | Upload a Run Template step handler zip file
91-
*TwingraphApi* | [**delete**](Apis/TwingraphApi.md#delete) | **DELETE** /delete/{graphId} | Launch a mass delete job
91+
*TwingraphApi* | [**delete**](Apis/TwingraphApi.md#delete) | **DELETE** /organizations/{organization_id}/delete/{graphId} | Launch a mass delete job
9292
*TwingraphApi* | [**importGraph**](Apis/TwingraphApi.md#importgraph) | **POST** /organizations/{organization_id}/import | Import a new version of a twin graph
9393
*TwingraphApi* | [**query**](Apis/TwingraphApi.md#query) | **POST** /organizations/{organization_id}/query | Run a query on a graph instance
9494
*UserApi* | [**authorizeUser**](Apis/UserApi.md#authorizeuser) | **GET** /oauth2/authorize | Authorize an User with OAuth2. Delegated to configured OAuth2 service

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/ContainerFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ internal class ContainerFactory(
276276

277277
var defaultSizing = BASIC_SIZING
278278

279-
if (nodeLabel != null) {
279+
if (!nodeLabel.isNullOrBlank()) {
280280
defaultSizing = LABEL_SIZING[nodeLabel] ?: BASIC_SIZING
281281
}
282282

@@ -353,7 +353,7 @@ internal class ContainerFactory(
353353

354354
var defaultSizing = BASIC_SIZING
355355

356-
if (nodeLabel != null) {
356+
if (!nodeLabel.isNullOrBlank()) {
357357
defaultSizing = LABEL_SIZING[nodeLabel] ?: BASIC_SIZING
358358
}
359359

twingraph/src/main/kotlin/com/cosmotech/twingraph/api/TwingraphServiceImpl.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ package com.cosmotech.twingraph.api
44

55
import com.cosmotech.api.CsmPhoenixService
66
import com.cosmotech.api.events.TwingraphImportEvent
7+
import com.cosmotech.api.exceptions.CsmResourceNotFoundException
78
import com.cosmotech.api.rbac.CsmRbac
89
import com.cosmotech.api.rbac.PERMISSION_READ
10+
import com.cosmotech.api.utils.objectMapper
911
import com.cosmotech.organization.api.OrganizationApiService
1012
import com.cosmotech.organization.azure.getRbac
11-
import com.cosmotech.api.exceptions.CsmResourceNotFoundException
12-
import com.cosmotech.api.utils.objectMapper
1313
import com.cosmotech.twingraph.domain.TwinGraphImport
1414
import com.cosmotech.twingraph.domain.TwinGraphImportInfo
1515
import com.cosmotech.twingraph.domain.TwinGraphQuery
16-
import org.slf4j.Logger
17-
import org.slf4j.LoggerFactory
1816
import org.springframework.stereotype.Service
1917
import redis.clients.jedis.UnifiedJedis
2018
import redis.clients.jedis.graph.Record
@@ -31,8 +29,6 @@ class TwingraphServiceImpl(
3129
private val csmRbac: CsmRbac
3230
) : CsmPhoenixService(), TwingraphApiService {
3331

34-
val logger: Logger = LoggerFactory.getLogger(TwingraphServiceImpl::class.java)
35-
3632
override fun importGraph(
3733
organizationId: String,
3834
twinGraphImport: TwinGraphImport
@@ -52,8 +48,10 @@ class TwingraphServiceImpl(
5248
logger.debug("TwingraphImportEventResponse={}", graphImportEvent.response)
5349
return TwinGraphImportInfo(jobId = requestJobId, graphName = twinGraphImport.graphName)
5450
}
55-
56-
override fun delete(graphId: String) {
51+
@Suppress("SpreadOperator")
52+
override fun delete(organizationId: String, graphId: String) {
53+
val organization = organizationService.findOrganizationById(organizationId)
54+
csmRbac.verify(organization.getRbac(), PERMISSION_READ)
5755
val matchingKeys = mutableSetOf<String>()
5856
var nextCursor = SCAN_POINTER_START
5957
do {
@@ -62,12 +60,13 @@ class TwingraphServiceImpl(
6260
matchingKeys.addAll(scanResult.result)
6361
} while (!nextCursor.equals(SCAN_POINTER_START))
6462

65-
@Suppress("SpreadOperator") val count = jedis.del(*matchingKeys.toTypedArray())
63+
val count = jedis.del(*matchingKeys.toTypedArray())
6664
logger.debug("$count keys are removed from Twingraph with prefix $graphId")
6765
}
6866

6967
override fun query(organizationId: String, twinGraphQuery: TwinGraphQuery): String {
70-
68+
val organization = organizationService.findOrganizationById(organizationId)
69+
csmRbac.verify(organization.getRbac(), PERMISSION_READ)
7170
if (twinGraphQuery.version.isNullOrEmpty()) {
7271
twinGraphQuery.version = jedis.hget("${twinGraphQuery.graphId}MetaData", "lastVersion")
7372
if (twinGraphQuery.version.isNullOrEmpty()) {

twingraph/src/main/openapi/twingraph.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,14 @@ paths:
7777
application/json:
7878
schema:
7979
type: string
80-
/delete/{graphId}:
80+
/organizations/{organization_id}/delete/{graphId}:
8181
parameters:
82+
- name: organization_id
83+
in: path
84+
description: the Organization identifier
85+
required: true
86+
schema:
87+
type: string
8288
- name: graphId
8389
in: path
8490
description: the Graph Identifier

0 commit comments

Comments
 (0)