Skip to content

Commit

Permalink
feat(universe.ts): added churning support on universes
Browse files Browse the repository at this point in the history
  • Loading branch information
mellifluus committed Mar 26, 2024
1 parent ea8cfa0 commit 6f11739
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/cloud/entities/universe/universe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface CloudUniverseOptions extends EntityOptions {
}

type LogLevel = 'none' | 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'
type ChurnLevel = 'None' | 'Light' | 'Medium' | 'Full'

export interface DeployOperatorOptions {
readonly size: 'small' | 'large',
Expand Down Expand Up @@ -534,6 +535,31 @@ export class CloudUniverse extends Entity<CloudUniversePayload, CloudUniverseRaw
}
}

public async patchChurn (churnLevel: ChurnLevel): Promise<void> {
if (this.id === null || this.id === undefined) throw new TypeError('Universe.patchChurn requires universe id to be set.')
const endpoint = `api/v0/universes/${this.id}/churn`
try {
const opts = {
method: 'POST',
url: `${this.apiCarrier?.injectables?.base}/${endpoint}`,
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
responseType: 'json',
data: {
churnLevel
}
}
const res = await this.http?.getClient()(opts)
const { status } = res.data
if (status !== 200) {
throw this.handleError(new PatchChurnError())
}
} catch (err) {
throw this.handleError(new PatchChurnError())
}
}

public async patchOperatorOptions (id: string, payload: PatchOperatorOptions): Promise<void> {
const endpoint = `api/v0/universes/operator/${id}/options`
try {
Expand Down Expand Up @@ -772,6 +798,14 @@ export class DeployVersionError extends BaseError {
}
}

export class PatchChurnError extends BaseError {
public name = 'PatchChurnError'
constructor (public message: string = 'Could not set Universe churn level.', properties?: any) {
super(message, properties)
Object.setPrototypeOf(this, PatchChurnError.prototype)
}
}

export class UniverseIamError extends BaseError {
public name = 'UniverseIamError'
constructor (public message: string = 'Could not apply universe iam changes.', properties?: any) {
Expand Down

0 comments on commit 6f11739

Please sign in to comment.