Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial TSP conversion of Microsoft.DocumentDB #26596

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@typespec/rest";
import "./models.tsp";
import "./MongoCluster.tsp";

using TypeSpec.Rest;
using Azure.ResourceManager;
using Azure.ResourceManager.Foundations;
using TypeSpec.Http;

namespace Microsoft.DocumentDB;
@doc("Represents a mongo cluster firewall rule.")
@parentResource(MongoCluster)
model FirewallRule is ProxyResource<FirewallRuleProperties> {
@doc("The name of the mongo cluster firewall rule.")
@maxLength(80)
@minLength(1)
@pattern("^[a-zA-Z0-9][-_.a-zA-Z0-9]*")
@path
@key("firewallRuleName")
@segment("firewallRules")
name: string;
}

@armResourceOperations
interface FirewallRules {
@doc("Gets information about a mongo cluster firewall rule.")
getFirewallRule is ArmResourceRead<FirewallRule>;
@doc("Creates a new firewall rule or updates an existing firewall rule on a mongo cluster.")
createOrUpdateFirewallRule is ArmResourceCreateOrUpdateAsync<FirewallRule>;
@doc("Deletes a mongo cluster firewall rule.")
deleteFirewallRule is ArmResourceDeleteWithoutOkAsync<FirewallRule>;
@doc("List all the firewall rules in a given mongo cluster.")
listFirewallRules is ArmResourceListByParent<FirewallRule>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@typespec/rest";
import "./models.tsp";

using TypeSpec.Rest;
using Azure.ResourceManager;
using Azure.ResourceManager.Foundations;
using TypeSpec.Http;

namespace Microsoft.DocumentDB;
@doc("Represents a mongo cluster resource.")
model MongoCluster is TrackedResource<MongoClusterProperties> {
@doc("The name of the mongo cluster.")
@maxLength(40)
@minLength(3)
@pattern("^[a-z0-9]+(-[a-z0-9]+)*")
@path
@key("mongoClusterName")
@segment("mongoClusters")
name: string;
}

@armResourceOperations
interface MongoClusters {
@doc("Gets information about a mongo cluster.")
get is ArmResourceRead<MongoCluster>;
@doc("Create or update a mongo cluster. Update overwrites all properties for the resource. To only modify some of the properties, use PATCH.")
createOrUpdate is ArmResourceCreateOrUpdateAsync<MongoCluster>;
@doc("Updates an existing mongo cluster. The request body can contain one to many of the properties present in the normal mongo cluster definition.")
update is ArmResourcePatchAsync<MongoCluster, MongoClusterProperties>;
@doc("Deletes a mongo cluster.")
delete is ArmResourceDeleteWithoutOkAsync<MongoCluster>;
@doc("List all the mongo clusters in a given resource group.")
listByResourceGroup is ArmResourceListByParent<MongoCluster>;
@doc("List all the mongo clusters in a given subscription.")
list is ArmListBySubscription<MongoCluster>;
@doc("List mongo cluster connection strings. This includes the default connection string using SCRAM-SHA-256, as well as other connection strings supported by the cluster.")
listConnectionStrings is ArmResourceActionSync<
MongoCluster,
{},
ListConnectionStringsResult
>;
}
29 changes: 29 additions & 0 deletions specification/cosmosdbmongocluster/DocumentDB.Management/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "./models.tsp";
import "./MongoCluster.tsp";
import "./FirewallRule.tsp";
import "./routes.tsp";

using TypeSpec.Rest;
using TypeSpec.Http;
using Azure.ResourceManager.Foundations;
using Azure.Core;
using Azure.ResourceManager;
using TypeSpec.Versioning;
@armProviderNamespace
@service({
title: "CosmosDB Mongo Cluster",
})
@versioned(Versions)
@doc("The Microsoft Azure management API provides create, read, update, and delete functionality for Azure Cosmos DB for MongoDB vCore resources including clusters and firewall rules.")
namespace Microsoft.DocumentDB;

@doc("The available API versions.")
enum Versions {
@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2023_10_01: "2023-10-01",
}
190 changes: 190 additions & 0 deletions specification/cosmosdbmongocluster/DocumentDB.Management/models.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import "@typespec/rest";
import "@typespec/http";
import "@azure-tools/typespec-azure-resource-manager";

using TypeSpec.Rest;
using TypeSpec.Http;
using Azure.ResourceManager;

namespace Microsoft.DocumentDB;

interface Operations extends Azure.ResourceManager.Operations {}

enum Origin {
user,
system,
`user,system`,
}

enum ActionType {
Internal,
}

enum CreateMode {
Default,
PointInTimeRestore,
}

enum ProvisioningState {
Succeeded,
Failed,
Canceled,
InProgress,
Updating,
Dropping,
}

enum MongoClusterStatus {
Ready,
Provisioning,
Updating,
Starting,
Stopping,
Stopped,
Dropping,
}

enum NodeKind {
Shard,
}

enum CreatedByType {
User,
Application,
ManagedIdentity,
Key,
}

enum CheckNameAvailabilityReason {
Invalid,
AlreadyExists,
}

@doc("The properties of a mongo cluster.")
model MongoClusterProperties {
@doc("The mode to create a mongo cluster.")
@visibility("create")
createMode?: CreateMode;

@doc("Parameters used for restore operations")
@visibility("create")
restoreParameters?: MongoClusterRestoreParameters;

@doc("The administrator's login for the mongo cluster.")
@visibility("read", "create", "update")
administratorLogin?: string;

@doc("The password of the administrator login.")
@visibility("create", "update")
@secret
administratorLoginPassword?: string;

@doc("The Mongo DB server version. Defaults to the latest available version if not specified.")
serverVersion?: string;

@doc("The default mongo connection string for the cluster.")
@visibility("read")
connectionString?: string;

@doc("Earliest restore timestamp in UTC ISO8601 format.")
@visibility("read")
earliestRestoreTime?: string;

@doc("A provisioning state of the mongo cluster.")
@visibility("read")
provisioningState?: ProvisioningState;

@doc("A status of the mongo cluster.")
@visibility("read")
clusterStatus?: MongoClusterStatus;

@doc("The list of node group specs in the cluster.")
nodeGroupSpecs?: NodeGroupSpec[];
}

@doc("Parameters used for restore operations")
model MongoClusterRestoreParameters {
@doc("UTC point in time to restore a mongo cluster")
// FIXME: (utcDateTime) Please double check that this is the correct type for your scenario.
pointInTimeUTC?: utcDateTime;

@doc("Resource ID to locate the source cluster to restore")
sourceResourceId?: string;
}

@doc("Specification for a node group.")
model NodeGroupSpec {
...NodeGroupProperties;

@doc("The node type deployed in the node group.")
kind?: NodeKind;

@doc("The number of nodes in the node group.")
nodeCount?: int32;
}

@doc("The properties of the node group on a cluster.")
model NodeGroupProperties {
@doc("The resource sku for the node group. This defines the size of CPU and memory that is provisioned for each node. Example values: 'M30', 'M40'.")
sku?: string;

@doc("The disk storage size for the node group in GB. Example values: 128, 256, 512, 1024.")
diskSizeGB?: int32;

@doc("Whether high availability is enabled on the node group.")
enableHa?: boolean;
}

@doc("The properties of a mongo cluster firewall rule.")
model FirewallRuleProperties {
@doc("The provisioning state of the firewall rule.")
@visibility("read")
provisioningState?: ProvisioningState;

@doc("The start IP address of the mongo cluster firewall rule. Must be IPv4 format.")
@pattern("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$")
startIpAddress: string;

@doc("The end IP address of the mongo cluster firewall rule. Must be IPv4 format.")
@pattern("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$")
endIpAddress: string;
}

@doc("The check availability request body.")
model CheckNameAvailabilityRequest {
@doc("The name of the resource for which availability needs to be checked.")
name?: string;

@doc("The resource type.")
type?: string;
}

@doc("The check availability result.")
model CheckNameAvailabilityResponse {
@doc("Indicates if the resource name is available.")
nameAvailable?: boolean;

@doc("The reason why the given name is not available.")
reason?: CheckNameAvailabilityReason;

@doc("Detailed reason why the given name is available.")
message?: string;
}

@doc("The connection strings for the given mongo cluster.")
model ListConnectionStringsResult {
@doc("An array that contains the connection strings for a mongo cluster.")
@visibility("read")
connectionStrings?: ConnectionString[];
}

@doc("Connection string for the mongo cluster")
model ConnectionString {
@doc("Value of the connection string")
@visibility("read")
connectionString?: string;

@doc("Description of the connection string")
@visibility("read")
description?: string;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import "@azure-tools/typespec-azure-core";
import "@typespec/rest";
import "./models.tsp";

using TypeSpec.Rest;
using TypeSpec.Http;

namespace Microsoft.DocumentDB;

interface MongoClustersOperations {
@doc("Check the availability of name for resource")
@route("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/checkMongoClusterNameAvailability")
@post
CheckNameAvailability is Azure.Core.Foundations.Operation<
{
@doc("The ID of the target subscription. The value must be an UUID.")
@path
subscriptionId: string;

@doc("The name of the Azure region.")
@minLength(1)
@path
location: string;

@doc("The required parameters for checking if resource name is available.")
@body
parameters: CheckNameAvailabilityRequest;
},
CheckNameAvailabilityResponse
>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
emit:
- "@azure-tools/typespec-autorest"
options:
"@azure-tools/typespec-autorest":
emitter-output-dir: "{project-root}/.."
azure-resource-provider-folder: "resource-manager"
output-file: "{azure-resource-provider-folder}/{service-name}/{version-status}/{version}/mongoCluster.json"
examples-directory: "{project-root}/examples"
linter:
extends:
- "@azure-tools/typespec-azure-resource-manager/all"
Loading
Loading