Skip to content

Commit

Permalink
checkin smithy api definition
Browse files Browse the repository at this point in the history
  • Loading branch information
rumenvasilev committed Oct 24, 2023
1 parent bf29c86 commit b07f3a0
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
.smithy.lsp.log
.gradle
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# terraform-registry-api
Terraform registry API definition, in case you want to build it

Instructions how to use it will follow soon.
96 changes: 96 additions & 0 deletions model/module.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
$version: "2"
namespace tf.registry.module
use tf.registry.shapes#SemVer
use tf.registry.shapes#githubModuleDownloadURL
use tf.registry.shapes#NamespaceDef

resource Module {
identifiers: {
namespace: NamespaceDef
name: String
version: SemVer
}
read: GetModuleVersion,
list: ListModuleVersions,
}

@suppress(["HttpUriConflict"])
@readonly
@http(method: "GET", uri: "/v1/modules/{namespace}/{name}/{system}/{version}/download", code: 200)
operation GetModuleVersion {
input: GetModuleVersionInput
output: GetModuleVersionOutput
}

@input
structure GetModuleVersionInput {
@required
@httpLabel
namespace: NamespaceDef = "terraform-aws-modules"

@required
@httpLabel
name: String = "iam"

@required
@httpLabel
system: String = "aws"

@required
@httpLabel
version: SemVer = "5.2.0"
}

@output
structure GetModuleVersionOutput {
@httpHeader("X-Terraform-Get")
xterraformget: githubModuleDownloadURL
}

@suppress(["HttpUriConflict"])
@readonly
@http(method: "GET", uri: "/v1/modules/{namespace}/{name}/{system}/versions", code:200)
operation ListModuleVersions {
input: ListModuleVersionsInput
output: ListModuleVersionsOutput
}

@input
structure ListModuleVersionsInput {
@required
@httpLabel
namespace: NamespaceDef = "terraform-aws-modules"

@required
@httpLabel
name: String = "iam"

@required
@httpLabel
system: String = "aws"
}

@output
structure ListModuleVersionsOutput {
@required
modules: Modules
}

@length(max:1)
list Modules {
member: VersionsModule
}

structure VersionsModule {
@required
versions: Versions
}

list Versions {
member: Version
}

structure Version {
@required
version: SemVer
}
162 changes: 162 additions & 0 deletions model/provider.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
$version: "2"
namespace tf.registry.provider
use tf.registry.shapes#SemVer
use tf.registry.shapes#Arch
use tf.registry.shapes#Protocol
use tf.registry.shapes#SHASum
use tf.registry.shapes#GPGKeyID
use tf.registry.shapes#Filename
use tf.registry.shapes#OS

resource Provider {
identifiers: {
namespace: String
type: String
version: SemVer
}
read: GetProviderVersion,
list: ListProviderVersions,
}

// https://registry.opentofu.org/v1/providers/hashicorp/aws/5.20.1/download/darwin/amd64
@suppress(["HttpUriConflict"])
@readonly
@http(method: "GET", uri: "/v1/providers/{namespace}/{type}/{version}/download/{os}/{arch}", code: 200)
operation GetProviderVersion {
input: GetProviderVersionInput
output: GetProviderVersionOutput
}

@input
structure GetProviderVersionInput {
@required
@httpLabel
@length(min: 2)
namespace: String = "hashicorp"

@required
@httpLabel
type: String = "aws"

@required
@httpLabel
version: SemVer = "5.20.1"

@required
@httpLabel
os: String = "darwin"

@required
@httpLabel
arch: String = "amd64"
}

@output
structure GetProviderVersionOutput {
@required
arch: Arch

// https://github.com/opentofu/terraform-provider-aws/releases/download/v5.20.1/terraform-provider-aws_5.20.1_darwin_amd64.zip
@required
@jsonName("download_url")
downloadUrl: String

@required
filename: Filename

// darwin
@required
os: OS

// 5.0
@required
protocols: Protocols

// 8d356f2b0f67e9a048f0dafa463541cc0965021364cb689c3481195b304fdbab
@required
shasum: SHASum

// https://github.com/opentofu/terraform-provider-aws/releases/download/v5.20.1/terraform-provider-aws_5.20.1_SHA256SUMS
@required
@jsonName("shasums_url")
shasumsUrl: String

// https://github.com/opentofu/terraform-provider-aws/releases/download/v5.20.1/terraform-provider-aws_5.20.1_SHA256SUMS.sig
@required
@jsonName("shasums_signature_url")
shasumsSignatureUrl: String

@jsonName("signing_keys")
signkeys: SigningKeys
}

