Skip to content

Commit

Permalink
Merge branch 'master' into konflux/mintmaker/master/coverage-7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellen-Yi-Dong authored Jan 21, 2025
2 parents 46f345f + 35d0da3 commit 2dab1ef
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 35 deletions.
16 changes: 8 additions & 8 deletions .tekton/insights-rbac-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ spec:
- name: name
value: init
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-init:0.2@sha256:90dda596d44b3f861889da2fba161dff34c6116fe76c3989e3f84262ea0f29cd
value: quay.io/konflux-ci/tekton-catalog/task-init:0.2@sha256:b76b563510ad9db0049e9b4512a152aef2bb51fb714363b6aa592744a580bcbd
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -286,7 +286,7 @@ spec:
- name: name
value: prefetch-dependencies-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-prefetch-dependencies-oci-ta:0.1@sha256:994f816e36ac832f4020647afd69223a015c84c503f925013c573fed52f05420
value: quay.io/konflux-ci/tekton-catalog/task-prefetch-dependencies-oci-ta:0.1@sha256:8fb092dae7109ac211d8b98413d9bc0c71c14f64644ce239676383576f861a86
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -327,7 +327,7 @@ spec:
- name: name
value: buildah-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-buildah-oci-ta:0.3@sha256:11b9ce26fd2933ccc81ca3f983e094ec54326a2e0aaf8bdcc4c0b8fea1a42c53
value: quay.io/konflux-ci/tekton-catalog/task-buildah-oci-ta:0.3@sha256:b1cdafdac20b33cb6ccbad64fa91abc0aa673f1bdfcf95abd5cf230e0c4ea2b4
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -356,7 +356,7 @@ spec:
- name: name
value: build-image-index
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-build-image-index:0.1@sha256:479775c8655d815fb515aeb97efc0e64284a8520c452754981970900b937a393
value: quay.io/konflux-ci/tekton-catalog/task-build-image-index:0.1@sha256:09344e6bda708f48ef759bbe84bce99515549f4cfdcbe89e417f695c19463260
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -399,7 +399,7 @@ spec:
- name: name
value: source-build-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-source-build-oci-ta:0.1@sha256:75e882bf1619dd45a4043060ce42a6ad3ce781264ade5b7f66a1d994ee159126
value: quay.io/konflux-ci/tekton-catalog/task-source-build-oci-ta:0.1@sha256:bd191e50b2eb7e3996d7f24e38fa44b4552c142920b540fb7f3dc104e508a68f
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -493,7 +493,7 @@ spec:
- name: name
value: sast-snyk-check-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-sast-snyk-check-oci-ta:0.3@sha256:af93b35e6e71a6ff7f3785ad8d8497b11204a5c0c33ab1a78b44f9d43f49c7a5
value: quay.io/konflux-ci/tekton-catalog/task-sast-snyk-check-oci-ta:0.3@sha256:9172196136831a61b9039ea4498fcdc71d6adc86d9694f236bea7b2a85488cd3
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -535,7 +535,7 @@ spec:
- name: name
value: apply-tags
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-apply-tags:0.1@sha256:2c2d88c07623b2d25163994ded6e9f29205ea5bbab090f4c86379739940028b9
value: quay.io/konflux-ci/tekton-catalog/task-apply-tags:0.1@sha256:46f4471a86130c146a6e14124f175d6ef1ddb4b80ac51e7957d78a3facb6261b
- name: kind
value: task
resolver: bundles
Expand All @@ -558,7 +558,7 @@ spec:
- name: name
value: push-dockerfile-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-push-dockerfile-oci-ta:0.1@sha256:98ccae6ac132ab837fc51a70514be5fca656e09d6d4ad93230bd10f0119258aa
value: quay.io/konflux-ci/tekton-catalog/task-push-dockerfile-oci-ta:0.1@sha256:6cfb72a0b5c382a3584af322d11f3ae855d07eb72a6ee2253de7b9512a0c21a5
- name: kind
value: task
resolver: bundles
Expand Down
16 changes: 8 additions & 8 deletions .tekton/insights-rbac-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ spec:
- name: name
value: init
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-init:0.2@sha256:90dda596d44b3f861889da2fba161dff34c6116fe76c3989e3f84262ea0f29cd
value: quay.io/konflux-ci/tekton-catalog/task-init:0.2@sha256:b76b563510ad9db0049e9b4512a152aef2bb51fb714363b6aa592744a580bcbd
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -174,7 +174,7 @@ spec:
- name: name
value: prefetch-dependencies-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-prefetch-dependencies-oci-ta:0.1@sha256:994f816e36ac832f4020647afd69223a015c84c503f925013c573fed52f05420
value: quay.io/konflux-ci/tekton-catalog/task-prefetch-dependencies-oci-ta:0.1@sha256:8fb092dae7109ac211d8b98413d9bc0c71c14f64644ce239676383576f861a86
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -215,7 +215,7 @@ spec:
- name: name
value: buildah-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-buildah-oci-ta:0.3@sha256:11b9ce26fd2933ccc81ca3f983e094ec54326a2e0aaf8bdcc4c0b8fea1a42c53
value: quay.io/konflux-ci/tekton-catalog/task-buildah-oci-ta:0.3@sha256:b1cdafdac20b33cb6ccbad64fa91abc0aa673f1bdfcf95abd5cf230e0c4ea2b4
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -244,7 +244,7 @@ spec:
- name: name
value: build-image-index
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-build-image-index:0.1@sha256:479775c8655d815fb515aeb97efc0e64284a8520c452754981970900b937a393
value: quay.io/konflux-ci/tekton-catalog/task-build-image-index:0.1@sha256:09344e6bda708f48ef759bbe84bce99515549f4cfdcbe89e417f695c19463260
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -287,7 +287,7 @@ spec:
- name: name
value: source-build-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-source-build-oci-ta:0.1@sha256:75e882bf1619dd45a4043060ce42a6ad3ce781264ade5b7f66a1d994ee159126
value: quay.io/konflux-ci/tekton-catalog/task-source-build-oci-ta:0.1@sha256:bd191e50b2eb7e3996d7f24e38fa44b4552c142920b540fb7f3dc104e508a68f
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -381,7 +381,7 @@ spec:
- name: name
value: sast-snyk-check-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-sast-snyk-check-oci-ta:0.3@sha256:af93b35e6e71a6ff7f3785ad8d8497b11204a5c0c33ab1a78b44f9d43f49c7a5
value: quay.io/konflux-ci/tekton-catalog/task-sast-snyk-check-oci-ta:0.3@sha256:9172196136831a61b9039ea4498fcdc71d6adc86d9694f236bea7b2a85488cd3
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -423,7 +423,7 @@ spec:
- name: name
value: apply-tags
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-apply-tags:0.1@sha256:2c2d88c07623b2d25163994ded6e9f29205ea5bbab090f4c86379739940028b9
value: quay.io/konflux-ci/tekton-catalog/task-apply-tags:0.1@sha256:46f4471a86130c146a6e14124f175d6ef1ddb4b80ac51e7957d78a3facb6261b
- name: kind
value: task
resolver: bundles
Expand All @@ -446,7 +446,7 @@ spec:
- name: name
value: push-dockerfile-oci-ta
- name: bundle
value: quay.io/konflux-ci/tekton-catalog/task-push-dockerfile-oci-ta:0.1@sha256:98ccae6ac132ab837fc51a70514be5fca656e09d6d4ad93230bd10f0119258aa
value: quay.io/konflux-ci/tekton-catalog/task-push-dockerfile-oci-ta:0.1@sha256:6cfb72a0b5c382a3584af322d11f3ae855d07eb72a6ee2253de7b9512a0c21a5
- name: kind
value: task
resolver: bundles
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ django = "==4.2.18"
django-filter = "==22.1"
requests = "==2.32.3"
django-tenants = "==3.5.0"
django-cors-headers = "==3.13.0"
django-cors-headers = "==4.6.0"
djangorestframework-csv = "==2.1.1"
grpcio = "==1.68.1"
grpcio-status = "==1.68.1"
Expand Down
30 changes: 15 additions & 15 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rbac/internal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
path("api/utils/bootstrap_tenant/", views.bootstrap_tenant),
path("api/utils/migration_resources/", views.migration_resources),
path("api/utils/reset_imported_tenants/", views.reset_imported_tenants),
path("api/utils/resource_definitions/", views.correct_resource_definitions),
]

