GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Google Drive: explain setup failures, use an existing project at Goog… · gitmoot/keyring@030f6c6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • deploy/cloudflare
    • README.md
    • src
      • index.ts
  • internal
    • consent
      • consent.go
      • consent_test.go
      • google.go
    • googlelogin
      • command.go
      • controller.go
      • controller_test.go
      • setup.go
      • state.go
    • instance
      • google.go
      • google_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎deploy/cloudflare/README.md‎

Copy file name to clipboardExpand all lines: deploy/cloudflare/README.md
+38-2Lines changed: 38 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -430,18 +430,54 @@ instances into fixed Google services. For existing instances, call
430430
proof and admin bearer token, then request the normal `service: drive` connection
431431
link. Provisioning is atomic and repeatable: it preserves the router token and
432432
unrelated services/grants. It returns `200 {"version":N}` only after sealed-state
433-
sync, `400` for an invalid/nonempty body, `401` for failed authentication, `404`
433+
sync, `400` for an invalid body or unknown field, `401` for failed authentication, `404`
434434
for an unknown instance, `409` for incompatible reserved service/grant definitions,
435435
and the existing `502` failure shape when the container or state save is unavailable.
436436
Provisioning is not sign-in.
437437

438+
`{"project": "<existing project ID>"}` instead of `{}` only chooses a Google Cloud
439+
project the signed-in account already owns and that still exists (an older
440+
`drivekey-…` project listed by `gcloud projects list`, or any other), for when
441+
Google will not create a new one (see `project_limit_reached` below). It
442+
provisions nothing; only a body without `project` provisions. An invalid ID
443+
(not 6-30 lowercase letters, digits or hyphens, starting with a letter, not
444+
ending with a hyphen; `""` and `null` included) gets `400`; without a
445+
retained sign-in whose setup has not finished, or while a connection runs, it
446+
gets `409`. Both change nothing. On success (`200 {"version":N}`) the ID is
447+
sealed like a generated one; the owner then presses Retry on the Drive page or
448+
opens a new `drive` link. The failed Drive page also offers the same choice
449+
whenever the sign-in is retained, together with Retry. Setup only checks that
450+
project is ACTIVE and reachable, enables Drive and Sheets and probes; it never
451+
creates or replaces a chosen project. Several keyrings may share one project: it
452+
only carries API quota (`X-Goog-User-Project`); every sign-in and credential
453+
stays per keyring.
454+
438455
The one-time link opens a browser-bound `/connect/<id>/g/<flow>` page. The person
439456
opens Google's URL and enters its verification code **only on that private page**,
440457
never in chat. Login runs in that person's container with the SDK's own OAuth
441458
client and `--enable-gdrive-access`. Setup retains one project ID across retries,
442459
enables Drive and Sheets, and checks the selected identity. Cloud terms refusal
443460
links to Google Cloud Console and offers an explicit retry without discarding
444-
the completed login. No billing account is attached. This relies on Google
461+
the completed login. A failed setup shows its code and the step that failed
462+
(`project_describe`, `project_create`, `services_enable`, `access_token`) on the
463+
page and in `failing` as `"<code> (<step>)"`, never command output:
464+
465+
| Code | Meaning and what to do |
466+
|---|---|
467+
| `project_limit_reached` | The account is at Google's project limit (deleted projects count for 30 days). Enter the ID of a project the account already owns, such as an older `drivekey-…` one, on the page, then Retry. |
468+
| `project_not_active` | The retained project is deleted or pending deletion: restore it in Cloud Console → Manage resources, enter another owned project ID, or disconnect Drive to start with a new project. |
469+
| `project_not_accessible` | Google refused even a fresh project ID. Retry later, enter an owned project ID, or disconnect and connect again. |
470+
| `project_not_found` | The chosen project is not visible to this account; check the ID and owner, then enter it again. |
471+
| `google_command_failed` | A Google Cloud command failed; retry, and check the project in Cloud Console if it repeats. |
472+
| `api_disabled` | Drive/Sheets APIs are not enabled yet; wait a few minutes, then retry. |
473+
| `api_probe_failed` | Google refused the setup test call; after a sign-out everywhere or password change, disconnect and connect again, otherwise retry. |
474+
| `connection_failed` | Anything else; retry or ask for a new link. |
475+
476+
Google answers `projects describe` identically for a project deleted for good
477+
and one the account cannot reach, and `projects create` refuses both IDs as "already in use"
478+
(Google never reuses an ID). So when a retained ID is refused that way, setup
479+
seals one fresh ID and creates it once; it does not try to tell the cases apart.
480+
No billing account is attached. This relies on Google
445481
continuing to permit the SDK flow; it does not bypass reauthentication or policy.
446482

