UNPKG

genezio

Version:

Command line utility to interact with Genezio infrastructure.

49 lines (48 loc) 1.68 kB
import axios from "./axios.js"; import { getAuthToken } from "../utils/accounts.js"; import { BACKEND_ENDPOINT } from "../constants.js"; import version from "../utils/version.js"; import { GENEZIO_NOT_AUTH_ERROR_MSG, UserError } from "../errors.js"; export async function getContainerRegistry() { // Check if user is authenticated const authToken = await getAuthToken(); if (!authToken) { throw new UserError(GENEZIO_NOT_AUTH_ERROR_MSG); } const response = await axios({ method: "GET", url: `${BACKEND_ENDPOINT}/core/container-registry`, headers: { Authorization: `Bearer ${authToken}`, "Accept-Version": `genezio-cli/${version}`, }, maxContentLength: Infinity, maxBodyLength: Infinity, }).catch((error) => { throw error; }); if (!(response.status >= 200 && response.status < 300)) { throw new Error(response.statusText || "Unknown error occurred."); } return response.data; } export async function getContainerRegistryCredentials() { const authToken = await getAuthToken(); if (!authToken) { throw new UserError(GENEZIO_NOT_AUTH_ERROR_MSG); } const response = await axios({ method: "GET", url: `${BACKEND_ENDPOINT}/users/harbor/credentials`, headers: { Authorization: `Bearer ${authToken}`, "Accept-Version": `genezio-cli/${version}`, }, }).catch((error) => { throw error; }); if (!(response.status >= 200 && response.status < 300)) { throw new Error(response.statusText || "Unknown error occurred."); } return response.data; }