working version with HsHostingAsset + type
This commit is contained in:
parent
fc8cf0a0b7
commit
d2ba55701c
@ -1,11 +1,11 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.api.HsHostingServersApi;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.api.HsHostingAssetsApi;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsServerInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsServerPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsServerResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetResource;
|
||||
import net.hostsharing.hsadminng.mapper.KeyValueMap;
|
||||
import net.hostsharing.hsadminng.mapper.Mapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -18,8 +18,9 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
|
||||
@RestController
|
||||
public class HsHostingAssetController implements HsHostingServersApi {
|
||||
public class HsHostingAssetController implements HsHostingAssetsApi {
|
||||
|
||||
@Autowired
|
||||
private Context context;
|
||||
@ -28,70 +29,70 @@ public class HsHostingAssetController implements HsHostingServersApi {
|
||||
private Mapper mapper;
|
||||
|
||||
@Autowired
|
||||
private HsHostingAssetRepository serverRepo;
|
||||
private HsHostingAssetRepository assetRepo;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<List<HsServerResource>> listServersByDebitorUuid(
|
||||
public ResponseEntity<List<HsHostingAssetResource>> listAssetsByDebitorUuid(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID debitorUuid) {
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var entities = serverRepo.findAllByDebitorUuid(debitorUuid);
|
||||
final var entities = assetRepo.findAllByDebitorUuid(debitorUuid);
|
||||
|
||||
final var resources = mapper.mapList(entities, HsServerResource.class);
|
||||
final var resources = mapper.mapList(entities, HsHostingAssetResource.class);
|
||||
return ResponseEntity.ok(resources);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<HsServerResource> addServer(
|
||||
public ResponseEntity<HsHostingAssetResource> addAsset(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final HsServerInsertResource body) {
|
||||
final HsHostingAssetInsertResource body) {
|
||||
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var entityToSave = mapper.map(body, HsHostingAssetEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER);
|
||||
|
||||
final var saved = serverRepo.save(entityToSave);
|
||||
final var saved = assetRepo.save(entityToSave);
|
||||
|
||||
final var uri =
|
||||
MvcUriComponentsBuilder.fromController(getClass())
|
||||
.path("/api/hs/hosting/servers/{id}")
|
||||
.path("/api/hs/hosting/assets/{id}")
|
||||
.buildAndExpand(saved.getUuid())
|
||||
.toUri();
|
||||
final var mapped = mapper.map(saved, HsServerResource.class);
|
||||
final var mapped = mapper.map(saved, HsHostingAssetResource.class);
|
||||
return ResponseEntity.created(uri).body(mapped);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<HsServerResource> getServerByUuid(
|
||||
public ResponseEntity<HsHostingAssetResource> getAssetByUuid(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID serverUuid) {
|
||||
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var result = serverRepo.findByUuid(serverUuid);
|
||||
final var result = assetRepo.findByUuid(serverUuid);
|
||||
return result
|
||||
.map(serverEntity -> ResponseEntity.ok(
|
||||
mapper.map(serverEntity, HsServerResource.class)))
|
||||
mapper.map(serverEntity, HsHostingAssetResource.class)))
|
||||
.orElseGet(() -> ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteServerUuid(
|
||||
public ResponseEntity<Void> deleteAssetUuid(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID serverUuid) {
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var result = serverRepo.deleteByUuid(serverUuid);
|
||||
final var result = assetRepo.deleteByUuid(serverUuid);
|
||||
return result == 0
|
||||
? ResponseEntity.notFound().build()
|
||||
: ResponseEntity.noContent().build();
|
||||
@ -99,25 +100,25 @@ public class HsHostingAssetController implements HsHostingServersApi {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<HsServerResource> patchServer(
|
||||
public ResponseEntity<HsHostingAssetResource> patchAsset(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID serverUuid,
|
||||
final HsServerPatchResource body) {
|
||||
final HsHostingAssetPatchResource body) {
|
||||
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var current = serverRepo.findByUuid(serverUuid).orElseThrow();
|
||||
final var current = assetRepo.findByUuid(serverUuid).orElseThrow();
|
||||
|
||||
new HsHostingAssetEntityPatcher(current).apply(body);
|
||||
|
||||
final var saved = serverRepo.save(current);
|
||||
final var mapped = mapper.map(saved, HsServerResource.class);
|
||||
final var saved = assetRepo.save(current);
|
||||
final var mapped = mapper.map(saved, HsHostingAssetResource.class);
|
||||
return ResponseEntity.ok(mapped);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final BiConsumer<HsServerInsertResource, HsHostingAssetEntity> RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
|
||||
final BiConsumer<HsHostingAssetInsertResource, HsHostingAssetEntity> RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
|
||||
entity.putConfig(KeyValueMap.from(resource.getConfig()));
|
||||
};
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
||||
import lombok.AccessLevel;
|
||||
@ -33,9 +33,9 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.server.HsHostingAssetType.CLOUD_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.server.HsHostingAssetType.MANAGED_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.server.HsHostingAssetType.MANAGED_WEBSPACE;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingCase;
|
||||
@ -64,7 +64,10 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
||||
|
||||
private static Stringify<HsHostingAssetEntity> stringify = stringify(HsHostingAssetEntity.class)
|
||||
.withProp(e -> e.getBookingItem().toShortString())
|
||||
.withProp(HsHostingAssetEntity::getBookingItem)
|
||||
.withProp(HsHostingAssetEntity::getType)
|
||||
.withProp(HsHostingAssetEntity::getParentAsset)
|
||||
.withProp(HsHostingAssetEntity::getIdentifier)
|
||||
.withProp(HsHostingAssetEntity::getCaption)
|
||||
.withProp(HsHostingAssetEntity::getConfig)
|
||||
.quotedValues(false);
|
||||
@ -88,8 +91,8 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
||||
@Enumerated(EnumType.STRING)
|
||||
private HsHostingAssetType type;
|
||||
|
||||
@Column(name = "fixedname")
|
||||
private String fixedName; // vm1234, xyz00, example.org, xyz00_abc
|
||||
@Column(name = "identifier")
|
||||
private String identifier; // vm1234, xyz00, example.org, xyz00_abc
|
||||
|
||||
@Column(name = "caption")
|
||||
private String caption;
|
||||
@ -125,17 +128,17 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
||||
@Override
|
||||
public String toShortString() {
|
||||
return ofNullable(bookingItem).map(HsBookingItemEntity::toShortString).orElse("D-???????:?") +
|
||||
":" + caption;
|
||||
":" + identifier;
|
||||
}
|
||||
|
||||
public static RbacView rbac() {
|
||||
return rbacViewFor("asset", HsHostingAssetEntity.class)
|
||||
.withIdentityView(SQL.query("""
|
||||
SELECT asset.uuid as uuid, bookingItemIV.idName || '-' || cleanIdentifier(asset.caption) as idName
|
||||
SELECT asset.uuid as uuid, bookingItemIV.idName || '-' || cleanIdentifier(asset.identifier) as idName
|
||||
FROM hs_hosting_asset asset
|
||||
JOIN hs_booking_item_iv bookingItemIV ON bookingItemIV.uuid = asset.bookingItemUuid
|
||||
"""))
|
||||
.withRestrictedViewOrderBy(SQL.expression("caption"))
|
||||
.withRestrictedViewOrderBy(SQL.expression("identifier"))
|
||||
.withUpdatableColumns("version", "caption", "config")
|
||||
|
||||
.importEntityAlias("bookingItem", HsBookingItemEntity.class, usingDefaultCase(),
|
@ -1,13 +1,13 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsServerPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource;
|
||||
import net.hostsharing.hsadminng.mapper.EntityPatcher;
|
||||
import net.hostsharing.hsadminng.mapper.KeyValueMap;
|
||||
import net.hostsharing.hsadminng.mapper.OptionalFromJson;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class HsHostingAssetEntityPatcher implements EntityPatcher<HsServerPatchResource> {
|
||||
public class HsHostingAssetEntityPatcher implements EntityPatcher<HsHostingAssetPatchResource> {
|
||||
|
||||
private final HsHostingAssetEntity entity;
|
||||
|
||||
@ -16,7 +16,7 @@ public class HsHostingAssetEntityPatcher implements EntityPatcher<HsServerPatchR
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(final HsServerPatchResource resource) {
|
||||
public void apply(final HsHostingAssetPatchResource resource) {
|
||||
OptionalFromJson.of(resource.getCaption())
|
||||
.ifPresent(entity::setCaption);
|
||||
Optional.ofNullable(resource.getConfig())
|
@ -1,4 +1,4 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
@ -0,0 +1,28 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
public enum HsHostingAssetType {
|
||||
CLOUD_SERVER, // named e.g. vm1234
|
||||
MANAGED_SERVER, // named e.g. vm1234
|
||||
MANAGED_WEBSPACE(MANAGED_SERVER), // named eg. xyz00
|
||||
UNIX_USER(MANAGED_WEBSPACE), // named e.g. xyz00-abc
|
||||
DOMAIN_SETUP(UNIX_USER), // named e.g. example.org
|
||||
|
||||
// TODO.spec: SECURE_MX
|
||||
EMAIL_ALIAS(MANAGED_WEBSPACE), // named e.g. xyz00-abc
|
||||
EMAIL_ADDRESS(DOMAIN_SETUP), // named e.g. sample@example.org
|
||||
PGSQL_USER(MANAGED_WEBSPACE), // named e.g. xyz00_abc
|
||||
PGSQL_DATABASE(MANAGED_WEBSPACE), // named e.g. xyz00_abc, TODO.spec: or PGSQL_USER?
|
||||
MARIADB_USER(MANAGED_WEBSPACE), // named e.g. xyz00_abc
|
||||
MARIADB_DATABASE(MANAGED_WEBSPACE); // named e.g. xyz00_abc, TODO.spec: or MARIADB_USER?
|
||||
|
||||
|
||||
public final HsHostingAssetType parentAssetType;
|
||||
|
||||
HsHostingAssetType(final HsHostingAssetType parentAssetType) {
|
||||
this.parentAssetType = parentAssetType;
|
||||
}
|
||||
|
||||
HsHostingAssetType() {
|
||||
this(null);
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
|
||||
public enum HsHostingAssetType {
|
||||
CLOUD_SERVER,
|
||||
MANAGED_SERVER,
|
||||
MANAGED_WEBSPACE(MANAGED_SERVER),
|
||||
UNIX_USER(MANAGED_WEBSPACE),
|
||||
DOMAIN_SETUP(UNIX_USER),
|
||||
|
||||
// TODO.spec: SECURE_MX
|
||||
EMAIL_ALIAS(MANAGED_WEBSPACE),
|
||||
EMAIL_ADDRESS(DOMAIN_SETUP),
|
||||
PGSQL_USER(MANAGED_WEBSPACE),
|
||||
PGSQL_DATABASE(MANAGED_WEBSPACE), // TODO.spec: or PGSQL_USER?
|
||||
MARIADB_USER(MANAGED_WEBSPACE),
|
||||
MARIADB_DATABASE(MANAGED_WEBSPACE); // TODO.spec: or MARIADB_USER?
|
||||
|
||||
|
||||
public final HsHostingAssetType parentAssetType;
|
||||
|
||||
HsHostingAssetType(final HsHostingAssetType parentAssetType) {
|
||||
this.parentAssetType = parentAssetType;
|
||||
}
|
||||
|
||||
HsHostingAssetType() {
|
||||
this(null);
|
||||
}
|
||||
}
|
@ -13,5 +13,5 @@ map:
|
||||
- type: string:uuid => java.util.UUID
|
||||
|
||||
paths:
|
||||
/api/hs/hosting/servers/{serverUuid}:
|
||||
/api/hs/hosting/assets/{assetUuid}:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
||||
|
@ -3,51 +3,81 @@ components:
|
||||
|
||||
schemas:
|
||||
|
||||
HsServer:
|
||||
HsHostingAssetType:
|
||||
type: string
|
||||
enum:
|
||||
- CLOUD_SERVER
|
||||
- MANAGED_SERVER
|
||||
- MANAGED_WEBSPACE
|
||||
- UNIX_USER
|
||||
- DOMAIN_SETUP
|
||||
- EMAIL_ALIAS
|
||||
- EMAIL_ADDRESS
|
||||
- PGSQL_USER
|
||||
- PGSQL_DATABASE
|
||||
- MARIADB_USER
|
||||
- MARIADB_DATABASE
|
||||
|
||||
HsHostingAsset:
|
||||
type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
type:
|
||||
$ref: '#/components/schemas/HsHostingAssetType'
|
||||
identifier:
|
||||
type: string
|
||||
caption:
|
||||
type: string
|
||||
config:
|
||||
$ref: '#/components/schemas/ServerConfiguration'
|
||||
$ref: '#/components/schemas/HsHostingAssetConfiguration'
|
||||
required:
|
||||
- type
|
||||
- ídentifier
|
||||
- uuid
|
||||
- config
|
||||
|
||||
HsServerPatch:
|
||||
HsHostingAssetPatch:
|
||||
type: object
|
||||
properties:
|
||||
caption:
|
||||
type: string
|
||||
nullable: true
|
||||
config:
|
||||
$ref: '#/components/schemas/ServerConfiguration'
|
||||
$ref: '#/components/schemas/HsHostingAssetConfiguration'
|
||||
|
||||
HsServerInsert:
|
||||
HsHostingAssetInsert:
|
||||
type: object
|
||||
properties:
|
||||
bookingItemUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
nullable: false
|
||||
type:
|
||||
$ref: '#/components/schemas/HsHostingAssetType'
|
||||
identifier:
|
||||
type: string
|
||||
minLength: 3
|
||||
maxLength: 80
|
||||
nullable: false
|
||||
caption:
|
||||
type: string
|
||||
minLength: 3
|
||||
maxLength: 80
|
||||
nullable: false
|
||||
config:
|
||||
$ref: '#/components/schemas/ServerConfiguration'
|
||||
$ref: '#/components/schemas/HsHostingAssetConfiguration'
|
||||
required:
|
||||
- type
|
||||
- identifier
|
||||
- caption
|
||||
- debitorUuid
|
||||
- config
|
||||
additionalProperties: false
|
||||
|
||||
ServerConfiguration:
|
||||
# forces generating a java.lang.Object containing a Map, instead of class ServerConfiguration
|
||||
HsHostingAssetConfiguration:
|
||||
# forces generating a java.lang.Object containing a Map, instead of class AssetConfiguration
|
||||
anyOf:
|
||||
- type: object
|
||||
properties:
|
@ -1,25 +1,25 @@
|
||||
get:
|
||||
tags:
|
||||
- hs-hosting-servers
|
||||
description: 'Fetch a single managed server by its uuid, if visible for the current subject.'
|
||||
operationId: getServerByUuid
|
||||
- hs-hosting-assets
|
||||
description: 'Fetch a single managed asset by its uuid, if visible for the current subject.'
|
||||
operationId: getAssetByUuid
|
||||
parameters:
|
||||
- $ref: 'auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: serverUuid
|
||||
- name: assetUuid
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
description: UUID of the managed server to fetch.
|
||||
description: UUID of the hosting asset to fetch.
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: 'hs-hosting-server-schemas.yaml#/components/schemas/HsServer'
|
||||
$ref: 'hs-hosting-asset-schemas.yaml#/components/schemas/HsHostingAsset'
|
||||
|
||||
"401":
|
||||
$ref: 'error-responses.yaml#/components/responses/Unauthorized'
|
||||
@ -28,13 +28,13 @@ get:
|
||||
|
||||
patch:
|
||||
tags:
|
||||
- hs-hosting-servers
|
||||
description: 'Updates a single managed server identified by its uuid, if permitted for the current subject.'
|
||||
operationId: patchServer
|
||||
- hs-hosting-assets
|
||||
description: 'Updates a single hosting asset identified by its uuid, if permitted for the current subject.'
|
||||
operationId: patchAsset
|
||||
parameters:
|
||||
- $ref: 'auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: serverUuid
|
||||
- name: assetUuid
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
@ -44,14 +44,14 @@ patch:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: 'hs-hosting-server-schemas.yaml#/components/schemas/HsServerPatch'
|
||||
$ref: 'hs-hosting-asset-schemas.yaml#/components/schemas/HsHostingAssetPatch'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: 'hs-hosting-server-schemas.yaml#/components/schemas/HsServer'
|
||||
$ref: 'hs-hosting-asset-schemas.yaml#/components/schemas/HsHostingAsset'
|
||||
"401":
|
||||
$ref: 'error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
@ -59,19 +59,19 @@ patch:
|
||||
|
||||
delete:
|
||||
tags:
|
||||
- hs-hosting-servers
|
||||
description: 'Delete a single managed server identified by its uuid, if permitted for the current subject.'
|
||||
operationId: deleteServerUuid
|
||||
- hs-hosting-assets
|
||||
description: 'Delete a single hosting asset identified by its uuid, if permitted for the current subject.'
|
||||
operationId: deleteAssetUuid
|
||||
parameters:
|
||||
- $ref: 'auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: serverUuid
|
||||
- name: assetUuid
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
description: UUID of the managed server to delete.
|
||||
description: UUID of the hosting asset to delete.
|
||||
responses:
|
||||
"204":
|
||||
description: No Content
|
@ -1,9 +1,9 @@
|
||||
get:
|
||||
summary: Returns a list of all managed servers for a specified debitor.
|
||||
description: Returns the list of all managed servers for a debitor which are visible to the current user or any of it's assumed roles.
|
||||
summary: Returns a list of all hosting assets for a specified debitor.
|
||||
description: Returns the list of all hosting assets for a debitor which are visible to the current user or any of it's assumed roles.
|
||||
tags:
|
||||
- hs-hosting-servers
|
||||
operationId: listServersByDebitorUuid
|
||||
- hs-hosting-assets
|
||||
operationId: listAssetsByDebitorUuid
|
||||
parameters:
|
||||
- $ref: 'auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||
@ -13,7 +13,7 @@ get:
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
description: The UUID of the debitor, whose managed servers are to be listed.
|
||||
description: The UUID of the debitor, whose hosting assets are to be listed.
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
@ -22,34 +22,34 @@ get:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: 'hs-hosting-server-schemas.yaml#/components/schemas/HsServer'
|
||||
$ref: 'hs-hosting-asset-schemas.yaml#/components/schemas/HsHostingAsset'
|
||||
"401":
|
||||
$ref: 'error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: 'error-responses.yaml#/components/responses/Forbidden'
|
||||
|
||||
post:
|
||||
summary: Adds a new managed server.
|
||||
summary: Adds a new hosting asset.
|
||||
tags:
|
||||
- hs-hosting-servers
|
||||
operationId: addServer
|
||||
- hs-hosting-assets
|
||||
operationId: addAsset
|
||||
parameters:
|
||||
- $ref: 'auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
|
||||
requestBody:
|
||||
description: A JSON object describing the new managed server.
|
||||
description: A JSON object describing the new hosting asset.
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: 'hs-hosting-server-schemas.yaml#/components/schemas/HsServerInsert'
|
||||
$ref: 'hs-hosting-asset-schemas.yaml#/components/schemas/HsHostingAssetInsert'
|
||||
responses:
|
||||
"201":
|
||||
description: Created
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: 'hs-hosting-server-schemas.yaml#/components/schemas/HsServer'
|
||||
$ref: 'hs-hosting-asset-schemas.yaml#/components/schemas/HsHostingAsset'
|
||||
"401":
|
||||
$ref: 'error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
@ -10,8 +10,8 @@ paths:
|
||||
|
||||
# Items
|
||||
|
||||
/api/hs/hosting/servers:
|
||||
$ref: "hs-hosting-servers.yaml"
|
||||
/api/hs/hosting/assets:
|
||||
$ref: "hs-hosting-assets.yaml"
|
||||
|
||||
/api/hs/hosting/servers/{serverUuid}:
|
||||
$ref: "hs-hosting-servers-with-uuid.yaml"
|
||||
/api/hs/hosting/assets/{assetUuid}:
|
||||
$ref: "hs-hosting-assets-with-uuid.yaml"
|
||||
|
@ -5,6 +5,7 @@
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
create type HsHostingAssetType as enum (
|
||||
'CLOUD_SERVER',
|
||||
'MANAGED_SERVER',
|
||||
'MANAGED_WEBSPACE',
|
||||
'UNIX_USER',
|
||||
@ -17,6 +18,8 @@ create type HsHostingAssetType as enum (
|
||||
'MARIADB_DATABASE'
|
||||
);
|
||||
|
||||
CREATE CAST (character varying as HsHostingAssetType) WITH INOUT AS IMPLICIT;
|
||||
|
||||
create table if not exists hs_hosting_asset
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid),
|
||||
@ -24,6 +27,7 @@ create table if not exists hs_hosting_asset
|
||||
bookingItemUuid uuid not null references hs_booking_item(uuid),
|
||||
type HsHostingAssetType,
|
||||
parentAssetUuid uuid null references hs_hosting_asset(uuid),
|
||||
identifier varchar(80) not null,
|
||||
caption varchar(80) not null,
|
||||
config jsonb not null
|
||||
);
|
||||
|
@ -158,7 +158,7 @@ create trigger hs_hosting_asset_insert_permission_check_tg
|
||||
|
||||
call generateRbacIdentityViewFromQuery('hs_hosting_asset',
|
||||
$idName$
|
||||
SELECT asset.uuid as uuid, bookingItemIV.idName || '-' || cleanIdentifier(asset.caption) as idName
|
||||
SELECT asset.uuid as uuid, bookingItemIV.idName || '-' || cleanIdentifier(asset.identifier) as idName
|
||||
FROM hs_hosting_asset asset
|
||||
JOIN hs_booking_item_iv bookingItemIV ON bookingItemIV.uuid = asset.bookingItemUuid
|
||||
$idName$);
|
||||
@ -169,7 +169,7 @@ create trigger hs_hosting_asset_insert_permission_check_tg
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRbacRestrictedView('hs_hosting_asset',
|
||||
$orderBy$
|
||||
caption
|
||||
identifier
|
||||
$orderBy$,
|
||||
$updates$
|
||||
version = new.version,
|
||||
|
@ -10,7 +10,8 @@
|
||||
*/
|
||||
create or replace procedure createHsHostingAssetTestData(
|
||||
givenPartnerNumber numeric,
|
||||
givenDebitorSuffix char(2)
|
||||
givenDebitorSuffix char(2),
|
||||
givenWebspacePrefix char(3)
|
||||
)
|
||||
language plpgsql as $$
|
||||
declare
|
||||
@ -36,10 +37,10 @@ begin
|
||||
raise notice 'creating test hosting-asset: %', givenPartnerNumber::text || givenDebitorSuffix::text;
|
||||
raise notice '- using debitor (%): %', relatedDebitor.uuid, relatedDebitor;
|
||||
insert
|
||||
into hs_hosting_asset (uuid, bookingitemuuid, caption, config)
|
||||
values (uuid_generate_v4(), relatedBookingItem.uuid, 'some ManagedAsset', '{ "CPU": 2, "SDD": 512, "extra": 42 }'::jsonb),
|
||||
(uuid_generate_v4(), relatedBookingItem.uuid, 'another CloudAsset', '{ "CPU": 2, "HDD": 1024, "extra": 42 }'::jsonb),
|
||||
(uuid_generate_v4(), relatedBookingItem.uuid, 'some Whatever', '{ "CPU": 1, "SDD": 512, "HDD": 2048, "extra": 42 }'::jsonb);
|
||||
into hs_hosting_asset (uuid, bookingitemuuid, type, identifier, caption, config)
|
||||
values (uuid_generate_v4(), relatedBookingItem.uuid, 'MANAGED_SERVER'::HsHostingAssetType, 'vm10' || givenDebitorSuffix, 'some ManagedServer', '{ "CPU": 2, "SDD": 512, "extra": 42 }'::jsonb),
|
||||
(uuid_generate_v4(), relatedBookingItem.uuid, 'CLOUD_SERVER'::HsHostingAssetType, 'vm20' || givenDebitorSuffix, 'another CloudServer', '{ "CPU": 2, "HDD": 1024, "extra": 42 }'::jsonb),
|
||||
(uuid_generate_v4(), relatedBookingItem.uuid, 'MANAGED_WEBSPACE'::HsHostingAssetType, givenWebspacePrefix || '01', 'some Webspace', '{ "RAM": 1, "SDD": 512, "HDD": 2048, "extra": 42 }'::jsonb);
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
@ -50,8 +51,8 @@ end; $$;
|
||||
|
||||
do language plpgsql $$
|
||||
begin
|
||||
call createHsHostingAssetTestData(10001, '11');
|
||||
call createHsHostingAssetTestData(10002, '12');
|
||||
call createHsHostingAssetTestData(10003, '13');
|
||||
call createHsHostingAssetTestData(10001, '11', 'aaa');
|
||||
call createHsHostingAssetTestData(10002, '12', 'bbb');
|
||||
call createHsHostingAssetTestData(10003, '13', 'ccc');
|
||||
end;
|
||||
$$;
|
||||
|
@ -136,6 +136,6 @@ databaseChangeLog:
|
||||
- include:
|
||||
file: db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql
|
||||
- include:
|
||||
file: db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-server-rbac.sql
|
||||
file: db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql
|
||||
- include:
|
||||
file: db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql
|
||||
|
@ -51,7 +51,7 @@ public class ArchitectureTest {
|
||||
"..hs.office.relation",
|
||||
"..hs.office.sepamandate",
|
||||
"..hs.booking.item",
|
||||
"..hs.hosting.server",
|
||||
"..hs.hosting.asset",
|
||||
"..errors",
|
||||
"..mapper",
|
||||
"..ping",
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
@ -34,7 +34,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
private Integer port;
|
||||
|
||||
@Autowired
|
||||
HsHostingAssetRepository serverRepo;
|
||||
HsHostingAssetRepository assetRepo;
|
||||
|
||||
@Autowired
|
||||
HsBookingItemRepository bookingItemRepo;
|
||||
@ -46,10 +46,10 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
JpaAttempt jpaAttempt;
|
||||
|
||||
@Nested
|
||||
class ListServers {
|
||||
class ListAssets {
|
||||
|
||||
@Test
|
||||
void globalAdmin_canViewAllServersOfArbitraryDebitor() {
|
||||
void globalAdmin_canViewAllAssetsOfArbitraryDebitor() {
|
||||
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
@ -60,13 +60,26 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/hosting/servers?debitorUuid=" + givenDebitor.getUuid())
|
||||
.get("http://localhost/api/hs/hosting/assets?debitorUuid=" + givenDebitor.getUuid())
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
[
|
||||
{
|
||||
"type": "MANAGED_WEBSPACE",
|
||||
"identifier": "aaa01",
|
||||
"caption": "some Webspace",
|
||||
"config": {
|
||||
"HDD": 2048,
|
||||
"RAM": 1,
|
||||
"SDD": 512,
|
||||
"extra": 42
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "MANAGED_SERVER",
|
||||
"identifier": "vm1011",
|
||||
"caption": "some ManagedServer",
|
||||
"config": {
|
||||
"CPU": 2,
|
||||
@ -75,21 +88,14 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CLOUD_SERVER",
|
||||
"identifier": "vm2011",
|
||||
"caption": "another CloudServer",
|
||||
"config": {
|
||||
"CPU": 2,
|
||||
"HDD": 1024,
|
||||
"extra": 42
|
||||
}
|
||||
},
|
||||
{
|
||||
"caption": "some Whatever",
|
||||
"config": {
|
||||
"CPU": 1,
|
||||
"HDD": 2048,
|
||||
"SDD": 512,
|
||||
"extra": 42
|
||||
}
|
||||
}
|
||||
]
|
||||
"""));
|
||||
@ -101,7 +107,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
class AddServer {
|
||||
|
||||
@Test
|
||||
void globalAdmin_canAddServer() {
|
||||
void globalAdmin_canAddAsset() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenBookingItem = givenBookingItem("First", "some PrivateCloud");
|
||||
@ -113,26 +119,30 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.body("""
|
||||
{
|
||||
"bookingItemUuid": "%s",
|
||||
"type": "MANAGED_SERVER",
|
||||
"identifier": "vm1400",
|
||||
"caption": "some new CloudServer",
|
||||
"config": { "CPU": 3, "extra": 42 }
|
||||
}
|
||||
""".formatted(givenBookingItem.getUuid()))
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/hosting/servers")
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(201)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"type": "MANAGED_SERVER",
|
||||
"identifier": "vm1400",
|
||||
"caption": "some new CloudServer",
|
||||
"config": { "CPU": 3, "extra": 42 }
|
||||
}
|
||||
"""))
|
||||
.header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/servers/[^/]*"))
|
||||
.header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/assets/[^/]*"))
|
||||
.extract().header("Location"); // @formatter:on
|
||||
|
||||
// finally, the new server can be accessed under the generated UUID
|
||||
// finally, the new asset can be accessed under the generated UUID
|
||||
final var newUserUuid = UUID.fromString(
|
||||
location.substring(location.lastIndexOf('/') + 1));
|
||||
assertThat(newUserUuid).isNotNull();
|
||||
@ -140,12 +150,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
|
||||
@Nested
|
||||
class GetServer {
|
||||
class GetASset {
|
||||
|
||||
@Test
|
||||
void globalAdmin_canGetArbitraryServer() {
|
||||
void globalAdmin_canGetArbitraryAsset() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenServerUuid = serverRepo.findAll().stream()
|
||||
final var givenAssetUuid = assetRepo.findAll().stream()
|
||||
.filter(bi -> bi.getBookingItem().getDebitor().getDebitorNumber() == 1000111)
|
||||
.filter(item -> item.getCaption().equals("some ManagedServer"))
|
||||
.findAny().orElseThrow().getUuid();
|
||||
@ -155,7 +165,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/hosting/servers/" + givenServerUuid)
|
||||
.get("http://localhost/api/hs/hosting/assets/" + givenAssetUuid)
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
@ -172,9 +182,9 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalUser_canNotGetUnrelatedServer() {
|
||||
void normalUser_canNotGetUnrelatedAsset() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenServerUuid = serverRepo.findAll().stream()
|
||||
final var givenAssetUuid = assetRepo.findAll().stream()
|
||||
.filter(bi -> bi.getBookingItem().getDebitor().getDebitorNumber() == 1000212)
|
||||
.map(HsHostingAssetEntity::getUuid)
|
||||
.findAny().orElseThrow();
|
||||
@ -184,15 +194,15 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.header("current-user", "selfregistered-user-drew@hostsharing.org")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/hosting/servers/" + givenServerUuid)
|
||||
.get("http://localhost/api/hs/hosting/assets/" + givenAssetUuid)
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(404); // @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
void debitorAgentUser_canGetRelatedServer() {
|
||||
void debitorAgentUser_canGetRelatedAsset() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenServerUuid = serverRepo.findAll().stream()
|
||||
final var givenAssetUuid = assetRepo.findAll().stream()
|
||||
.filter(bi -> bi.getBookingItem().getDebitor().getDebitorNumber() == 1000313)
|
||||
.filter(bi -> bi.getCaption().equals("some ManagedServer"))
|
||||
.findAny().orElseThrow().getUuid();
|
||||
@ -202,12 +212,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.header("current-user", "person-TuckerJack@example.com")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/hosting/servers/" + givenServerUuid)
|
||||
.get("http://localhost/api/hs/hosting/assets/" + givenAssetUuid)
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"identifier": "vm1013",
|
||||
"caption": "some ManagedServer",
|
||||
"config": {
|
||||
"CPU": 2,
|
||||
@ -220,12 +231,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
|
||||
@Nested
|
||||
class PatchServer {
|
||||
class PatchAsset {
|
||||
|
||||
@Test
|
||||
void globalAdmin_canPatchAllUpdatablePropertiesOfServer() {
|
||||
void globalAdmin_canPatchAllUpdatablePropertiesOfAsset() {
|
||||
|
||||
final var givenServer = givenSomeTemporaryServerForDebitorNumber(1000111, entry("something", 1));
|
||||
final var givenAsset = givenSomeTemporaryAssetForDebitorNumber("2001", entry("something", 1));
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
@ -242,13 +253,15 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
""")
|
||||
.port(port)
|
||||
.when()
|
||||
.patch("http://localhost/api/hs/hosting/servers/" + givenServer.getUuid())
|
||||
.patch("http://localhost/api/hs/hosting/assets/" + givenAsset.getUuid())
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"caption": "some test-server",
|
||||
"type": "CLOUD_SERVER",
|
||||
"identifier": "vm2001",
|
||||
"caption": "some test-asset",
|
||||
"config": {
|
||||
"CPU": "4",
|
||||
"SSD": "4096",
|
||||
@ -257,53 +270,53 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
""")); // @formatter:on
|
||||
|
||||
// finally, the server is actually updated
|
||||
// finally, the asset is actually updated
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
assertThat(serverRepo.findByUuid(givenServer.getUuid())).isPresent().get()
|
||||
.matches(server -> {
|
||||
assertThat(server.toString()).isEqualTo("HsHostingServerEntity(D-1000111:some CloudServer, some test-server, { CPU: 4, SSD: 4096, something: 1 })");
|
||||
assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent().get()
|
||||
.matches(asset -> {
|
||||
assertThat(asset.toString()).isEqualTo("HsHostingAssetEntity(D-1000111:some CloudServer, CLOUD_SERVER, vm2001, some test-asset, { CPU: 4, SSD: 4096, something: 1 })");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class DeleteServer {
|
||||
class DeleteAsset {
|
||||
|
||||
@Test
|
||||
void globalAdmin_canDeleteArbitraryServer() {
|
||||
void globalAdmin_canDeleteArbitraryAsset() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenServer = givenSomeTemporaryServerForDebitorNumber(1000111, entry("something", 1));
|
||||
final var givenAsset = givenSomeTemporaryAssetForDebitorNumber("2002", entry("something", 1));
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/hosting/servers/" + givenServer.getUuid())
|
||||
.delete("http://localhost/api/hs/hosting/assets/" + givenAsset.getUuid())
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(204); // @formatter:on
|
||||
|
||||
// then the given server is gone
|
||||
assertThat(serverRepo.findByUuid(givenServer.getUuid())).isEmpty();
|
||||
// then the given assets is gone
|
||||
assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalUser_canNotDeleteUnrelatedServer() {
|
||||
void normalUser_canNotDeleteUnrelatedAsset() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenServer = givenSomeTemporaryServerForDebitorNumber(1000111, entry("something", 1));
|
||||
final var givenAsset = givenSomeTemporaryAssetForDebitorNumber("2003", entry("something", 1));
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "selfregistered-user-drew@hostsharing.org")
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/hosting/servers/" + givenServer.getUuid())
|
||||
.delete("http://localhost/api/hs/hosting/assets/" + givenAsset.getUuid())
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(404); // @formatter:on
|
||||
|
||||
// then the given server is still there
|
||||
assertThat(serverRepo.findByUuid(givenServer.getUuid())).isNotEmpty();
|
||||
// then the given asset is still there
|
||||
assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,18 +327,20 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.findAny().orElseThrow();
|
||||
}
|
||||
|
||||
private HsHostingAssetEntity givenSomeTemporaryServerForDebitorNumber(final int debitorNumber,
|
||||
private HsHostingAssetEntity givenSomeTemporaryAssetForDebitorNumber(final String identifierSuffix,
|
||||
final Map.Entry<String, Integer> resources) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var newServer = HsHostingAssetEntity.builder()
|
||||
final var newAsset = HsHostingAssetEntity.builder()
|
||||
.uuid(UUID.randomUUID())
|
||||
.bookingItem(givenBookingItem("First", "some CloudServer"))
|
||||
.caption("some test-server")
|
||||
.type(HsHostingAssetType.CLOUD_SERVER)
|
||||
.identifier("vm" + identifierSuffix)
|
||||
.caption("some test-asset")
|
||||
.config(Map.ofEntries(resources))
|
||||
.build();
|
||||
|
||||
return serverRepo.save(newServer);
|
||||
return assetRepo.save(newAsset);
|
||||
}).assertSuccessful().returnedValue();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsServerPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||
import net.hostsharing.hsadminng.mapper.KeyValueMap;
|
||||
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
|
||||
@ -26,7 +26,7 @@ import static org.mockito.Mockito.lenient;
|
||||
@TestInstance(PER_CLASS)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
HsServerPatchResource,
|
||||
HsHostingAssetPatchResource,
|
||||
HsHostingAssetEntity
|
||||
> {
|
||||
|
||||
@ -73,8 +73,8 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HsServerPatchResource newPatchResource() {
|
||||
return new HsServerPatchResource();
|
||||
protected HsHostingAssetPatchResource newPatchResource() {
|
||||
return new HsHostingAssetPatchResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -87,12 +87,12 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
return Stream.of(
|
||||
new JsonNullableProperty<>(
|
||||
"caption",
|
||||
HsServerPatchResource::setCaption,
|
||||
HsHostingAssetPatchResource::setCaption,
|
||||
PATCHED_CAPTION,
|
||||
HsHostingAssetEntity::setCaption),
|
||||
new SimpleProperty<>(
|
||||
"config",
|
||||
HsServerPatchResource::setConfig,
|
||||
HsHostingAssetPatchResource::setConfig,
|
||||
PATCH_CONFIG,
|
||||
HsHostingAssetEntity::putConfig,
|
||||
PATCHED_CONFIG)
|
@ -1,4 +1,4 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -10,9 +10,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class HsHostingAssetEntityUnitTest {
|
||||
|
||||
final HsHostingAssetEntity givenParentAsset = HsHostingAssetEntity.builder()
|
||||
.bookingItem(TEST_BOOKING_ITEM)
|
||||
.type(HsHostingAssetType.MANAGED_SERVER)
|
||||
.identifier("vm1234")
|
||||
.caption("some managed asset")
|
||||
.config(Map.ofEntries(
|
||||
entry("CPUs", 2),
|
||||
entry("SSD-storage", 512),
|
||||
entry("HDD-storage", 2048)))
|
||||
.build();
|
||||
final HsHostingAssetEntity givenServer = HsHostingAssetEntity.builder()
|
||||
.bookingItem(TEST_BOOKING_ITEM)
|
||||
.caption("some caption")
|
||||
.type(HsHostingAssetType.MANAGED_WEBSPACE)
|
||||
.parentAsset(givenParentAsset)
|
||||
.identifier("xyz00")
|
||||
.caption("some managed webspace")
|
||||
.config(Map.ofEntries(
|
||||
entry("CPUs", 2),
|
||||
entry("SSD-storage", 512),
|
||||
@ -24,13 +37,13 @@ class HsHostingAssetEntityUnitTest {
|
||||
final var result = givenServer.toString();
|
||||
|
||||
assertThat(result).isEqualTo(
|
||||
"HsHostingAssetEntity(D-1000100:test booking item, some caption, { CPUs: 2, HDD-storage: 2048, SSD-storage: 512 })");
|
||||
"HsHostingAssetEntity(D-1000100:test booking item, MANAGED_WEBSPACE, D-1000100:test booking item:vm1234, xyz00, some managed webspace, { CPUs: 2, HDD-storage: 2048, SSD-storage: 512 })");
|
||||
}
|
||||
|
||||
@Test
|
||||
void toShortStringContainsOnlyMemberNumberAndCaption() {
|
||||
final var result = givenServer.toShortString();
|
||||
|
||||
assertThat(result).isEqualTo("D-1000100:test booking item:some caption");
|
||||
assertThat(result).isEqualTo("D-1000100:test booking item:xyz00");
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.server;
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
|
||||
@ -25,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.distinctGrantDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.distinctRoleNamesOf;
|
||||
import static net.hostsharing.hsadminng.rbac.test.Array.fromFormatted;
|
||||
@ -36,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@Autowired
|
||||
HsHostingAssetRepository serverRepo;
|
||||
HsHostingAssetRepository assetRepo;
|
||||
|
||||
@Autowired
|
||||
HsBookingItemRepository bookingItemRepo;
|
||||
@ -60,30 +61,31 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
HttpServletRequest request;
|
||||
|
||||
@Nested
|
||||
class CreateServer {
|
||||
class CreateAsset {
|
||||
|
||||
@Test
|
||||
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewServer() {
|
||||
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewAsset() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var count = serverRepo.count();
|
||||
final var count = assetRepo.count();
|
||||
final var givenBookingItem = givenBookingItem("First", "some CloudServer");
|
||||
|
||||
|
||||
// when
|
||||
final var result = attempt(em, () -> {
|
||||
final var newServer = HsHostingAssetEntity.builder()
|
||||
final var newAsset = HsHostingAssetEntity.builder()
|
||||
.bookingItem(givenBookingItem)
|
||||
.caption("some new booking server")
|
||||
.caption("some new managed webspace")
|
||||
.type(HsHostingAssetType.MANAGED_WEBSPACE)
|
||||
.identifier("xyz90")
|
||||
.build();
|
||||
return toCleanup(serverRepo.save(newServer));
|
||||
return toCleanup(assetRepo.save(newAsset));
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetEntity::getUuid).isNotNull();
|
||||
assertThatServerIsPersisted(result.returnedValue());
|
||||
assertThat(serverRepo.count()).isEqualTo(count + 1);
|
||||
assertThatAssetIsPersisted(result.returnedValue());
|
||||
assertThat(assetRepo.count()).isEqualTo(count + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -97,45 +99,48 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
final var givenBookingItem = givenBookingItem("First", "some CloudServer");
|
||||
|
||||
// when
|
||||
attempt(em, () -> {
|
||||
final var newServer = HsHostingAssetEntity.builder()
|
||||
final var result = attempt(em, () -> {
|
||||
final var newAsset = HsHostingAssetEntity.builder()
|
||||
.bookingItem(givenBookingItem)
|
||||
.caption("some new booking server")
|
||||
.type(HsHostingAssetType.MANAGED_WEBSPACE)
|
||||
.identifier("xyz91")
|
||||
.caption("some new managed webspace")
|
||||
.build();
|
||||
return toCleanup(serverRepo.save(newServer));
|
||||
return toCleanup(assetRepo.save(newAsset));
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
final var all = rawRoleRepo.findAll();
|
||||
assertThat(distinctRoleNamesOf(all)).containsExactlyInAnyOrder(Array.from(
|
||||
initialRoleNames,
|
||||
"hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:ADMIN",
|
||||
"hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:OWNER",
|
||||
"hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:TENANT"));
|
||||
"hs_hosting_asset#D-1000111-someCloudServer-xyz91:ADMIN",
|
||||
"hs_hosting_asset#D-1000111-someCloudServer-xyz91:OWNER",
|
||||
"hs_hosting_asset#D-1000111-someCloudServer-xyz91:TENANT"));
|
||||
assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll()))
|
||||
.map(s -> s.replace("hs_office_", ""))
|
||||
.containsExactlyInAnyOrder(fromFormatted(
|
||||
initialGrantNames,
|
||||
// global-admin
|
||||
"{ grant perm:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:DELETE to role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:OWNER by system and assume }",
|
||||
|
||||
// owner
|
||||
"{ grant perm:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:UPDATE to role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:ADMIN by system and assume }",
|
||||
"{ grant perm:hs_hosting_asset#D-1000111-someCloudServer-xyz91:DELETE to role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:OWNER by system and assume }",
|
||||
|
||||
// admin
|
||||
"{ grant role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:ADMIN to role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:OWNER by system and assume }",
|
||||
"{ grant role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:OWNER to role:hs_booking_item#D-1000111-someCloudServer:ADMIN by system and assume }",
|
||||
"{ grant perm:hs_hosting_asset#D-1000111-someCloudServer-xyz91:UPDATE to role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:ADMIN by system and assume }",
|
||||
"{ grant role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:ADMIN to role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:OWNER by system and assume }",
|
||||
"{ grant role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:OWNER to role:hs_booking_item#D-1000111-someCloudServer:ADMIN by system and assume }",
|
||||
|
||||
// tenant
|
||||
"{ grant role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:TENANT to role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:ADMIN by system and assume }",
|
||||
"{ grant perm:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:SELECT to role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:TENANT by system and assume }",
|
||||
"{ grant role:hs_booking_item#D-1000111-someCloudServer:TENANT to role:hs_hosting_asset#D-1000111-someCloudServer-somenewbookingserver:TENANT by system and assume }",
|
||||
"{ grant perm:hs_hosting_asset#D-1000111-someCloudServer-xyz91:SELECT to role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:TENANT by system and assume }",
|
||||
"{ grant role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:TENANT to role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:ADMIN by system and assume }",
|
||||
"{ grant role:hs_booking_item#D-1000111-someCloudServer:TENANT to role:hs_hosting_asset#D-1000111-someCloudServer-xyz91:TENANT by system and assume }",
|
||||
|
||||
null));
|
||||
}
|
||||
|
||||
private void assertThatServerIsPersisted(final HsHostingAssetEntity saved) {
|
||||
final var found = serverRepo.findByUuid(saved.getUuid());
|
||||
private void assertThatAssetIsPersisted(final HsHostingAssetEntity saved) {
|
||||
final var found = assetRepo.findByUuid(saved.getUuid());
|
||||
assertThat(found).isNotEmpty().map(HsHostingAssetEntity::toString).get().isEqualTo(saved.toString());
|
||||
}
|
||||
}
|
||||
@ -144,69 +149,69 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
class FindByDebitorUuid {
|
||||
|
||||
@Test
|
||||
public void globalAdmin_withoutAssumedRole_canViewAllServersOfArbitraryDebitor() {
|
||||
public void globalAdmin_withoutAssumedRole_canViewAllAssetsOfArbitraryDebitor() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var debitorUuid = debitorRepo.findDebitorByDebitorNumber(1000212).stream()
|
||||
.findAny().orElseThrow().getUuid();
|
||||
|
||||
// when
|
||||
final var result = serverRepo.findAllByDebitorUuid(debitorUuid);
|
||||
final var result = assetRepo.findAllByDebitorUuid(debitorUuid);
|
||||
|
||||
// then
|
||||
allTheseServersAreReturned(
|
||||
result,
|
||||
"HsHostingServerEntity(D-1000212:some PrivateCloud, another CloudServer, { CPU: 2, HDD: 1024, extra: 42 })",
|
||||
"HsHostingServerEntity(D-1000212:some PrivateCloud, some ManagedServer, { CPU: 2, SDD: 512, extra: 42 })",
|
||||
"HsHostingServerEntity(D-1000212:some PrivateCloud, some Whatever, { CPU: 1, HDD: 2048, SDD: 512, extra: 42 })");
|
||||
"HsHostingAssetEntity(D-1000212:some PrivateCloud, MANAGED_WEBSPACE, bbb01, some Webspace, { HDD: 2048, RAM: 1, SDD: 512, extra: 42 })",
|
||||
"HsHostingAssetEntity(D-1000212:some PrivateCloud, MANAGED_SERVER, vm1012, some ManagedServer, { CPU: 2, SDD: 512, extra: 42 })",
|
||||
"HsHostingAssetEntity(D-1000212:some PrivateCloud, CLOUD_SERVER, vm2012, another CloudServer, { CPU: 2, HDD: 1024, extra: 42 })");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalUser_canViewOnlyRelatedServers() {
|
||||
public void normalUser_canViewOnlyRelatedAsset() {
|
||||
// given:
|
||||
context("person-FirbySusan@example.com");
|
||||
final var debitorUuid = debitorRepo.findDebitorByDebitorNumber(1000111).stream().findAny().orElseThrow().getUuid();
|
||||
|
||||
// when:
|
||||
final var result = serverRepo.findAllByDebitorUuid(debitorUuid);
|
||||
final var result = assetRepo.findAllByDebitorUuid(debitorUuid);
|
||||
|
||||
// then:
|
||||
exactlyTheseServersAreReturned(
|
||||
exactlyTheseAssetsAreReturned(
|
||||
result,
|
||||
"HsHostingServerEntity(D-1000111:some PrivateCloud, another CloudServer, { CPU: 2, HDD: 1024, extra: 42 })",
|
||||
"HsHostingServerEntity(D-1000111:some PrivateCloud, some ManagedServer, { CPU: 2, SDD: 512, extra: 42 })",
|
||||
"HsHostingServerEntity(D-1000111:some PrivateCloud, some Whatever, { CPU: 1, HDD: 2048, SDD: 512, extra: 42 })");
|
||||
"HsHostingAssetEntity(D-1000111:some PrivateCloud, MANAGED_WEBSPACE, aaa01, some Webspace, { HDD: 2048, RAM: 1, SDD: 512, extra: 42 })",
|
||||
"HsHostingAssetEntity(D-1000111:some PrivateCloud, MANAGED_SERVER, vm1011, some ManagedServer, { CPU: 2, SDD: 512, extra: 42 })",
|
||||
"HsHostingAssetEntity(D-1000111:some PrivateCloud, CLOUD_SERVER, vm2011, another CloudServer, { CPU: 2, HDD: 1024, extra: 42 })");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class UpdateServer {
|
||||
class UpdateAsset {
|
||||
|
||||
@Test
|
||||
public void hostsharingAdmin_canUpdateArbitraryServer() {
|
||||
// given
|
||||
final var givenServerUuid = givenSomeTemporaryServer("First").getUuid();
|
||||
final var givenAssetUuid = givenSomeTemporaryAsset("First", "vm1000").getUuid();
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var foundServer = em.find(HsHostingAssetEntity.class, givenServerUuid);
|
||||
foundServer.getConfig().put("CPUs", 2);
|
||||
foundServer.getConfig().remove("SSD-storage");
|
||||
foundServer.getConfig().put("HSD-storage", 2048);
|
||||
return toCleanup(serverRepo.save(foundServer));
|
||||
final var foundAsset = em.find(HsHostingAssetEntity.class, givenAssetUuid);
|
||||
foundAsset.getConfig().put("CPUs", 2);
|
||||
foundAsset.getConfig().remove("SSD-storage");
|
||||
foundAsset.getConfig().put("HSD-storage", 2048);
|
||||
return toCleanup(assetRepo.save(foundAsset));
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
assertThatServerActuallyInDatabase(result.returnedValue());
|
||||
assertThatAssetActuallyInDatabase(result.returnedValue());
|
||||
}).assertSuccessful();
|
||||
}
|
||||
|
||||
private void assertThatServerActuallyInDatabase(final HsHostingAssetEntity saved) {
|
||||
final var found = serverRepo.findByUuid(saved.getUuid());
|
||||
private void assertThatAssetActuallyInDatabase(final HsHostingAssetEntity saved) {
|
||||
final var found = assetRepo.findByUuid(saved.getUuid());
|
||||
assertThat(found).isNotEmpty().get().isNotSameAs(saved)
|
||||
.extracting(Object::toString).isEqualTo(saved.toString());
|
||||
}
|
||||
@ -216,59 +221,59 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
class DeleteByUuid {
|
||||
|
||||
@Test
|
||||
public void globalAdmin_withoutAssumedRole_canDeleteAnyServer() {
|
||||
public void globalAdmin_withoutAssumedRole_canDeleteAnyAsset() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net", null);
|
||||
final var givenServer = givenSomeTemporaryServer("First");
|
||||
final var givenAsset = givenSomeTemporaryAsset("First", "vm1000");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
serverRepo.deleteByUuid(givenServer.getUuid());
|
||||
assetRepo.deleteByUuid(givenAsset.getUuid());
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
assertThat(jpaAttempt.transacted(() -> {
|
||||
context("superuser-fran@hostsharing.net", null);
|
||||
return serverRepo.findByUuid(givenServer.getUuid());
|
||||
return assetRepo.findByUuid(givenAsset.getUuid());
|
||||
}).assertSuccessful().returnedValue()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void relatedOwner_canDeleteTheirRelatedServer() {
|
||||
public void relatedOwner_canDeleteTheirRelatedAsset() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net", null);
|
||||
final var givenServer = givenSomeTemporaryServer("First");
|
||||
final var givenAsset = givenSomeTemporaryAsset("First", "vm1000");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("person-FirbySusan@example.com");
|
||||
assertThat(serverRepo.findByUuid(givenServer.getUuid())).isPresent();
|
||||
assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent();
|
||||
|
||||
serverRepo.deleteByUuid(givenServer.getUuid());
|
||||
assetRepo.deleteByUuid(givenAsset.getUuid());
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
assertThat(jpaAttempt.transacted(() -> {
|
||||
context("superuser-fran@hostsharing.net", null);
|
||||
return serverRepo.findByUuid(givenServer.getUuid());
|
||||
return assetRepo.findByUuid(givenAsset.getUuid());
|
||||
}).assertSuccessful().returnedValue()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void relatedAdmin_canNotDeleteTheirRelatedServer() {
|
||||
public void relatedAdmin_canNotDeleteTheirRelatedAsset() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net", null);
|
||||
final var givenServer = givenSomeTemporaryServer("First");
|
||||
final var givenAsset = givenSomeTemporaryAsset("First", "vm1000");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("person-FirbySusan@example.com", "hs_hosting_asset#D-1000111-someCloudServer-sometempbookingserver:ADMIN");
|
||||
assertThat(serverRepo.findByUuid(givenServer.getUuid())).isPresent();
|
||||
context("person-FirbySusan@example.com", "hs_hosting_asset#D-1000111-someCloudServer-vm1000:ADMIN");
|
||||
assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent();
|
||||
|
||||
serverRepo.deleteByUuid(givenServer.getUuid());
|
||||
assetRepo.deleteByUuid(givenAsset.getUuid());
|
||||
});
|
||||
|
||||
// then
|
||||
@ -277,22 +282,22 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
"[403] Subject ", " is not allowed to delete hs_hosting_asset");
|
||||
assertThat(jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
return serverRepo.findByUuid(givenServer.getUuid());
|
||||
return assetRepo.findByUuid(givenAsset.getUuid());
|
||||
}).assertSuccessful().returnedValue()).isPresent(); // still there
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletingAServerAlsoDeletesRelatedRolesAndGrants() {
|
||||
public void deletingAnAssetAlsoDeletesRelatedRolesAndGrants() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var initialRoleNames = Array.from(distinctRoleNamesOf(rawRoleRepo.findAll()));
|
||||
final var initialGrantNames = Array.from(distinctGrantDisplaysOf(rawGrantRepo.findAll()));
|
||||
final var givenServer = givenSomeTemporaryServer("First");
|
||||
final var givenAsset = givenSomeTemporaryAsset("First", "vm1000");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
return serverRepo.deleteByUuid(givenServer.getUuid());
|
||||
return assetRepo.deleteByUuid(givenAsset.getUuid());
|
||||
});
|
||||
|
||||
// then
|
||||
@ -317,24 +322,26 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
|
||||
// then
|
||||
assertThat(customerLogEntries).map(Arrays::toString).contains(
|
||||
"[creating hosting-server test-data 1000111, hs_hosting_asset, INSERT]",
|
||||
"[creating hosting-server test-data 1000212, hs_hosting_asset, INSERT]",
|
||||
"[creating hosting-server test-data 1000313, hs_hosting_asset, INSERT]");
|
||||
"[creating hosting-asset test-data 1000111, hs_hosting_asset, INSERT]",
|
||||
"[creating hosting-asset test-data 1000212, hs_hosting_asset, INSERT]",
|
||||
"[creating hosting-asset test-data 1000313, hs_hosting_asset, INSERT]");
|
||||
}
|
||||
|
||||
private HsHostingAssetEntity givenSomeTemporaryServer(final String debitorName) {
|
||||
private HsHostingAssetEntity givenSomeTemporaryAsset(final String debitorName, final String identifier) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var givenBookingItem = givenBookingItem(debitorName, "some CloudServer");
|
||||
final var newServer = HsHostingAssetEntity.builder()
|
||||
final var newAsset = HsHostingAssetEntity.builder()
|
||||
.bookingItem(givenBookingItem)
|
||||
.caption("some temp booking server")
|
||||
.type(CLOUD_SERVER)
|
||||
.identifier(identifier)
|
||||
.caption("some temp cloud asset")
|
||||
.config(Map.ofEntries(
|
||||
entry("CPUs", 1),
|
||||
entry("SSD-storage", 256)))
|
||||
.build();
|
||||
|
||||
return toCleanup(serverRepo.save(newServer));
|
||||
return toCleanup(assetRepo.save(newAsset));
|
||||
}).assertSuccessful().returnedValue();
|
||||
}
|
||||
|
||||
@ -345,17 +352,17 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
.findAny().orElseThrow();
|
||||
}
|
||||
|
||||
void exactlyTheseServersAreReturned(
|
||||
void exactlyTheseAssetsAreReturned(
|
||||
final List<HsHostingAssetEntity> actualResult,
|
||||
final String... serverNames) {
|
||||
assertThat(actualResult)
|
||||
.extracting(serverEntity -> serverEntity.toString())
|
||||
.extracting(HsHostingAssetEntity::toString)
|
||||
.containsExactlyInAnyOrder(serverNames);
|
||||
}
|
||||
|
||||
void allTheseServersAreReturned(final List<HsHostingAssetEntity> actualResult, final String... serverNames) {
|
||||
assertThat(actualResult)
|
||||
.extracting(serverEntity -> serverEntity.toString())
|
||||
.extracting(HsHostingAssetEntity::toString)
|
||||
.contains(serverNames);
|
||||
}
|
||||
}
|
@ -143,7 +143,6 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
initialGrantNames,
|
||||
// TODO.rbac: this grant should only be created for DEBITOR-Relationships, thus the RBAC DSL needs to support conditional grants
|
||||
"{ grant perm:relation#HostsharingeG-with-PARTNER-EBess:INSERT>sepamandate to role:relation#HostsharingeG-with-PARTNER-EBess:ADMIN by system and assume }",
|
||||
"{ grant perm:relation#HostsharingeG-with-PARTNER-EBess:INSERT>hs_booking_item to role:relation#HostsharingeG-with-PARTNER-EBess:ADMIN by system and assume }",
|
||||
|
||||
// permissions on partner
|
||||
"{ grant perm:partner#P-20032:DELETE to role:relation#HostsharingeG-with-PARTNER-EBess:OWNER by system and assume }",
|
||||
|
@ -133,7 +133,6 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
initialGrantNames,
|
||||
// TODO.rbac: this grant should only be created for DEBITOR-Relationships, thus the RBAC DSL needs to support conditional grants
|
||||
"{ grant perm:hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert:INSERT>hs_office_sepamandate to role:hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert:ADMIN by system and assume }",
|
||||
"{ grant perm:hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert:INSERT>hs_booking_item to role:hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert:ADMIN by system and assume }",
|
||||
|
||||
"{ grant perm:hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert:DELETE to role:hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert:OWNER by system and assume }",
|
||||
"{ grant role:hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert:OWNER to role:global#global:ADMIN by system and assume }",
|
||||
|
Loading…
Reference in New Issue
Block a user