447483
| Service | Methods | Path prefixes |
Collapse file

‎deploy/cloudflare/src/index.ts‎

Copy file name to clipboardExpand all lines: deploy/cloudflare/src/index.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ interface Reply {
242242
unlocked?: boolean;
243243
keys?: string[];
244244
services?: Record<string, { key: string; auth?: string; google_account?: string; extra_headers?: Record<string, string> }>;
245-
google?: { phase: string; busy: boolean; error?: string };
245+
google?: { phase: string; busy: boolean; error?: string; step?: string };
246246
failing?: Record<string, string>;
247247
reconnect_required?: Record<string, boolean>;
248248
roles?: Record<string, { access?: Record<string, unknown>; expires?: string }>;
@@ -604,12 +604,14 @@ export class KeyringInstance extends DurableObject<Env> {
604604
return this.withInstance(async (m) => {
605605
const s = await this.adminJSON(m, "GET", "/status");
606606
const keys = new Set<string>(s.keys ?? []);
607+
// A failed setup names its step: "google_command_failed (project_create)".
608+
const googleError = s.google?.error ? s.google.error + (s.google.step ? ` (${s.google.step})` : "") : undefined;
607609
const list = Object.entries(s.services ?? {})
608610
.map(([name, svc]) => {
609611
const google = svc.google_account === "me" && (svc.auth === "gcloud" || svc.auth === "gcloud-login");
610612
const credentialsPresent = keys.has(svc.key) && Object.values(svc.extra_headers ?? {}).every((key) => keys.has(key));
611613
return { name, connected: google ? s.google?.phase === "connected" : credentialsPresent && !s.reconnect_required?.[name],
612-
failing: google ? s.google?.error ?? s.failing?.[name] ?? (s.google?.phase === "connected" ? null : "Google connection is not ready") : s.failing?.[name] ?? null };
614+
failing: google ? googleError ?? s.failing?.[name] ?? (s.google?.phase === "connected" ? null : "Google connection is not ready") : s.failing?.[name] ?? null };
613615
})
614616
.sort((a, b) => a.name.localeCompare(b.name));
615617
return { body: { services: list } };
Collapse file

‎internal/consent/consent.go‎

Copy file name to clipboardExpand all lines: internal/consent/consent.go
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,9 @@ type pageData struct {
10291029
Status int
10301030
Problem bool
10311031
Google, GoogleCode, GoogleRetry, GoogleTerms, Refresh bool
1032-
GoogleURL, GoogleAccount, GoogleProject string
1032+
// GoogleChooseProject offers an existing project ID with the retry.
1033+
GoogleChooseProject bool
1034+
GoogleURL, GoogleAccount, GoogleProject string
10331035
// GoogleStep is the Google connection's current step while it runs
10341036
// (1 sign-in, 2 project setup), shown as a list; 0 shows none.
10351037
GoogleStep int
@@ -1119,6 +1121,9 @@ input:focus,select:focus{border-color:var(--blue);box-shadow:0 0 0 3px rgba(36,1
11191121
<input id="code" type="password" name="code" required maxlength="4096" autocomplete="off" spellcheck="false">
11201122
<button class="btn" type="submit">Finish Google sign-in</button>
11211123
{{else if .GoogleRetry}}<input type="hidden" name="action" value="retry">
1124+
{{if .GoogleChooseProject}}<label for="project">Use an existing Google Cloud project ID</label>
1125+
<input id="project" name="project" minlength="6" maxlength="30" pattern="[a-z][a-z0-9\-]{4,28}[a-z0-9]" autocomplete="off" spellcheck="false" placeholder="drivekey-…">
1126+
<p class="hint">Optional. Find it in Google Cloud Console under Manage resources; it must belong to the Google account above. One project can serve several keyrings: it only carries API quota, never your sign-in.</p>{{end}}
11221127
<button class="btn" type="submit">Retry connection</button>
11231128
{{else if .SignIn}}<p>You will sign in on the provider's own page. Your password is never seen here.</p>
11241129
<button class="btn" type="submit">Sign in and connect</button>
Collapse file

‎internal/consent/consent_test.go‎

Copy file name to clipboardExpand all lines: internal/consent/consent_test.go
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"testing"
1717
"time"
1818

19+
"github.com/gitmoot/keyring/internal/googlelogin"
1920
"github.com/gitmoot/keyring/internal/policy"
2021
)
2122

@@ -927,3 +928,23 @@ func TestReturnURLAfterConnecting(t *testing.T) {
927928
t.Fatalf("plain value page: %d %s", w.Code, w.Body)
928929
}
929930
}
931+
932+
// Every setup failure the owner can hit needs its own advice; falling back to
933+
// the generic text hid deleted projects and refused sign-ins (#184).
934+
func TestGoogleSetupFailuresExplainWhatToDo(t *testing.T) {
935+
generic := googleFailureMessage(googlelogin.View{Error: "connection_failed"})
936+
for code, advice := range map[string]string{
937+
"google_command_failed": "check the project in Google Cloud Console",
938+
"project_not_active": "Manage resources",
939+
"project_not_accessible": "would not create a new Drive project",
940+
"project_limit_reached": "Enter the ID of a project you already own",
941+
"project_not_found": "did not find that project",
942+
"api_disabled": "not enabled yet",
943+
"api_probe_failed": "disconnect Drive and connect again",
944+
} {
945+
message := googleFailureMessage(googlelogin.View{Phase: "failed", Error: code, Step: "project_create"})
946+
if message == generic || !strings.Contains(message, advice) || !strings.HasSuffix(message, "(Failed step: project_create.)") {
947+
t.Errorf("%s: %q", code, message)
948+
}
949+
}
950+
}
Collapse file

‎internal/consent/google.go‎

Copy file name to clipboardExpand all lines: internal/consent/google.go
+45-15Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (s *Server) startGoogle(w http.ResponseWriter, r *http.Request, l *link, h
3030
return
3131
}
3232
state, browser := randomToken(), randomToken()
33-
if err := s.google.Start(state, l.googleEpoch); err != nil {
33+
if err := s.google.Start(state, l.googleEpoch, ""); err != nil {
3434
s.mu.Unlock()
3535
render(w, http.StatusConflict, pageData{Message: err.Error()})
3636
return
@@ -89,7 +89,10 @@ func (s *Server) googlePage(w http.ResponseWriter, r *http.Request, id string, p
8989
return
9090
}
9191
if r.PostForm.Get("action") == "retry" {
92-
err = s.google.Start(id, f.googleEpoch)
92+
// An existing project the account owns, when Google will not
93+
// create another one. Optional; not a secret. Choosing it and
94+
// retrying are one operation: a refused retry chooses nothing.
95+
err = s.google.Start(id, f.googleEpoch, strings.TrimSpace(r.PostForm.Get("project")))
9396
} else {
9497
err = s.google.Submit(id, r.PostForm.Get("code"))
9598
}
@@ -119,19 +122,10 @@ func (s *Server) googlePage(w http.ResponseWriter, r *http.Request, id string, p
119122
case "failed":
120123
data.Problem = true
121124
data.Form, data.GoogleRetry = true, true
122-
switch view.Error {
123-
case "cloud_terms_not_accepted":
124-
data.GoogleTerms = true
125-
data.Message = "Google requires you to accept its Cloud terms before creating your project."
126-
case "login_required", "wrong_google_account":
127-
data.Message = "Google sign-in must be completed with the intended account. Retry, or disconnect first to change accounts."
128-
case "rate_limited":
129-
data.Message = "Google limited project setup requests. Wait a few minutes, then retry; the same project ID is retained."
130-
case "connection_timed_out":
131-
data.Message = "Connection timed out. Retry or ask for a new link; completed login and project progress are retained."
132-
default:
133-
data.Message = "Google connection could not finish. Retry or ask for a new link; completed progress is retained."
134-
}
125+
data.GoogleTerms = view.Error == "cloud_terms_not_accepted"
126+
// Whatever failed, a retained sign-in may still take another project.
127+
data.GoogleChooseProject = view.ProjectChoosable
128+
data.Message = googleFailureMessage(view)
135129
case "setting_up_project":
136130
data.GoogleStep = 2
137131
data.Message = "Setting up Drive and Sheets in your Google account. This can take a few minutes; keep this page open."
@@ -149,3 +143,39 @@ func googlePagePath(rest string) (string, bool) {
149143
id, ok := strings.CutPrefix(rest, "/g/")
150144
return id, ok && id != "" && !strings.Contains(id, "/")
151145
}
146+
147+
// googleFailureMessage tells the owner what each failed connection code
148+
// means and what to do. The step is a fixed name, never command output.
149+
func googleFailureMessage(view googlelogin.View) string {
150+
var message string
151+
switch view.Error {
152+
case "cloud_terms_not_accepted":
153+
message = "Google requires you to accept its Cloud terms before creating your project."
154+
case "login_required", "wrong_google_account":
155+
message = "Google sign-in must be completed with the intended account. Retry, or disconnect first to change accounts."
156+
case "rate_limited":
157+
message = "Google limited project setup requests. Wait a few minutes, then retry; the same project ID is retained."
158+
case "connection_timed_out":
159+
message = "Connection timed out. Retry or ask for a new link; completed login and project progress are retained."
160+
case "google_command_failed":
161+
message = "A Google Cloud command failed while setting up Drive. Retry; if it fails again, check the project in Google Cloud Console."
162+
case "project_not_active":
163+
message = "The Drive project in your Google account is deleted or pending deletion. Restore it in Google Cloud Console (Manage resources), enter the ID of another project you own, or disconnect Drive to start with a new project."
164+
case "project_not_accessible":
165+
message = "Google would not create a new Drive project for this account. Retry later, enter the ID of a project you already own, or disconnect Drive and connect again."
166+
case "project_limit_reached":
167+
message = "Your Google account has reached its Google Cloud project limit, so a new Drive project could not be created. Enter the ID of a project you already own (for example an older drivekey-… project) and retry. Deleting projects frees the limit only after 30 days."
168+
case "project_not_found":
169+
message = "Google did not find that project for this account. Check the ID in Google Cloud Console (Manage resources) and that this Google account owns it, then enter it again."
170+
case "api_disabled":
171+
message = "The Drive and Sheets APIs are not enabled yet. Google can take a few minutes; wait, then retry."
172+
case "api_probe_failed":
173+
message = "Google refused the test call. If this account recently signed out everywhere or changed its password, disconnect Drive and connect again to sign in afresh; otherwise retry."
174+
default:
175+
message = "Google connection could not finish. Retry or ask for a new link; completed progress is retained."
176+
}
177+
if view.Step != "" {
178+
message += " (Failed step: " + view.Step + ".)"
179+
}
180+
return message
181+
}
Collapse file

‎internal/googlelogin/command.go‎

Copy file name to clipboardExpand all lines: internal/googlelogin/command.go
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ const (
2626
errTerms commandError = "cloud_terms_not_accepted"
2727
errRate commandError = "rate_limited"
2828
errCommand commandError = "google_command_failed"
29+
// errProjectHidden: Google answers a deleted-for-good project and one
30+
// this account cannot reach identically (see setup).
31+
errProjectHidden commandError = "project_not_visible"
32+
// errProjectTaken: projects create refused the ID; Google never reuses
33+
// one, even after the project is deleted.
34+
errProjectTaken commandError = "project_id_in_use"
35+
// errProjectInactive: the project is deleted or pending deletion.
36+
errProjectInactive commandError = "project_not_active"
37+
// errProjectRefused: even a fresh project ID was refused at create.
38+
errProjectRefused commandError = "project_not_accessible"
39+
// errProjectLimit: the account may not create more projects. Deleted
40+
// projects keep counting for 30 days; a new ID never helps.
41+
errProjectLimit commandError = "project_limit_reached"
42+
// errProjectNotFound: a project the owner named is not ACTIVE-visible
43+
// to this account.
44+
errProjectNotFound commandError = "project_not_found"
2945
)
3046

3147
// Raw SDK output never becomes an error, log entry or HTTP response.
@@ -41,8 +57,16 @@ func classifyCommand(data []byte) error {
4157
gcloudexec.ClassifyReauth(text).Required,
4258
has("you do not currently have an active account selected"):
4359
return errLogin
60+
// "You've reached your project limit", "... allotted project quota",
61+
// metric projects_count. Before rate limits: waiting never ends it.
62+
case has("project limit"), has("project quota"), has("projects_count"):
63+
return errProjectLimit
4464
case has("resource_exhausted"), has("quota exceeded"), has("'status': 429"):
4565
return errRate
66+
case has("does not have permission to access projects instance"):
67+
return errProjectHidden
68+
case has("already in use by another project"), has("requested entity already exists"):
69+
return errProjectTaken
4670
default:
4771
return errCommand
4872
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.