Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,16 @@ def get(self, request, project, app_slug, app_id):
username, password = None, None
if instance.get_app_status() == "Running":
subdomain = instance.subdomain
# If release name contains chart name it will be used as a full name.
# see here: https://github.com/bitnami/charts/blob/main/bitnami/common/templates/_names.tpl#L21-L37
if "mlflow" in subdomain.subdomain.lower():
secret_name = f"{subdomain.subdomain}-tracking"
else:
secret_name = f"{subdomain.subdomain}-mlflow-tracking"
Comment on lines +323 to +328
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work, thank you!

I think this will be more intuitive:)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you! Yes, I agree :)

username = subprocess.run(
(
"kubectl get secret "
f"--namespace {settings.NAMESPACE} {subdomain.subdomain}-mlflow-tracking "
f"--namespace {settings.NAMESPACE} {secret_name} "
'-o jsonpath="{.data.admin-user}"'
).split(),
check=True,
Expand All @@ -334,7 +340,7 @@ def get(self, request, project, app_slug, app_id):
password = subprocess.run(
(
"kubectl get secret "
f"--namespace {settings.NAMESPACE} {subdomain.subdomain}-mlflow-tracking "
f"--namespace {settings.NAMESPACE} {secret_name} "
'-o jsonpath="{.data.admin-password}"'
).split(),
check=True,
Expand Down
71 changes: 54 additions & 17 deletions templates/apps/secrets_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ <h1 class="h3 mb-3 card-title">MLflow is not provisioned yet</h1>
<h1 class="h3 mb-3 card-title">Your MLflow Credentials</h1>
<p class="card-text">Use the credentials below to access MLflow.</p>

<div class="mb-3">
<label for="mlflow-username" class="form-label">Username</label>
<div class="input-group">
<input type="text" id="mlflow-username" class="form-control" value="{{ mlflow_username }}" readonly>
<button class="btn btn-outline-secondary" onclick="copyToClipboard('mlflow-username')">Copy</button>
<!-- Updated Username Section -->
<div class="mb-3">
<label class="form-label">Username</label>
<div class="d-flex align-items-center gap-2">
<code class="p-2 bg-light rounded flex-grow-1" id="mlflow-username">{{ mlflow_username }}</code>
<button class="btn btn-outline-secondary" onclick="copyToClipboard('mlflow-username')">Copy</button>
</div>
</div>
</div>

<div class="mb-3">
<label for="mlflow-password" class="form-label">Password</label>
<div class="input-group">
<input type="text" id="mlflow-password" class="form-control" value="{{ mlflow_password }}" readonly>
<button class="btn btn-outline-secondary" onclick="copyToClipboard('mlflow-password')">Copy</button>
<!-- Updated Password Section -->
<div class="mb-3">
<label class="form-label">Password</label>
<div class="d-flex align-items-center gap-2">
<code class="p-2 bg-light rounded flex-grow-1" id="mlflow-password">{{ mlflow_password }}</code>
<button class="btn btn-outline-secondary" onclick="copyToClipboard('mlflow-password')">Copy</button>
</div>
</div>
</div>

<div class="text-center mt-4">
<a href="{{ mlflow_url }}" target="_blank" class="btn btn-dark">Open MLflow</a>
Expand Down Expand Up @@ -70,12 +72,47 @@ <h4 class="h5 mt-4">How to Use These Credentials</h4>
</div>

<script>
function copyToClipboard(elementId) {
var copyText = document.getElementById(elementId);
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
navigator.clipboard.writeText(copyText.value);

async function copyToClipboard(elementId) {
const el = document.getElementById(elementId);
const text = el.textContent;
const tempTextArea = document.createElement('textarea');

try {
// Modern clipboard API (requires HTTPS)
await navigator.clipboard.writeText(text);

// Visual feedback
const btn = document.querySelector(`button[onclick*='${elementId}']`);
btn.classList.add('btn-success');
setTimeout(() => btn.classList.remove('btn-success'), 1000);

} catch (err) {
// Fallback for older browsers/HTTP
try {
tempTextArea.value = text;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand('copy');

// Fallback visual feedback
const btn = document.querySelector(`button[onclick*='${elementId}']`);
btn.classList.add('btn-info');
setTimeout(() => btn.classList.remove('btn-info'), 1000);

} catch (fallbackErr) {
// Ultimate fallback: show text and prompt manual copy
tempTextArea.style.position = 'fixed';
tempTextArea.style.top = '10px';
tempTextArea.style.left = '10px';
tempTextArea.style.zIndex = 1000;
alert('Press Ctrl/Cmd+C to copy:\n\n' + text);
}
} finally {
document.body.removeChild(tempTextArea);
}
}

</script>
{% endif %}
{% endblock %}