-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from ineilson/local_info-schema-checking
Add local_info.xsd and xml schema validation
- Loading branch information
Showing
10 changed files
with
541 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"\] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"><xs:schema version="1.0" | ||
xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
></xsl:text> | ||
<xsl:text disable-output-escaping="yes"> | ||
<xs:complexType name="validMenus"> | ||
<xs:all></xsl:text> | ||
<xsl:apply-templates/> | ||
<xsl:text disable-output-escaping="yes"> | ||
</xs:all> | ||
</xs:complexType> | ||
</xs:schema>
</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"> | ||
<xs:element name="</xsl:text> | ||
<xsl:value-of select="name()"/> | ||
<xsl:text disable-output-escaping="yes">" type="showType" minOccurs="0"/></xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="/menus/main_menu/spacer"> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.