Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI whitelabel runtime system #8942

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

BryanMLima
Copy link
Contributor

Description

1. Problem description

Currently ACS allows the GUI personalization (color changing, add a personalized logo, and so on); however, those configurations are set for the whole environment, which does not allow Apache CloudStack to have a personalized GUI by domain, account and so on. In a scenario of cloud providers reselling the infrastructure, the current behavior does not allow the operators to personalize the GUI for each use case (reseller, domain, account, and so on).

2. Proposed Changes

This spec introduces the concept of Runtime White Label to the Apache CloudStack GUI, which combines the market concept of White Label and enables it to be configured in runtime and by scope (domain, account, and so on). Briefly, we will introduce APIs to allow the operators to define GUI themes for a set of Internet common names (fixed or wildcard), a set of ACS domain UUIDs (also known as ID for the end-user), and a set of ACS account UUIDs (also known as ID for the end-user). The APIs will receive the CSS and JSON configuration as parameter and will store them into the database. When accessing Apache CloudStack, the UI will retrieve the CSS and JSON configurations according to the access definition and import them into the browser. If there are no themes match, the GUI will fallback to the current environment configuration.

Operations that create/modify/remove the themes will be registered with events in ACS.

2.1. Database model

A table named gui_themes will be created in the cloud schema and will have the following columns:

Name Type Nullable Default Description
id bigint(20) unsigned No Auto increment -
uuid varchar(40) No null -
name varchar(2048) No null A name to identify the theme.
description varchar(4096) Yes null A description for the theme.
css text Yes null The CSS to be retrieved and imported into the GUI when matching the theme access configurations.
Name Type Nullable Default Description
json_configuration text Yes null The JSON with the configurations to be retrieved and imported into the GUI when matching the theme access configurations.
common_names text Yes null A set of Internet common names (fixed or wildcard) separated by comma that can use the theme; e.g.: *acme.com,acme2.com.
domain_uuids text Yes null A set of [ACS] domain IDs separated by comma that can use the theme.
account_uuids text Yes null A set of [ACS] account IDs separated by comma that can use the theme
is_public boolean Yes true Defines whether a theme can be retrieved by anyone when only the common_names is informed. If the domain_uuids or account_uuids is informed, it is considered as false.
created datetime No null When the theme was created.
removed datetime Yes null When the theme was removed.
2.2. APIs

Right below there are the descriptions of the APIs to be introduced to allow the management of GUI themes by scope.

2.2.1. createGuiTheme

The API createGuiTheme will be accessible only by the operators (Root Admin accounts) and will allow them to create themes for several scopes. It will have the following parameters:

Parameter Description Mandatory Type Default value Length
name A name to identify the theme. Yes String null 2048
description A description for the theme. No String null 4096
Parameter Description Mandatory Type Default value Length
css The CSS to be retrieved and imported into the GUI when matching the theme access configurations. No String null 65535
jsonconfiguration The JSON with the configurations to be retrieved and imported into the GUI when matching the theme access configurations. More details about the JSON configurations can be found in the JSON Configurations session. No String null 65535
commonnames A set of Internet common names (fixed or wildcard) separated by comma that can retrieve the theme; e.g.: *acme.com,acme2.com No String null 65535
domainids A set of [ACS] domain UUIDs (also known as ID for the end-user) separated by comma that can retrieve the theme. No String null 65535
accountids A set of [ACS] account UUIDs (also known as ID for the end-user) separated by comma that can retrieve the theme No String null 65535
ispublic Defines whether a theme can be retrieved by anyone when only the domainnames is informed. If the domainids or accountids is informed, it is considered as false. No Boolean true -

Either css or jsonconfiguration parameter must be informed for the GUI theme creation. If neither commonnames, domainids, and accountids is defined, the theme will be considered as the default; there can exist only one default theme and it automatically will be public. If there are no themes match, the GUI will fallback to the current environment configuration.

2.2.2. listGuiThemes

The API listGuiThemes will be accessible by anyone and will retrieve the themes according to the parameters and the caller access. It will have the following parameters:

