Skip to content

Commit

Permalink
Bugfix/minio date issue (#129)
Browse files Browse the repository at this point in the history
* Creating a default bucket using correct minio client command
* Renaming variables
* Update toml editor in workflow
* Using django built-in password generator
  • Loading branch information
sandstromviktor authored Jan 24, 2024
1 parent 02d5d6c commit 097612d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ jobs:
type=raw,value={{date 'YYYYMMDD'}},prefix=${{ github.ref_name }}-
- name: Set the build date project toml file
uses: ciiiii/toml-editor@1.0.0
uses: sandstromviktor/toml-editor@2.0.0
with:
file: "pyproject.toml"
key: "tool.serve.build-date"
value: ${{ env.BUILD_DATE }}

- name: Set the git tag or branch name in the project toml file
uses: ciiiii/toml-editor@1.0.0
uses: sandstromviktor/toml-editor@2.0.0
with:
file: "pyproject.toml"
key: "tool.serve.gitref"
value: ${{ github.ref_name }}

- name: Set the image tag in the project toml file
uses: ciiiii/toml-editor@1.0.0
uses: sandstromviktor/toml-editor@2.0.0
with:
file: "pyproject.toml"
key: "tool.serve.imagetag"
Expand Down
12 changes: 3 additions & 9 deletions apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db.models import Q
from django.http import HttpResponseForbidden, JsonResponse
from django.shortcuts import HttpResponseRedirect, render, reverse
from django.utils.crypto import get_random_string
from django.utils.decorators import method_decorator
from django.views import View
from guardian.decorators import permission_required_or_403
Expand Down Expand Up @@ -424,15 +425,8 @@ def get(self, request, user, project, app_slug, data=[], wait=False, call=False)
return HttpResponseForbidden()

if app.slug == "minio":

def generate_password(len: int) -> str:
return "".join(
secrets.choice(string.octdigits + string.ascii_uppercase + string.ascii_lowercase + string.digits)
for i in range(len)
)

MINIO_USERNAME = generate_password(8)
MINIO_PASSWORD = generate_password(8)
minio_username = get_random_string(8)
minio_password = get_random_string(8)

do_display_description_field = app.category is not None and app.category.name.lower() == "serve"

Expand Down
2 changes: 1 addition & 1 deletion charts/apps/minio/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ spec:
sleep 5
mc alias set local http://127.0.0.1:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD}
mc admin user add local {{ .Values.credentials.access_key }} {{ .Values.credentials.secret_key }}
mc mb /data/data-bucket
mc mb local/data-bucket
mc admin policy attach local readwrite --user {{ .Values.credentials.access_key }} || true
hostname: {{ .Release.Name }}-minio
restartPolicy: Always
Expand Down
4 changes: 3 additions & 1 deletion common/management/commands/add_locust_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def add_arguments(self, parser):
parser.add_argument("num_users", type=int)

def handle(self, *args, **options):
users_created_counter = 0
for i in range(1, options["num_users"] + 1):
username = f"locust_test_user_{i}"
email = f"locust_test_user_{i}@test.uu.net"
Expand All @@ -20,7 +21,8 @@ def handle(self, *args, **options):
user = User.objects.create_user(username, email, password)
user.is_active = True
user.save()
users_created_counter += 1
except IntegrityError:
self.stdout.write(self.style.WARNING("User with the given username or email already exists."))

self.stdout.write(self.style.SUCCESS(f"Successfully created {i} users"))
self.stdout.write(self.style.SUCCESS(f"Successfully created {users_created_counter} users"))
8 changes: 8 additions & 0 deletions customtags/templatetags/get_dict_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@

@register.filter
def dict_key(dictionary, key):
"""
Allows fetching of dictionary values where keys have whitespace in templates
Example:
my_dict = {"some key": "some value"}
In the template you can not use {{ my_dict.some key }}, so with this filter you can do
{{ my_dict|dict_key:"some key" }}
"""
return dictionary.get(key, None)
5 changes: 2 additions & 3 deletions templates/apps/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% block title %}Create {{ app.name }}{% endblock %}
{% load static %}
{% load custom_tags %}
{% load get_dict_key %}

{% block content %}
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
Expand Down Expand Up @@ -282,12 +281,12 @@ <h6> {{ vals.meta_title }}</h6>

{% if subval.type == "minio-username" %}
<label class="form-label">{{ subval.title }}</label>
<input type="text" id="{{ subkey }}" name="{{ key }}.{{ subkey }}" value="{{ MINIO_USERNAME }}" class="form-control">
<input type="text" id="{{ subkey }}" name="{{ key }}.{{ subkey }}" value="{{ minio_username }}" class="form-control">
{% endif %}

{% if subval.type == "minio-password" %}
<label class="form-label">{{ subval.title }}</label>
<input type="text" id="{{ subkey }}" name="{{ key }}.{{ subkey }}" value="{{ MINIO_PASSWORD }}" class="form-control">
<input type="text" id="{{ subkey }}" name="{{ key }}.{{ subkey }}" value="{{ minio_password }}" class="form-control">
{% endif %}


Expand Down
1 change: 0 additions & 1 deletion templates/projects/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% load static %}
{% load can_create_app %}
{% load custom_tags %}
{% load get_dict_key %}
{% block title %}{{ project.name }}{% endblock %}

{% block content %}
Expand Down

0 comments on commit 097612d

Please sign in to comment.