Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.
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
26 changes: 20 additions & 6 deletions cmd/server/assets/codes/bulk-issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@

<script type="text/javascript">
let total = 0;
// Common error codes which should cancel the whole upload.
let stopUploadingCodes = [
'429', // too many requests
'403', // forbidden
'404', // not-found
'503', // unavailable
];

$(function() {
let $form = $('#form');
Expand Down Expand Up @@ -221,14 +228,21 @@
$tableBody.append(row);
}

await uploadBatch(batch).catch(err => { });
$startAt.val(i + 1);
if (cancelUpload && total > 0) {
flash.warning("Successfully issued " + total + " codes."
+ (rows.length - i) + " remaining.");
await uploadBatch(batch).catch(err => {
if (err && stopUploadingCodes.includes(err.status)) {
flash.alert("Code " + err.status + " detected. Canceling remaining upload.");
cancelUpload = true;
}
});

if (cancelUpload) {
if (total > 0) {
flash.warning("Successfully issued " + total + " codes."
+ (rows.length - i) + " remaining.");
}
break;
}

$startAt.val(i + 1);
let percent = Math.floor((i + 1) * 100 / rows.length) + "%";
$progress.width(percent);
$progress.html(percent);
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/issueapi/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/google/exposure-notifications-server/pkg/logging"
"github.com/google/exposure-notifications-server/pkg/timeutils"
"github.com/google/exposure-notifications-verification-server/internal/project"
"github.com/google/exposure-notifications-verification-server/pkg/api"
"github.com/google/exposure-notifications-verification-server/pkg/controller"
"github.com/google/exposure-notifications-verification-server/pkg/database"
Expand Down Expand Up @@ -229,7 +230,8 @@ func (c *Controller) HandleIssue() http.Handler {

// If there is a client-provided UUID, check if a code has already been issued.
// this prevents us from consuming quota on conflict.
if request.UUID != "" {
rUUID := project.TrimSpaceAndNonPrintable(request.UUID)
if rUUID != "" {
if code, err := realm.FindVerificationCodeByUUID(c.db, request.UUID); err != nil {
if !database.IsNotFound(err) {
controller.InternalError(w, r, c.h, err)
Expand Down Expand Up @@ -305,7 +307,7 @@ func (c *Controller) HandleIssue() http.Handler {
IssuingUser: user,
IssuingApp: authApp,
RealmID: realm.ID,
UUID: request.UUID,
UUID: rUUID,
}

code, longCode, uuid, err := codeRequest.Issue(ctx, c.config.GetCollisionRetryCount())
Expand Down