Parameter Description Mandatory Type Default value Length
id The theme ID. No String null 40
name The name of the theme. No String null 2048
commonname The Internet common name to be filtered. No String null 256
domainid The UUID (also known as ID for the end-user) of the domain to be filtered. No String null 40
accountid The UUID (also known as ID for the end-user) of the account to be filtered. No String null 40
listall Whether to list all themes. No Boolean false -
listremoved Whether to list removed themes. No Boolean false -
ispublic Whether to list public themes. By default, it lists them all. No Boolean null -
listonlydefaulttheme Whether to list only the default theme. If this parameter is true, than all other parameters are ignored. No Boolean false -

In order to allow the theme to be displayed yet in the login web page, it will be possible to call this API without authentication; however, there will be limitations and all the parameters will be ignored. An unauthenticated call to the API listGuiThemes will retrieve no entry or only a single entry; the single entry will be the default theme or the public, most recently, and active theme that matches the Internet common name requesting the API.

2.2.3. updateGuiTheme

The API updateGuiTheme will be accessible only by the operators (Root Admin accounts) and will allow them to update a theme. It will have the following parameters:

Parameter Description Mandatory Type Default value Length
id The ID of the theme to be updated. Yes String null 40
name A name to identify the theme. No String null 2048
description A description for the theme. No String null 4096
css The CSS to be retrieved and imported into the GUI when matching the theme access configurations. No String null 65535
jsonconfiguration The JSON with the configurations to be retrieved and imported into the GUI when matching the theme access configurations. More details about the JSON configurations can be found in the JSON Configurations session. No String null 65535
commonnames A set of Internet common names (fixed or wildcard) separated by comma that can retrieve the theme; e.g.: *acme.com,acme2.com No String null 65535
domainids A set of [ACS] domain UUIDs (also known as ID for the end-user) separated by comma that can retrieve the theme. No String null 65535
accountids A set of [ACS] account UUIDs (also known as ID for the end-user) separated by comma that can retrieve the theme No String null 65535
ispublic Defines whether a theme can be retrieved by anyone when only the domainnames is informed. If the domainids or accountids is informed, it is considered as false. No Boolean null -

By default, all the parameters are null; therefore, to remove one of the parameters, it will be necessary to explicitly pass it as an empty string. If commonnames, domainids, and accountids are passed as empty, the theme will be considered as the default; there can exist only one default theme and it automatically will be public. If there are no themes match, the GUI will fallback to the current environment configuration.

2.2.4. removeGuiTheme

The API removeGuiTheme will be accessible only by the operators (Root Admin accounts) and will allow them to remove a theme. It will have the following parameter:

Parameter Description Mandatory Type Default value Length
id The UUID (also known as ID for the end-user) of the theme to be removed. Yes String null 40

If the default theme is removed and there is no match to a theme access configuration, the GUI will fallback to the current environment configuration.

3.0. Future works

With this proposal, it will be only possible to manage the themes via API; for the future, we plan to add support for the themes management on the GUI. We will extend the feature to comply with projects, identity federation and domains change. Also, we will extend the feature to allow domain admins and users to manage their own themes.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Screenshots (if appropriate):

There were two themes added with this PR: Dark theme and Apache Foundation theme. They can be used by anyone using the createGuiTheme API. They serve only to demonstrate the usage of this new feature, as presented in the screenshots below:

  • Apache theme:

image

image

Dark theme:

image

image

How Has This Been Tested?

I created multiple themes for specific accounts, domains and common names; they were correctly assigned.

How did you try to break this feature and the system with this change?

@DaanHoogland
Copy link
Contributor

interesting

@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✖️ debian ✔️ suse15. SL-JID 9322

@DaanHoogland
Copy link
Contributor

@blueorangutan test alma9 kvm-alma9 keepEnv

@blueorangutan
Copy link

@DaanHoogland a [SL] Trillian-Jenkins test job (alma9 mgmt + kvm-alma9) has been kicked to run smoke tests

@blueorangutan
Copy link

[SF] Trillian test result (tid-9917)
Environment: kvm-alma9 (x2), Advanced Networking with Mgmt server a9
Total time taken: 51841 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr8942-t9917-kvm-alma9.zip
Smoke tests completed. 127 look OK, 2 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_01_events_resource Error 318.04 test_events_resource.py
test_01_events_resource Error 318.05 test_events_resource.py
test_04_deploy_vm_for_other_user_and_test_vm_operations Failure 96.36 test_network_permissions.py
ContextSuite context=TestNetworkPermissions>:teardown Error 1.62 test_network_permissions.py

