-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add open api to the mix * Adds base OpenApi spec * Wire api doc and openapi spec route to the router * Adds host list operation to openapi spec * Rename default api tag to Landscape * Make dialyzer happy * Polish Host OpenApi schema
- Loading branch information
1 parent
894e09f
commit 44fc08e
Showing
10 changed files
with
234 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule TrentoWeb.OpenApi.ApiSpec do | ||
@moduledoc """ | ||
OpenApi specification entry point | ||
""" | ||
|
||
alias OpenApiSpex.{Info, OpenApi, Paths, Server, Tag} | ||
alias TrentoWeb.{Endpoint, Router} | ||
@behaviour OpenApi | ||
|
||
@impl OpenApi | ||
def spec do | ||
%OpenApi{ | ||
servers: [ | ||
# Populate the Server info from a phoenix endpoint | ||
Server.from_endpoint(Endpoint) | ||
], | ||
info: %Info{ | ||
title: "Trento", | ||
description: to_string(Application.spec(:trento, :description)), | ||
version: to_string(Application.spec(:trento, :vsn)) | ||
}, | ||
# Populate the paths from a phoenix router | ||
paths: Paths.from_router(Router), | ||
tags: [ | ||
%Tag{ | ||
name: "Landscape", | ||
description: "Providing access to the discovered target infrastructure" | ||
} | ||
] | ||
} | ||
# Discover request/response schemas from path specs | ||
|> OpenApiSpex.resolve_schema_modules() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
defmodule TrentoWeb.OpenApi.Schema.Host do | ||
@moduledoc false | ||
|
||
require OpenApiSpex | ||
alias OpenApiSpex.Schema | ||
|
||
defmodule IPv4 do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "IPv4", | ||
type: :string, | ||
format: :ipv4 | ||
}) | ||
end | ||
|
||
defmodule IPv6 do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "IPv6", | ||
type: :string, | ||
format: :ipv6 | ||
}) | ||
end | ||
|
||
defmodule HostItem do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "Host", | ||
description: "A discovered host on the target infrastructure", | ||
type: :object, | ||
properties: %{ | ||
id: %Schema{type: :integer, description: "Host ID"}, | ||
hostname: %Schema{type: :string, description: "Host name"}, | ||
ip_addresses: %Schema{ | ||
type: :array, | ||
description: "IP addresses", | ||
items: %Schema{ | ||
title: "IP address", | ||
oneOf: [ | ||
IPv4, | ||
IPv6 | ||
] | ||
} | ||
}, | ||
ssh_address: TrentoWeb.OpenApi.Schema.Host.IPv4, | ||
agent_version: %Schema{ | ||
type: :string, | ||
description: "Version of the agent installed on the host" | ||
}, | ||
cluster_id: %Schema{ | ||
type: :string, | ||
description: "Identifier of the cluster this host is part of", | ||
format: :uuid | ||
}, | ||
heartbeat: %Schema{ | ||
type: :string, | ||
description: "Host's last heartbeat status", | ||
enum: [:critical, :passing, :unknown] | ||
}, | ||
provider: %Schema{ | ||
type: :string, | ||
description: "Detected Provider on which the host is running", | ||
enum: [:azure, :aws, :gcp, :unknown] | ||
}, | ||
provider_data: TrentoWeb.OpenApi.Schema.Provider.ProviderData, | ||
tags: %Schema{ | ||
title: "Tags", | ||
description: "A list of tags attached to a resource", | ||
type: :array, | ||
items: TrentoWeb.OpenApi.Schema.Tag | ||
}, | ||
sles_subscriptions: %Schema{ | ||
title: "SlesSubscriptions", | ||
description: "A list of the available SLES Subscriptions on a host", | ||
type: :array, | ||
items: TrentoWeb.OpenApi.Schema.SlesSubscription | ||
} | ||
} | ||
}) | ||
end | ||
|
||
defmodule HostsCollection do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "HostsCollection", | ||
description: "A list of the discovered hosts", | ||
type: :array, | ||
items: HostItem | ||
}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule TrentoWeb.OpenApi.Schema.Provider do | ||
@moduledoc false | ||
|
||
require OpenApiSpex | ||
alias OpenApiSpex.Schema | ||
|
||
defmodule ProviderData do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "ProviderMetadata", | ||
description: "Detected metadata for any provider", | ||
oneOf: [ | ||
TrentoWeb.OpenApi.Schema.Provider.AzureProviderData | ||
] | ||
}) | ||
end | ||
|
||
defmodule AzureProviderData do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "AzureProviderData", | ||
description: "Azure detected metadata", | ||
type: :object, | ||
properties: %{ | ||
resource_group: %Schema{type: :string}, | ||
location: %Schema{type: :string}, | ||
vm_size: %Schema{type: :string}, | ||
data_disk_number: %Schema{type: :integer}, | ||
offer: %Schema{type: :string}, | ||
sku: %Schema{type: :string}, | ||
admin_username: %Schema{type: :string} | ||
} | ||
}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule TrentoWeb.OpenApi.Schema.SlesSubscription do | ||
@moduledoc false | ||
|
||
require OpenApiSpex | ||
alias OpenApiSpex.Schema | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "SlesSubscription", | ||
description: "A discovered SLES Subscription on a host", | ||
type: :object, | ||
properties: %{ | ||
host_id: %Schema{type: :string, format: :uuid}, | ||
identifier: %Schema{type: :string}, | ||
version: %Schema{type: :string}, | ||
arch: %Schema{type: :string}, | ||
status: %Schema{type: :string}, | ||
subscription_status: %Schema{type: :string}, | ||
type: %Schema{type: :string}, | ||
starts_at: %Schema{type: :string}, | ||
expires_at: %Schema{type: :string} | ||
} | ||
}) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule TrentoWeb.OpenApi.Schema.Tag do | ||
@moduledoc false | ||
|
||
require OpenApiSpex | ||
alias OpenApiSpex.Schema | ||
|
||
OpenApiSpex.schema(%{ | ||
title: "Tag", | ||
description: "A tag attached to a resource", | ||
type: :object, | ||
properties: %{ | ||
id: %Schema{type: :integer}, | ||
resource_id: %Schema{type: :string, format: :uuid}, | ||
resource_type: %Schema{type: :string, enum: [:host, :cluster, :sap_system, :database]}, | ||
value: %Schema{type: :string} | ||
} | ||
}) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters