Risoluzione dei problemi relativi ai gem Ruby

Questo documento spiega perché possono verificarsi determinati errori quando utilizzi gemme Ruby in un repository Artifact Registry e i possibili rimedi per queste situazioni.

Credenziali push scadute

Hai effettuato una richiesta push, ma hai ricevuto il seguente messaggio di errore:

Pushing gem to https://LOCATION-ruby.pkg.devPROJECT/REPOSITORY..
The request does not have valid authentication credentials.

Per aggiornare le credenziali, genera un nuovo token eseguendo questo comando:

export GEM_HOST_API_KEY="Bearer $(gcloud auth print-access-token)"
export HOST="https://LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY"
bundle config $HOST $GEM_HOST_API_KEY

Dove:

  • LOCATION è la posizione regionale o multiregionale del repository.
  • PROJECT è l'ID progetto. Se questo flag viene omesso, viene utilizzato il progetto corrente o predefinito.
  • REPOSITORY è l'ID del repository. Se hai configurato un repository predefinito di Artifact Registry, questo viene utilizzato quando questo flag viene omesso dal comando.

Richiesta di accesso durante il push

Hai effettuato una richiesta push, ma hai ricevuto un messaggio che ti chiede le tue credenziali ruby.pkg.dev:

Enter your https://us-ruby.pkg.dev/REPOSITORY/GEM_NAME credentials.
Don't have an account yet? Create one at https://us-ruby.pkg.dev/REPOSITORY/GEM_NAME/sign_up
   Email:

Prova a eseguire questo comando:

GEM_HOST_API_KEY="Bearer $(gcloud auth print-access-token)"

Credenziali pull scadute

Hai creato una richiesta di pull, ma hai ricevuto il seguente messaggio di errore:

 Unable to download data from https://oauth2accesstoken:REDACTED@LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY/ - bad response Unauthorized 401 (https://oauth2accesstoken:REDACTED@LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY/latest_specs.4.8.gz)

Per aggiornare le credenziali, rimuovi l'origine delle credenziali scadute da gem sources. Successivamente, genera un nuovo token eseguendo il seguente comando:

export GEM_HOST_API_KEY="Bearer $(gcloud auth print-access-token)"
export HOST="https://LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY"
bundle config $HOST $GEM_HOST_API_KEY

Dove:

  • LOCATION è la posizione del tuo repository.
  • PROJECT è l'ID progetto. Se questo flag viene omesso, viene utilizzato il progetto corrente o predefinito.
  • REPOSITORY è il nome del tuo repository in Artifact Registry.

Errore della richiesta di pull: Could not fetch specs

Hai creato una richiesta di pull, ma hai ricevuto il seguente messaggio di errore:

Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY/ due to underlying error <bad response Not Found 404 (https://LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY/specs.4.8.gz)>

Questo errore potrebbe essere visualizzato in modo errato anche se la richiesta pull è andata a buon fine. Utilizza un comando verbose per verificare che la richiesta pull sia stata eseguita correttamente, ad esempio bundle install --verbose.