@BryanMLima
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@BryanMLima a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 9365

@DaanHoogland
Copy link
Contributor

@blueorangutan test

@blueorangutan
Copy link

@DaanHoogland a [SL] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

Copy link

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@blueorangutan
Copy link

[SF] Trillian test result (tid-9967)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 47193 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr8942-t9967-kvm-centos7.zip
Smoke tests completed. 127 look OK, 2 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_01_events_resource Error 306.15 test_events_resource.py
test_01_events_resource Error 306.16 test_events_resource.py
test_04_deploy_vm_for_other_user_and_test_vm_operations Failure 92.52 test_network_permissions.py
ContextSuite context=TestNetworkPermissions>:teardown Error 1.50 test_network_permissions.py

@DaanHoogland
Copy link
Contributor

nice work @BryanMLima , haven't reviewed all of it, but I like it so far.

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2024

Codecov Report

Attention: Patch coverage is 5.90406% with 510 lines in your changes are missing coverage. Please review.

Project coverage is 18.34%. Comparing base (27124c1) to head (0432462).

Files Patch % Lines
...ache/cloudstack/gui/theme/GuiThemeServiceImpl.java 2.71% 179 Missing ⚠️
...oudstack/gui/theme/dao/GuiThemeDetailsDaoImpl.java 1.81% 54 Missing ⚠️
.../cloudstack/gui/theme/dao/GuiThemeJoinDaoImpl.java 4.08% 47 Missing ⚠️
...a/org/apache/cloudstack/gui/themes/GuiThemeVO.java 12.76% 41 Missing ⚠️
...ache/cloudstack/api/response/GuiThemeResponse.java 0.00% 38 Missing ⚠️
...g/apache/cloudstack/gui/themes/GuiThemeJoinVO.java 9.09% 30 Missing ⚠️
...api/command/user/gui/themes/UpdateGuiThemeCmd.java 0.00% 25 Missing ⚠️
...api/command/user/gui/themes/CreateGuiThemeCmd.java 0.00% 24 Missing ⚠️
.../api/command/user/gui/themes/ListGuiThemesCmd.java 0.00% 17 Missing ⚠️
...pache/cloudstack/gui/themes/GuiThemeDetailsVO.java 10.52% 17 Missing ⚠️
... and 5 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8942      +/-   ##
============================================
+ Coverage     15.95%   18.34%   +2.38%     
- Complexity    15925    16242     +317     
============================================
  Files          5207     4886     -321     
  Lines        366992   325109   -41883     
  Branches      53822    45670    -8152     
============================================
+ Hits          58570    59652    +1082     
+ Misses       301450   256899   -44551     
- Partials       6972     8558    +1586     
Flag Coverage Δ
simulator-marvin-tests 18.34% <5.90%> (?)
uitests ?
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@JoaoJandre JoaoJandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great, just a few minor remarks.

String entryKey = entry.getKey();

if (entryValue.isJsonPrimitive() && ALLOWED_PRIMITIVE_PROPERTIES.contains(entryKey)) {
logger.trace("The JSON attribute [%s] is a valid option.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the attribute and use {}

Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
entries.stream().forEach(entry -> validateJsonAttributes(entry, jsonObject));
} catch (JsonSyntaxException exception) {
logger.error(String.format("The following exception was thrown while parsing the JSON object: [%s].", exception.getMessage()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use String.format()


protected void persistDetailValueIfNotNull(long guiThemeId, String providedParameter, String type) {
if (providedParameter == null) {
logger.trace(String.format("GUI theme provided parameter `%s` is null; therefore, it will be ignored.", type));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use format

}

protected void warnOfInvalidJsonAttribute(String entryKey) {
logger.warn(String.format("The JSON attribute [%s] is not a valid option, therefore, it will be ignored.", entryKey));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

guiThemeVO.setRecursiveDomains(recursiveDomains);
}

logger.trace(String.format("Persisting GUI theme [%s] with CSS [%s] and JSON configuration [%s].", guiThemeVO, guiThemeVO.getCss(), guiThemeVO.getJsonConfiguration()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -0,0 +1,1150 @@
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apache license is missing.

@@ -0,0 +1,1573 @@
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apache license is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants