sesterce-cli
Version:
A powerful command-line interface tool for managing Sesterce Cloud services. Sesterce CLI provides easy access to GPU cloud instances, AI inference services, container registries, and SSH key management directly from your terminal.
50 lines • 1.99 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getApiKey = getApiKey;
const fs_1 = __importDefault(require("fs"));
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
function getApiKey(profile = "default") {
const home = os_1.default.homedir();
const credentialsPath = path_1.default.join(home, ".sesterce", "credentials");
if (!fs_1.default.existsSync(credentialsPath)) {
throw new Error(`Credentials file not found at ${credentialsPath}`);
}
const credentials = fs_1.default.readFileSync(credentialsPath, "utf8");
const profiles = parseCredentialsFile(credentials);
if (!profiles[profile]) {
throw new Error(`Profile '${profile}' not found in credentials file`);
}
if (!profiles[profile].sesterce_api_key) {
throw new Error(`API key not found for profile '${profile}'`);
}
return profiles[profile].sesterce_api_key;
}
function parseCredentialsFile(content) {
const profiles = {};
let currentProfile = "";
const lines = content.split("\n");
for (const line of lines) {
const trimmedLine = line.trim();
// Skip empty lines and comments
if (!trimmedLine || trimmedLine.startsWith("#")) {
continue;
}
// Check if it's a profile section
if (trimmedLine.startsWith("[") && trimmedLine.endsWith("]")) {
currentProfile = trimmedLine.slice(1, -1);
profiles[currentProfile] = {};
continue;
}
// Parse key-value pairs
if (currentProfile && trimmedLine.includes("=")) {
const [key, value] = trimmedLine.split("=", 2);
profiles[currentProfile][key.trim()] = value.trim();
}
}
return profiles;
}
//# sourceMappingURL=get-api-key.js.map