list Protocols {
member: Protocol
}

structure SigningKeys {
@required
@jsonName("gpg_public_keys")
gpgpublickeys: GPGPubKeys
}

@length(min:0)
list GPGPubKeys {
member: GPGPubKey
}

structure GPGPubKey {
@jsonName("key_id")
keyId: GPGKeyID

@jsonName("ascii_armor")
asciiArmor: String
}

// /v1/providers/hashicorp/type/versions
@suppress(["HttpUriConflict"])
@readonly
@http(method: "GET", uri: "/v1/providers/{namespace}/{type}/versions", code: 200)
operation ListProviderVersions {
input: ListProviderVersionsInput
output: ListProviderVersionsOutput
}

// ^/v1/providers/[^/]+/[^/]+/versions
@input
structure ListProviderVersionsInput {
@required
@httpLabel
@length(min: 2)
namespace: String = "hashicorp"

@required
@httpLabel
@length(min: 2)
type: String = "aws"
}

@output
structure ListProviderVersionsOutput {
@required
versions: ProviderVersionsList
}

list ProviderVersionsList {
member: ProviderVersion
}

structure ProviderVersion {
version: SemVer
protocols: Protocols
platforms: Platforms
}

list Platforms {
member: Platform
}

structure Platform {
os: OS
arch: Arch
}
33 changes: 33 additions & 0 deletions model/shapes.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
$version: "2"
namespace tf.registry.shapes

// PATTERNS
@pattern("^amd64|arm64|arm|386$")
string Arch

// terraform-provider-aws_5.20.1_darwin_amd64.zip
@pattern("^terraform-provider-([a-z]+(-[a-z]+)?)_(([0-9]{1}|[1-9][0-9])\\.){2}([0-9]{1}|[1-9][0-9])_(darwin|linux|windows)_(amd64|arm|arm64|386)\\.zip$")
string Filename

@pattern("^darwin|linux|windows$")
string OS

@pattern("^\\d{1,2}\\.\\d$")
string Protocol

@pattern("^[a-z0-9]{64}$")
string SHASum

@pattern("^[A-Z0-9]{16}$")
string GPGKeyID

// "X-Terraform-Get": fmt.Sprintf("git::https://github.com/%s/%s?ref=%s", params.Namespace, repoName, releaseTag)}
@pattern("^git::https://github\\.com/\\w+/\\w+\\?ref=\\w+$")
string githubModuleDownloadURL

@pattern("^terraform-[a-z0-9]+-[a-z0-9]+$")
string NamespaceDef

// semver
@pattern("^(([0-9]{1}|[1-9][0-9])\\.){2}([0-9]{1}|[1-9][0-9]{1,2})$")
string SemVer
12 changes: 12 additions & 0 deletions model/tf_registry.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$version: "2"
namespace tf.registry
use aws.protocols#restJson1
use tf.registry.provider#Provider
use tf.registry.module#Module
use tf.registry.wellknown#WellKnown

@restJson1
service Registry {
version: "2006-03-01"
resources: [Provider, Module, WellKnown]
}
34 changes: 34 additions & 0 deletions model/wellknown.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
$version: "2"
namespace tf.registry.wellknown

// .well-known/terraform.json
resource WellKnown {
read: GetWellKnown
}

@readonly
@http(method: "GET", uri: "/.well-known/terraform.json", code: 200)
operation GetWellKnown {
output: GetWellKnownOutput
}

@output
structure GetWellKnownOutput {
@required
@jsonName("modules.v1")
@default("/v1/modules/")
modulesv1: modulesMetadataVersion

@required
@jsonName("providers.v1")
@default("/v1/providers/")
providersv1: providersMetadataVersion
}

enum modulesMetadataVersion {
V1 = "/v1/modules/"
}

enum providersMetadataVersion {
V1 = "/v1/providers/"
}
17 changes: 17 additions & 0 deletions smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "1.0",
"maven": {
"dependencies": [
"software.amazon.smithy:smithy-aws-traits:1.40.0",
"software.amazon.smithy:smithy-openapi:1.40.0"
]
},
"plugins": {
"openapi": {
"service": "tf.registry#Registry",
"protocol": "aws.protocols#restJson1",
"version": "3.1.0",
"useIntegerType": true
}
}
}

0 comments on commit b07f3a0

Please sign in to comment.