Skip to content

Instantly share code, notes, and snippets.

@madhadron
Created February 19, 2021 06:29
Show Gist options
  • Save madhadron/51b5678070f9b569d6eb260cedc925cf to your computer and use it in GitHub Desktop.
Save madhadron/51b5678070f9b569d6eb260cedc925cf to your computer and use it in GitHub Desktop.
let v20210301 : Version = [2021, 3, 1]
let tr : Resource = {
path: "databaseAccounts/{accountName}",
resourceKind: ResourceType.Tracked,
previewVersion: v20210301,
properties: {
delegatedManagementSubnetId: {
description: "Subnet to attach NICs to",
type: StringT,
mutability: Immutable,
previewVersion: v20210301
},
externalCertificates: {
description: "TLS certificates to authenticate gossip",
previewVersion: v20210301,
type: ArrayT(ObjectT({
pem: {
description: "PEM formatted public key",
type: StringT,
previewVersion: v20210301
}
}))
},
initialAdminPassword: {
description: "Password to log in initially",
type: SecretT(StringT),
previewVersion: v20210301,
mutability: CreateOnly
}
}
}
// -----------
// Type definitions below here:
enum Mutability { Create, Read, Write }
let ReadOnly = new Set([Mutability.Read])
let CreateOnly = new Set([Mutability.Create])
let Immutable = new Set([Mutability.Create, Mutability.Read])
type Version = [number, number, number]
interface Versioned {
previewVersion: Version;
gaVersion?: Version
}
interface BoolField { kind: "bool" }
interface StringField { kind: "string" }
interface Int32Field { kind: "int32" }
interface Int64Field { kind: "int64" }
interface FloatField { kind: "float" }
interface ArrayField { kind: "array", elementKind: FieldType }
interface ObjectField { kind: "object", properties: Record<string, Property> }
interface SecretField { kind: "secret", innerKind: FieldType }
interface EnumField { kind: "enum", values: Array<string> }
type FieldType =
| BoolField
| StringField
| Int32Field
| Int64Field
| FloatField
| ArrayField
| ObjectField
| SecretField
| EnumField
let BoolT: BoolField = { kind: "bool" }
let StringT: StringField = { kind: "string" }
let Int32T: Int32Field = { kind: "int32" }
let Int64T: Int64Field = { kind: "int64" }
let FloatField: FloatField = { kind: "float" }
function ArrayT(t: FieldType): ArrayField { return { kind: "array", elementKind: t } }
function ObjectT(ps: Record<string, Property>): ObjectField { return { kind: "object", properties: ps } }
function SecretT(t: FieldType): SecretField { return { kind: "secret", innerKind: t } }
function EnumT(vs: Array<string>): EnumField { return { kind: "enum", values: vs } }
interface Property extends Versioned {
description: string;
type: FieldType;
mutability?: Set<Mutability>;
}
interface Method extends Versioned {
description: string,
returnType: FieldType,
}
enum ResourceType { Tracked, Proxy }
interface Resource extends Versioned {
path: string; // TODO
resourceKind: ResourceType;
properties: Record<string, Property>;
methods?: Record<string, Method>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment