@dataroadinc/setup-auth
Version:
CLI tool and programmatic API for automated OAuth setup across cloud platforms
46 lines (45 loc) • 2.03 kB
JavaScript
import { gcpCheckOauthOrganizationId } from "../../../providers/gcp/organization.js";
import { gcpCheckOauthProjectId, GcpProjectManager, } from "../../../providers/gcp/project/index.js";
import { SetupAuthError } from "../../../utils/error.js";
export async function gcpViewProject(options, identity) {
const { success: successProject, error: errorProject } = await gcpCheckOauthProjectId(options);
if (!successProject) {
throw new SetupAuthError(errorProject);
}
const { success: successOrganization, error: errorOrganization } = await gcpCheckOauthOrganizationId(options);
if (!successOrganization) {
throw new SetupAuthError(errorOrganization);
}
const projectViewer = new GcpProjectViewer(identity, options.gcpOauthOrganizationId, options.gcpOauthProjectId);
await projectViewer.view();
if (options.gcpOauthProjectId === options.gcpOauthQuotaProjectId) {
console.log("Project is also the quota project");
}
else {
console.log("Project has a different quota project:", options.gcpOauthQuotaProjectId);
const quotaProjectViewer = new GcpProjectViewer(identity, options.gcpOauthOrganizationId, options.gcpOauthQuotaProjectId);
await quotaProjectViewer.view();
}
}
export class GcpProjectViewer {
constructor(identity, organizationId, projectId) {
this.initialized = false;
this.identity = identity;
this.organizationId = organizationId;
this.projectId = projectId;
this.projectManager = new GcpProjectManager(this.identity, this.organizationId);
}
async initialize() {
if (this.initialized) {
return;
}
await this.projectManager.initialize();
this.initialized = true;
}
async view() {
await this.initialize();
console.log("Viewing project", this.projectId, "in organization", this.organizationId);
const project = await this.projectManager.getProject(this.projectId);
console.log(project);
}
}