Skip to content

Commit

Permalink
refactor(agent): skip racksdb route when disabled
Browse files Browse the repository at this point in the history
Skip registering RacksDB blueprint when racksdb is disabled. This
notably makes the agent return 404 for all RacksDB API routes.
  • Loading branch information
rezib committed Jan 17, 2025
1 parent f7be9cf commit 7959e22
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- gateway: Check RacksDB version executed by agent is greater or equal to the
minimal supported version specified in gateway configuration settings
(#415#417).
- agent: Skip registering of RacksDB API endpoint when disabled (#440).
- frontend:
- Reduce height of error message container when unable to retrieve
infrastructure graphical representation from RacksDB in resources page.
Expand Down
45 changes: 24 additions & 21 deletions slurmweb/apps/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,30 @@ class SlurmwebAppAgent(SlurmwebWebApp, RFLTokenizedRBACWebApp):
def __init__(self, seed):
SlurmwebWebApp.__init__(self, seed)

# Load RacksDB blueprint and fail with error if unable to load schema or
# database.
try:
self.register_blueprint(
RacksDBWebBlueprint(
db=self.settings.racksdb.db,
ext=self.settings.racksdb.extensions,
schema=self.settings.racksdb.schema,
drawings_schema=self.settings.racksdb.drawings_schema,
default_drawing_parameters={
"infrastructure": {"equipment_tags": self.settings.racksdb.tags}
},
),
url_prefix="/racksdb",
)
except RacksDBSchemaError as err:
logger.critical("Unable to load RacksDB schema: %s", err)
sys.exit(1)
except RacksDBFormatError as err:
logger.critical("Unable to load RacksDB database: %s", err)
sys.exit(1)
# If enabled, load RacksDB blueprint and fail with error if unable to load
# schema or database.
if self.settings.racksdb.enabled:
try:
self.register_blueprint(
RacksDBWebBlueprint(
db=self.settings.racksdb.db,
ext=self.settings.racksdb.extensions,
schema=self.settings.racksdb.schema,
drawings_schema=self.settings.racksdb.drawings_schema,
default_drawing_parameters={
"infrastructure": {
"equipment_tags": self.settings.racksdb.tags
}
},
),
url_prefix="/racksdb",
)
except RacksDBSchemaError as err:
logger.critical("Unable to load RacksDB schema: %s", err)
sys.exit(1)
except RacksDBFormatError as err:
logger.critical("Unable to load RacksDB database: %s", err)
sys.exit(1)

if self.settings.policy.roles.exists():
logger.debug("Select RBAC site roles policy %s", self.settings.policy.roles)
Expand Down

0 comments on commit 7959e22

Please sign in to comment.