urlpatterns.extend(integration_urlpatterns)
52 changes: 51 additions & 1 deletion rbac/internal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from django.utils.html import escape
from internal.utils import delete_bindings
from management.cache import TenantCache
from management.models import Group, Permission, Role
from management.models import Group, Permission, ResourceDefinition, Role
from management.principal.proxy import (
API_TOKEN_HEADER,
CLIENT_ID_HEADER,
Expand Down Expand Up @@ -781,3 +781,53 @@ def roles(request, uuid: str) -> HttpResponse:
def trigger_error(request):
"""Trigger an error to confirm Sentry is working."""
raise SentryDiagnosticError


def correct_resource_definitions(request):
"""Get/Fix resourceDefinitions with incorrect attributeFilters.
Attribute filters with lists must use 'in' operation. Those with a single string must use 'equal'
GET /_private/api/utils/resource_definitions
PATCH /_private/api/utils/resource_definitions
"""
list_query = """ FROM management_resourcedefinition
WHERE "attributeFilter"->>'operation' = 'equal'
AND jsonb_typeof("attributeFilter"->'value') = 'array';"""

string_query = """ from management_resourcedefinition WHERE "attributeFilter"->>'operation' = 'in'
AND jsonb_typeof("attributeFilter"->'value') = 'string';"""

if request.method == "GET":
with connection.cursor() as cursor:

cursor.execute("SELECT COUNT(*)" + list_query)
count = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*)" + string_query)
count += cursor.fetchone()[0]

