-
Notifications
You must be signed in to change notification settings - Fork 166
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
[WIP] Added CDN configuration to organizations module #1523
Open
Thulium-Drake
wants to merge
10
commits into
theforeman:develop
Choose a base branch
from
Thulium-Drake:add_configure_cdn_to_org
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
799d4b7
Rebased
Thulium-Drake 72b1681
Fix missing ()
Thulium-Drake d28c9ad
Fixed some stuff with regards to handling payload and existing orgs
Thulium-Drake c660f7e
Use Content Credential ID for now
Thulium-Drake de4955e
Processed feedback
Thulium-Drake 0906f2b
doc and examples formating fixes
evgeni a7e5305
Made it idempotent
Thulium-Drake 7fe76ba
Fix mangled merge
Thulium-Drake c5aa500
Remove workaround with ID
Thulium-Drake 458f2a8
add custom_cdn support
evgeni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# -*- coding: utf-8 -*- | ||
# (c) 2016, Eric D Helms <[email protected]> | ||
# (c) 2017, Matthias M Dellweg <[email protected]> (ATIX AG) | ||
# (c) 2022, Jeffrey van Pelt <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -30,6 +31,7 @@ | |
author: | ||
- "Eric D Helms (@ehelms)" | ||
- "Matthias M Dellweg (@mdellweg) ATIX AG" | ||
- "Jeffrey van Pelt (@Thulium-Drake)" | ||
options: | ||
name: | ||
description: | ||
|
@@ -54,6 +56,62 @@ | |
aliases: | ||
- select_all_types | ||
version_added: 3.8.0 | ||
upstream_type: | ||
description: | ||
- Type of upstream content source | ||
required: false | ||
type: str | ||
choices: | ||
- redhat_cdn | ||
- network_sync | ||
- export_sync | ||
- custom_cdn | ||
upstream_url: | ||
description: | ||
- URL of the upstream resource | ||
- Required when I(upstream_type) is C(redhat_cdn) or C(network_sync) | ||
required: false | ||
type: str | ||
upstream_ca_cert: | ||
description: | ||
- SSL CA certificate used to validate I(upstream_url) | ||
required: false | ||
type: str | ||
upstream_username: | ||
description: | ||
- Username to authenticate to the upstream Foreman server | ||
- Required when I(upstream_type) is C(network_sync) | ||
required: false | ||
type: str | ||
upstream_password: | ||
description: | ||
- Password to authenticate to the upstream Foreman server | ||
- Required when I(upstream_type) is C(network_sync) | ||
required: false | ||
type: str | ||
upstream_organization: | ||
description: | ||
- Organization in the upstream Foreman server to synchronize | ||
- Required when I(upstream_type) is C(network_sync) | ||
required: false | ||
type: str | ||
upstream_content_view: | ||
description: | ||
- Content View in the upstream Foreman server to synchronize | ||
- Required when I(upstream_type) is C(network_sync) | ||
required: false | ||
type: str | ||
upstream_lifecycle_environment: | ||
description: | ||
- Lifecycle Environment in the upstream Foreman server to synchronize | ||
- Required when I(upstream_type) is C(network_sync) | ||
required: false | ||
type: str | ||
upstream_custom_cdn_auth_enabled: | ||
description: | ||
- If product certificates should be used to authenticate to a custom CDN. | ||
type: bool | ||
required: false | ||
extends_documentation_fragment: | ||
- theforeman.foreman.foreman | ||
- theforeman.foreman.foreman.entity_state | ||
|
@@ -68,6 +126,38 @@ | |
server_url: "https://foreman.example.com" | ||
name: "My Cool New Organization" | ||
state: present | ||
|
||
- name: "Configure Red Hat CDN on a different URL" | ||
theforeman.foreman.organization: | ||
username: "admin" | ||
password: "changeme" | ||
server_url: "https://foreman.example.com" | ||
name: "My Cool New Organization" | ||
upstream_type: "redhat_cdn" | ||
upstream_url: "https://internal-cdn.example.com" | ||
|
||
- name: "Configure ISS Export Sync" | ||
theforeman.foreman.organization: | ||
username: "admin" | ||
password: "changeme" | ||
server_url: "https://foreman.example.com" | ||
name: "My Cool New Organization" | ||
upstream_type: "export_sync" | ||
|
||
- name: "Configure ISS Network Sync" | ||
theforeman.foreman.organization: | ||
username: "admin" | ||
password: "changeme" | ||
server_url: "https://foreman.example.com" | ||
name: "My Cool New Organization" | ||
upstream_type: "network_sync" | ||
upstream_url: "https://upstream-foreman.example.com" | ||
upstream_ca_cert: "Upstream Foreman" | ||
upstream_username: sync_user | ||
upstream_password: changeme2 | ||
upstream_organization: "Default Organization" | ||
upstream_lifecycle_environment: "Library" | ||
upstream_content_view: "Foreman_Network_Sync_View" | ||
''' | ||
|
||
RETURN = ''' | ||
|
@@ -98,6 +188,15 @@ def main(): | |
label=dict(), | ||
ignore_types=dict(type='list', elements='str', required=False, aliases=['select_all_types']), | ||
select_all_types=dict(type='list', invisible=True, flat_name='ignore_types'), | ||
upstream_type=dict(required=False, choices=['redhat_cdn', 'export_sync', 'network_sync', 'custom_cdn']), | ||
upstream_url=dict(required=False), | ||
upstream_username=dict(required=False), | ||
upstream_password=dict(required=False, no_log=True), | ||
upstream_ca_cert=dict(required=False, type='entity', resource_type='content_credentials', scope=['organization']), | ||
upstream_organization=dict(required=False), | ||
upstream_lifecycle_environment=dict(required=False), | ||
upstream_content_view=dict(required=False), | ||
upstream_custom_cdn_auth_enabled=dict(required=False, type='bool'), | ||
), | ||
) | ||
|
||
|
@@ -109,7 +208,54 @@ def main(): | |
if entity and 'select_all_types' in entity: | ||
entity['ignore_types'] = entity.pop('select_all_types') | ||
|
||
module.run() | ||
handle_cdn_configuration = 'upstream_type' in module.foreman_params | ||
|
||
organization = module.run() | ||
|
||
if handle_cdn_configuration and not module.desired_absent: | ||
payload = { | ||
'id': organization['id'], | ||
} | ||
extra_payload = { | ||
'type': module.foreman_params['upstream_type'], | ||
} | ||
|
||
if module.foreman_params['upstream_type'] == 'redhat_cdn': | ||
cdn_config = { | ||
'url': module.foreman_params['upstream_url'], | ||
} | ||
extra_payload.update(cdn_config) | ||
if module.foreman_params['upstream_type'] == 'network_sync': | ||
cdn_config = { | ||
'url': module.foreman_params['upstream_url'], | ||
'ssl_ca_credential_id': module.foreman_params['upstream_ca_cert'], | ||
'username': module.foreman_params['upstream_username'], | ||
'password': module.foreman_params['upstream_password'], | ||
'upstream_organization_label': module.foreman_params['upstream_organization'], | ||
'upstream_lifecycle_environment_label': module.foreman_params['upstream_lifecycle_environment'], | ||
'upstream_content_view_label': module.foreman_params['upstream_content_view'], | ||
} | ||
extra_payload.update(cdn_config) | ||
if module.foreman_params['upstream_type'] == 'custom_cdn': | ||
cdn_config = { | ||
'url': module.foreman_params['upstream_url'], | ||
'ssl_ca_credential_id': module.foreman_params['upstream_ca_cert'], | ||
'username': module.foreman_params['upstream_username'], | ||
'password': module.foreman_params['upstream_password'], | ||
'upstream_organization_label': module.foreman_params['upstream_organization'], | ||
'upstream_lifecycle_environment_label': module.foreman_params['upstream_lifecycle_environment'], | ||
'upstream_content_view_label': module.foreman_params['upstream_content_view'], | ||
'custom_cdn_auth_enabled': module.foreman_params['upstream_custom_cdn_auth_enabled'], | ||
} | ||
extra_payload.update(cdn_config) | ||
|
||
current_cdn_config = {k: v for k, v in organization['cdn_configuration'].items() if v is not None} | ||
del current_cdn_config['password_exists'] | ||
|
||
if current_cdn_config != extra_payload: | ||
if extra_payload: | ||
payload.update(extra_payload) | ||
module.resource_action('organizations', 'cdn_configuration', payload) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I read it right, this essentially always returns
changed=True
now, as there is no way to "diff" the cdn config?!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data is shown in the API reply to
/katello/api/organizations/:id
, so we could diff it… What a messThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried poking around in the API, but I can't find it.
When I go to
https://sat.rh.lab/api/organizations/1/cdn_configuration
I get a 404. And it's not listed in the 'overview' at theorganizations/<org_id>
endpoint either.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attention attention! katello overrides the org controller!
you need to go to
/katello/api/organizations/:id
, not to/api/organizations/:id
, the apipie library will do the right thing for us.and yes, the
cdn_configuration
part is only defined forPUT
(update) operations, you can'tGET
it, but the data is part of the normal org show view, if you look at the right controllerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel my Python-Fu is lacking a bit, but I made an attempt to compare some things, and it seems to work well :-)
This will never be idempotent for
network_sync
as the current password cannot be compared with the provided password.