Skip to content

Commit

Permalink
Merge branch 'main' into split-arch-build-image
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Izquierdo authored Oct 16, 2024
2 parents c9dd25b + 2bae5c7 commit b83ec06
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 29 deletions.
23 changes: 4 additions & 19 deletions .github/workflows/autoupdate-poetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
autoupdate-poetry-lock:
runs-on: ubuntu-latest
if: github.repository == 'ansible/eda-server'
permissions:
contents: write
pull-requests: write
outputs:
lock-changed: ${{ steps.lock-changed.outputs.lock-changed }}
steps:
Expand Down Expand Up @@ -43,27 +46,9 @@ jobs:
echo "lock-changed=true" >> $GITHUB_OUTPUT
fi
- name: Push changes
if: steps.lock-changed.outputs.lock-changed == 'true'
run: |
git checkout -b autoupdate-poetry-lock
git add poetry.lock
git commit -m "ci(bot): update poetry lock file"
git push origin autoupdate-poetry-lock --force
create-pr:
needs:
- autoupdate-poetry-lock
if: github.repository == 'ansible/eda-server' && needs.autoupdate-poetry-lock.outputs.lock-changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout autoupdate-poetry-lock branch
uses: actions/checkout@v3
with:
ref: autoupdate-poetry-lock

- name: Create a Pull Request
uses: peter-evans/create-pull-request@v5
if: steps.lock-changed.outputs.lock-changed == 'true'
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: autoupdate-poetry-lock
Expand Down
29 changes: 19 additions & 10 deletions src/aap_eda/core/management/commands/create_initial_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
from aap_eda.core.tasking import enable_redis_prefix
from aap_eda.core.utils.credentials import inputs_to_store

NEW_HELP_TEXT = (
"Red Hat Ansible Automation Platform base URL to authenticate with.",
"For Event-Driven Ansible controller 2.5 with Ansible Automation Controller 2.4, use the following example: https://<<your_controller_host>>", # noqa E501
"For Ansible Automation Controller 2.5, use the following example: https://<<your_gateway_host>>/api/controller/", # noqa E501
)

ORIG_HELP_TEXT = (
"Red Hat Ansible Automation Platform base URL to authenticate with."
)

CRUD = ["add", "view", "change", "delete"]
LOGGER = logging.getLogger(__name__)
AVAILABLE_ALGORITHMS = sorted(hashlib.algorithms_available)
Expand Down Expand Up @@ -251,10 +261,7 @@
"id": "host",
"label": "Red Hat Ansible Automation Platform",
"type": "string",
"help_text": (
"Red Hat Ansible Automation Platform base URL"
" to authenticate with."
),
"help_text": NEW_HELP_TEXT,
},
{
"id": "username",
Expand Down Expand Up @@ -1018,12 +1025,14 @@ def populate_credential_types(
for credential_type_data in credential_types:
new_type, created = models.CredentialType.objects.get_or_create(
name=credential_type_data["name"],
description=credential_type_data.get("description", ""),
namespace=credential_type_data.get("namespace"),
kind=credential_type_data.get("kind", "cloud"),
inputs=credential_type_data.get("inputs", {}),
injectors=credential_type_data.get("injectors", {}),
managed=credential_type_data.get("managed", True),
defaults={
"description": credential_type_data.get("description", ""),
"namespace": credential_type_data.get("namespace"),
"kind": credential_type_data.get("kind", "cloud"),
"inputs": credential_type_data.get("inputs", {}),
"injectors": credential_type_data.get("injectors", {}),
"managed": credential_type_data.get("managed", True),
},
)
if created:
created_credential_types.append(new_type)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 4.2.7 on 2024-10-11 14:49

from django.db import migrations

from aap_eda.core import enums
from aap_eda.core.management.commands.create_initial_data import (
NEW_HELP_TEXT,
ORIG_HELP_TEXT,
)


def update_credential_type(apps, schema_editor):
_update_credential_type_help_text(apps, NEW_HELP_TEXT)


def backward_credential_type(apps, schema_editor):
_update_credential_type_help_text(apps, ORIG_HELP_TEXT)


def _update_credential_type_help_text(apps, help_text):
credential_type = apps.get_model("core", "CredentialType") # noqa: N806

for ctype in credential_type.objects.filter(
name=enums.DefaultCredentialType.AAP
):
for field in ctype.inputs["fields"]:
if field["id"] == "host":
field["help_text"] = help_text

ctype.save(update_fields=["inputs"])


class Migration(migrations.Migration):
dependencies = [
("core", "0050_setting"),
]

operations = [
migrations.RunPython(update_credential_type, backward_credential_type),
]
116 changes: 116 additions & 0 deletions tests/unit/migrations/test_update_credential_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Copyright 2024 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, Union

import pytest
from django.core.management import call_command

from aap_eda.core import enums, models
from aap_eda.core.management.commands.create_initial_data import (
NEW_HELP_TEXT,
ORIG_HELP_TEXT,
)

INPUTS = {
"fields": [
{
"id": "host",
"label": "Red Hat Ansible Automation Platform",
"type": "string",
"help_text": ORIG_HELP_TEXT,
},
{
"id": "username",
"label": "Username",
"type": "string",
"help_text": (
"Red Hat Ansible Automation Platform username id"
" to authenticate as.This should not be set if"
" an OAuth token is being used."
),
},
{
"id": "password",
"label": "Password",
"type": "string",
"secret": True,
},
{
"id": "oauth_token",
"label": "OAuth Token",
"type": "string",
"secret": True,
"help_text": (
"An OAuth token to use to authenticate with."
"This should not be set if username/password"
" are being used."
),
},
{
"id": "verify_ssl",
"label": "Verify SSL",
"type": "boolean",
"secret": False,
},
],
"required": ["host"],
}

INJECTORS = {
"env": {
"TOWER_HOST": "{{host}}",
"TOWER_USERNAME": "{{username}}",
"TOWER_PASSWORD": "{{password}}",
"TOWER_VERIFY_SSL": "{{verify_ssl}}",
"TOWER_OAUTH_TOKEN": "{{oauth_token}}",
"CONTROLLER_HOST": "{{host}}",
"CONTROLLER_USERNAME": "{{username}}",
"CONTROLLER_PASSWORD": "{{password}}",
"CONTROLLER_VERIFY_SSL": "{{verify_ssl}}",
"CONTROLLER_OAUTH_TOKEN": "{{oauth_token}}",
}
}


@pytest.fixture
def rollback_migration():
call_command("migrate", "core", "0050")
yield
call_command("migrate")


@pytest.mark.django_db
def test_migration(rollback_migration):
credential_type = _prepare_aap_credetial_type()

call_command("migrate", "core", "0051")
credential_type.refresh_from_db()
assert _get_help_text(credential_type) == list(NEW_HELP_TEXT)


def _get_help_text(
credential_type: models.CredentialType,
) -> Union[str, List[str]]:
for field in credential_type.inputs["fields"]:
if field["id"] == "host":
return field["help_text"]


def _prepare_aap_credetial_type() -> models.CredentialType:
return models.CredentialType.objects.create(
name=enums.DefaultCredentialType.AAP,
inputs=INPUTS,
injectors=INJECTORS,
)

0 comments on commit b83ec06

Please sign in to comment.