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.
38 lines (33 loc) • 1.08 kB
text/typescript
import { UseCase } from "@/core/domain/use-case";
import { Either, left, right } from "@/core/logic/either";
import { ApiClientProvider } from "@/providers/api-client-provider";
import { SSHKey } from "../../domain/ssh-key";
import { CreateSSHKeyDTO } from "./create-ssh-key-dto";
import { CreateSSHKeyError } from "./errors/create-ssh-key-error";
export class CreateSSHKey
implements UseCase<CreateSSHKeyDTO, SSHKey, CreateSSHKeyError>
{
constructor(private readonly apiClientProvider: ApiClientProvider) {}
async execute(
dto: CreateSSHKeyDTO
): Promise<Either<CreateSSHKeyError, SSHKey>> {
try {
const sshKey = await this.apiClientProvider.post<SSHKey>(
"/gpu-cloud/ssh-keys",
{
body: JSON.stringify(dto),
}
);
if (!sshKey) {
return left(new CreateSSHKeyError("Failed to create SSH key"));
}
return right(sshKey);
} catch (error) {
return left(
new CreateSSHKeyError(
error instanceof Error ? error.message : "Unknown error"
)
);
}
}
}