Skip to content

Commit

Permalink
Merge branch 'dev' into 416-refresh-and-enrich-ServiceGroups-from-sam…
Browse files Browse the repository at this point in the history
…pleData
  • Loading branch information
rowan04 authored Sep 12, 2023
2 parents d0b2162 + 643461f commit 38ea9f2
Show file tree
Hide file tree
Showing 239 changed files with 4,741 additions and 2,028 deletions.
3 changes: 3 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ version: "2"
plugins:
phpcodesniffer:
enabled: true
# Need the beta channel to enforce PSR12,
# see https://docs.codeclimate.com/docs/phpcodesniffer#standard.
channel: "beta"
config:
standard: "phpcs.xml"
phpmd:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand Down
28 changes: 16 additions & 12 deletions config/gocdb_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,22 @@
</entity>
<!-- ========================================================== -->
<entity>
<name>service_type</name>
<field>
<fname>NAME</fname>
<length>255</length>
<regex>/^([[:alpha:]]|[[:digit:]]|[\._-])*$/</regex>
</field>
<field>
<fname>DESCRIPTION</fname>
<length>255</length>
<!--<regex>/^[a-zA-Z0-9\-\._\(\)\[\],;+:\/'"\s]*$/</regex>-->
<regex>/^[^`'\";&lt;&gt;]+$/</regex>
</field>
<name>service_type</name>
<field>
<fname>NAME</fname>
<length>255</length>
<regex>/^([[:alpha:]]|[[:digit:]]|[\._-])*$/</regex>
</field>
<field>
<fname>DESCRIPTION</fname>
<length>255</length>
<!--<regex>/^[a-zA-Z0-9\-\._\(\)\[\],;+:\/'"\s]*$/</regex>-->
<regex>/^[^`'\";&lt;&gt;]+$/</regex>
</field>
<field>
<fname>ALLOWMONITORINGEXCEPTION</fname>
<ftype>boolean</ftype>
</field>
</entity>
<!-- ========================================================== -->
<entity>
Expand Down
2 changes: 2 additions & 0 deletions config/local_info.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<config>
<!--
Provide default values for all configuration elements.
See also local override information provided below this local_info element.
-->

<local_info>

<!-- If read-only is set as true, the portal will prevent changes to the
Expand Down
132 changes: 132 additions & 0 deletions config/local_info.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0"?>

<!-- Copied from https://www.ibm.com/developerworks/library/x-validxphp/ -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:include schemaLocation="./web_portal/menu.xsd"/>

<xs:simpleType name="showType">
<xs:restriction base="xs:string">
<xs:enumeration value="hide"/>
<xs:enumeration value="show"/>
<xs:enumeration value="no"/>
<xs:enumeration value="yes"/>
<xs:enumeration value="false"/>
<xs:enumeration value="true"/>
</xs:restriction>
</xs:simpleType>

<xs:element name="config">
<xs:complexType>
<xs:sequence>
<xs:element name="local_info" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:all>

<xs:element name="page_banner" type="xs:string" minOccurs="0"/>
<xs:element name="read_only" type="xs:boolean" minOccurs="0"/>
<xs:element name="filter_downtimes_by_default_scope" type="xs:boolean" minOccurs="0"/>
<xs:element name="default_filter_by_scope" type="xs:boolean" minOccurs="0"/>
<xs:element name="menus" type="validMenus" minOccurs="0"/>

<!-- Note that we do not validate the email string values provided here -->
<xs:element name="email_from" type="xs:string" minOccurs="0"/>
<xs:element name="email_to" type="xs:string" minOccurs="0"/>

<xs:element name="aup" type="xs:anyURI" minOccurs="0"/>
<xs:element name="aup_title" type="xs:string" minOccurs="0"/>
<xs:element name="privacy_notice" type="xs:anyURI" minOccurs="0"/>
<xs:element name="privacy_notice_title" type="xs:string" minOccurs="0"/>

<xs:element name="restrict_personal_data" type="xs:boolean" minOccurs="0"/>

<xs:element name="API_all_auth_realms" type="xs:boolean" minOccurs="0"/>

<xs:element name="css" minOccurs="0">
<xs:complexType>
<xs:all>
<!-- Use string type to allow standard colour names -->
<xs:element name="backgroundColour1" type="xs:string"/>
<xs:element name="backgroundColour2" type="xs:string"/>
<xs:element name="backgroundColour3" type="xs:string"/>
<xs:element name="backgroundDirection" type="xs:string"/>
<xs:element name="headingTextColour" type="xs:string"/>

</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="name_mapping" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="Service">
<xs:complexType>
<xs:all>
<xs:element name="ServiceEndpoint" type="xs:string" minOccurs="0"/>
<xs:element name="endpoint" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="web_portal_url" type="xs:anyURI" minOccurs="0"/>
<xs:element name="pi_url" type="xs:anyURI" minOccurs="0"/>
<xs:element name="server_base_url" type="xs:anyURI" minOccurs="0"/>
<xs:element name="write_api_user_docs_url" type="xs:anyURI" minOccurs="0"/>
<xs:element name="optional_features" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="siteless_services" type="xs:boolean"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="default_scope" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="name" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="show_map_on_start_page" type="xs:boolean" minOccurs="0"/>
<xs:element name="default_scope_match" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="any"/>
<xs:enumeration value="all"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="minimum_scopes" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="ngi" type="xs:integer" minOccurs="0"/>
<xs:element name="site" type="xs:integer" minOccurs="0"/>
<xs:element name="service" type="xs:integer" minOccurs="0"/>
<xs:element name="service_group" type="xs:integer" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="reserved_scopes" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="scope" type="xs:string" minOccurs="1" maxOccurs='unbounded'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="extensions" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="max" type="xs:integer"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="send_email" type="xs:boolean" minOccurs="0"/>
</xs:all>
<xs:attribute name="url" type="xs:anyURI"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
57 changes: 57 additions & 0 deletions config/web_portal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Auto-generation of menu.xsd and its use in GOCDB configuration

## What *config/web_portal/menu.xsd* is for

This file is the schema file for the definiton of GOCDB's left-hand column menu, used to check that only valid menu names are included in the GOCDB main configuration file config/local_info.xml. The menu.xsd file is built automatically, **do not edit it** - see the next question.

GOCDB uses an XML definition (config/web_portal/menu.xml) to programatically draw the left-hand menu items on the user
interface. Which menu items are drawn is selected via the \<MENU> element in the GOCDB configuration file (config/local_info.xml). To check that only valid menu item names are given within the \<MENU> element it is necessary to generate an XML schema containing all valid menu names (config/web_portal/menu.xsd).

## What *config/web_portal/menu.xslt* is for

This file is the transformation file which builds the menu.xsd schema definition file - see the previous question - from the menu definition file config/web_portal/menu.xml.

To avoid having to specify menu names manually twice: once in the XML and once in the schema definition (config/local_info.xsd), an XSL Transformation file (config/web_portal/menu.xslt) is used to generate the menu schema (config/web_portal/menu.xsd) directly from the XML menu file. This menu schema is then included into the overall GOCDB schema when the configuration is validated.

## How to make changes made to the left-hand menu

Left-hand menu items can be added or deleted by editing the menu XML file (config/web_portal/menu.xml). You should then run the XSL Transformation processor command *xsltproc* to generate a new menu schema -

```bash
xsltproc -o menu.xsd menu.xslt menu.xml
```

The resulting .xsd file will automatically be included in the configuration validation.

## Why these files are used

To prevent mistypes and other difficult-to-spot configuration errors, GOCDB uses an XML schema file (config/local_info.xsd) to validate the XML elements given in the main configuration file (config/local_info.xml).

## How these files are used

Checking that the schema is correct is done as part of the operations monitoring tests (htdocs/web_portal/GOCDB_monitor/*).

An XSLT translation file is not used to build the main configuration schema file (config/local_info.xsd) because the menu XML is part of the codebase, whereas the main configuration XML is variable content to be validated against the main schema definition which is also part of the codebase.

```mermaid
---
title: Updating menu items and configuration validation
---
flowchart TB
menu.xml[config/web_portal/menu.xml]
menu.xsd[config/web_portal/menu.xsd]
menu.xslt[config/web_portal/menu.xslt]
local_info.xsd[config/local_info.xsd]
local_info.xml[config/local_info.xml]
edits([add or delete menu items]) -->menu.xml
menu.xml & menu.xslt --> xsltproc[[xsltproc translation]] -->menu.xsd
menu.xsd-->|include in|local_info.xsd
config([configuration value edits]) -->local_info.xml
local_info.xsd & local_info.xml --> validation[[XML validation]] --> result[\"#nbsp;Result: valid or invalid configuration#nbsp;"\]
```
36 changes: 36 additions & 0 deletions config/web_portal/menu.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<!--
** DO NOT EDIT THIS FILE DIRECTLY. **
** THIS FILE IS AUTO GENERATED. **
** SEE menu.xslt FOR DETAILS. **
-->
<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:complexType name="validMenus">
<xs:all>
<xs:element name="MySites" type="showType" minOccurs="0"/>
<xs:element name="Projects" type="showType" minOccurs="0"/>
<xs:element name="NGI" type="showType" minOccurs="0"/>
<xs:element name="Sites" type="showType" minOccurs="0"/>
<xs:element name="ServiceGroups" type="showType" minOccurs="0"/>
<xs:element name="Services" type="showType" minOccurs="0"/>
<xs:element name="Scopes" type="showType" minOccurs="0"/>
<xs:element name="RoleActionMappings" type="showType" minOccurs="0"/>
<xs:element name="AddSite" type="showType" minOccurs="0"/>
<xs:element name="AddServiceGroup" type="showType" minOccurs="0"/>
<xs:element name="AddService" type="showType" minOccurs="0"/>
<xs:element name="AddDowntime" type="showType" minOccurs="0"/>
<xs:element name="CurrentDowntimes" type="showType" minOccurs="0"/>
<xs:element name="Calendar" type="showType" minOccurs="0"/>
<xs:element name="HelpAndContact" type="showType" minOccurs="0"/>
<xs:element name="AddNGI" type="showType" minOccurs="0"/>
<xs:element name="AddProject" type="showType" minOccurs="0"/>
<xs:element name="MoveServiceEndPoint" type="showType" minOccurs="0"/>
<xs:element name="MoveSite" type="showType" minOccurs="0"/>
<xs:element name="ServiceTypes" type="showType" minOccurs="0"/>
<xs:element name="Users" type="showType" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:schema>

48 changes: 48 additions & 0 deletions config/web_portal/menu.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!--
- Generate the schema definition for valid menu elements for including
- into config/local_info.xsd
-
- Example: # xsltproc -o menu.xsd menu.xslt menu.xml
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>

<xsl:strip-space elements="*"/>

<xsl:template match="/menus/main_menu">
<xsl:comment>
** DO NOT EDIT THIS FILE DIRECTLY. **
** THIS FILE IS AUTO GENERATED. **
** SEE menu.xslt FOR DETAILS. **
</xsl:comment>
<xsl:text disable-output-escaping="yes">&lt;xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">
&lt;xs:complexType name="validMenus"&gt;
&lt;xs:all&gt;</xsl:text>
<xsl:apply-templates/>
<xsl:text disable-output-escaping="yes">
&lt;/xs:all&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;&#xa;</xsl:text>
</xsl:template>

<xsl:template match="/menus/main_menu/*[not(self::spacer)]">
<!--
It would be better not to have to specify minOccurs repeatedly
but it is/seems to be necessary to allow the override sections not to be fully
specified.
-->
<xsl:text disable-output-escaping="yes">
&lt;xs:element name="</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text disable-output-escaping="yes">" type="showType" minOccurs="0"/&gt;</xsl:text>
</xsl:template>

<xsl:template match="/menus/main_menu/spacer">
</xsl:template>

</xsl:stylesheet>
Loading

0 comments on commit 38ea9f2

Please sign in to comment.