View Source K8s.Operation.Path (k8s v2.4.2)
Generates Kubernetes REST API Paths
Summary
Functions
Generates the API path for a K8s.Operation
.
Find valid path params in a URL path.
Replaces path variables with options.
Functions
@spec build(K8s.Operation.t()) :: {:ok, binary()} | {:error, K8s.Operation.Error.t()}
Generates the API path for a K8s.Operation
.
Examples
Generate a path for a cluster scoped resource:
iex> resource = K8s.Resource.build("apps/v1", "CertificateSigningRequest", "foo")
...> operation = %K8s.Operation{
...> method: :put,
...> verb: :update,
...> data: resource,
...> path_params: [name: "foo"],
...> api_version: "apps/v1",
...> name: "certificatesigningrequests"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/apis/apps/v1/certificatesigningrequests/foo"}
iex> resource = K8s.Resource.build("apps/v1", "CertificateSigningRequest", "foo")
...> operation = %K8s.Operation{
...> method: :put,
...> verb: :update,
...> data: resource,
...> path_params: [name: "foo", namespace: nil],
...> api_version: "apps/v1",
...> name: "certificatesigningrequests"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/apis/apps/v1/certificatesigningrequests/foo"}
Generate a path for a namespace scoped resource:
iex> resource = K8s.Resource.build("v1", "Pod", "default", "foo")
...> operation = %K8s.Operation{
...> method: :put,
...> verb: :update,
...> data: resource,
...> path_params: [namespace: "default", name: "foo"],
...> api_version: "v1",
...> name: "pods"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/api/v1/namespaces/default/pods/foo"}
Generate a path for a namespace scoped resource on the collection: (ie create, list)
iex> resource = K8s.Resource.build("v1", "Pod", "default", "foo")
...> operation = %K8s.Operation{
...> method: :post,
...> verb: :create,
...> data: resource,
...> path_params: [namespace: "default", name: "foo"],
...> api_version: "v1",
...> name: "pods"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/api/v1/namespaces/default/pods"}
Generating a listing path for a namespace:
iex> operation = %K8s.Operation{
...> method: :get,
...> verb: :list,
...> data: nil,
...> path_params: [namespace: "default"],
...> api_version: "v1",
...> name: "pods"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/api/v1/namespaces/default/pods"}
Generating a listing path for a all namespaces:
iex> operation = %K8s.Operation{
...> method: :get,
...> verb: :list_all_namespaces,
...> data: nil,
...> path_params: [namespace: "default"],
...> api_version: "v1",
...> name: "pods"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/api/v1/pods"}
Generating a listing path for a watching all namespaces:
iex> operation = %K8s.Operation{
...> method: :get,
...> verb: :watch_all_namespaces,
...> data: nil,
...> path_params: [namespace: "default"],
...> api_version: "v1",
...> name: "pods"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/api/v1/pods"}
Generating a path for a subresource:
iex> operation = %K8s.Operation{
...> method: :get,
...> verb: :get,
...> data: nil,
...> path_params: [namespace: "default", name: "foo"],
...> api_version: "v1",
...> name: "pods/status"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/api/v1/namespaces/default/pods/foo/status"}
Deleting a collection:
iex> operation = %K8s.Operation{
...> method: :delete,
...> verb: :deletecollection,
...> data: nil,
...> path_params: [namespace: "default"],
...> api_version: "v1",
...> name: "pods"
...> }
...> K8s.Operation.Path.build(operation)
{:ok, "/api/v1/namespaces/default/pods"}
Find valid path params in a URL path.
Examples
iex> K8s.Operation.Path.find_params("/foo/{name}")
[:name]
iex> K8s.Operation.Path.find_params("/foo/{namespace}/bar/{name}")
[:namespace, :name]
iex> K8s.Operation.Path.find_params("/foo/bar")
[]
Replaces path variables with options.
Examples
iex> K8s.Operation.Path.replace_path_vars("/foo/{name}", name: "bar")
"/foo/bar"