return HttpResponse(f"{count} resource definitions would be corrected", status=200)
elif request.method == "PATCH":
count = 0
with connection.cursor() as cursor:

cursor.execute("SELECT id " + list_query)
result = cursor.fetchall()
for id in result:
resource_definition = ResourceDefinition.objects.get(id=id[0])
resource_definition.attributeFilter["operation"] = "in"
resource_definition.save()
count += 1

cursor.execute("SELECT id " + string_query)
result = cursor.fetchall()
for id in result:
resource_definition = ResourceDefinition.objects.get(id=id[0])
resource_definition.attributeFilter["operation"] = "equal"
resource_definition.save()
count += 1

return HttpResponse(f"Updated {count} bad resource definitions", status=200)

return HttpResponse('Invalid method, only "GET" or "PATCH" are allowed.', status=405)
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ click-plugins==1.1.1
click-repl==0.3.0; python_version >= '3.6'
cryptography==44.0.0; python_version >= '3.7' and python_full_version not in '3.9.0, 3.9.1'
django==4.2.18; python_version >= '3.8'
django-cors-headers==3.13.0; python_version >= '3.7'
django-cors-headers==4.6.0; python_version >= '3.9'
django-environ==0.10.0; python_version >= '3.5' and python_version < '4'
django-extensions==3.2.3; python_version >= '3.6'
django-filter==22.1; python_version >= '3.7'
Expand All @@ -40,7 +40,7 @@ kombu==5.5.0rc2; python_version >= '3.8'
markupsafe==3.0.2; python_version >= '3.9'
packaging==24.2; python_version >= '3.8'
prometheus-client==0.15.0; python_version >= '3.6'
prompt-toolkit==3.0.48; python_full_version >= '3.7.0'
prompt-toolkit==3.0.50; python_full_version >= '3.8.0'
protobuf==5.29.3; python_version >= '3.8'
protoc-gen-validate==1.0.4; python_version >= '3.6'
psycopg2==2.9.10; python_version >= '3.8'
Expand Down
Loading

0 comments on commit 2dab1ef

Please sign in to comment.