Skip to content
Merged
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
1,096 changes: 1,096 additions & 0 deletions assets/scss/_rest-api-reference.scss

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/scss/_styles_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@import "search_project.scss";
@import "_videos_project.scss";
@import "subscription.scss";
@import "rest-api-reference.scss";
@import "_video-landing_project.scss";
@import "elements_project";
@import "summary.scss";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: REST API
description: >
Low-level ReST API reference for extending Layer5 Cloud.
REST APIs for extending Layer5 Cloud.
weight: 1
categories: [Reference]
tags: [extensibility]
Expand All @@ -11,18 +11,18 @@ To create integrations, retrieve data, and automate your cloud native infrastruc

## Authenticating with the API

In order to authenticate to Layer5 Cloud's REST API, you need to generate and use a [security token](../security/tokens). Visit your [user account's security tokens](https://cloud.layer5.io/security/tokens) and generate a long-lived security token. Security tokens are without expiration date. You can generate as many tokens as you like. You can also revoke them at any time.
In order to authenticate to Layer5 Cloud's REST API, you need to generate and use a [security token](../security/tokens). Visit your [user account's security tokens](https://cloud.layer5.io/security/tokens) and generate a long-lived token. Security tokens remain valid until you revoke them, and you can issue as many as you need.

To authenticate with the API, pass the token as a bearer token in the `Authorization` header. For example, in cURL:

```bash
curl <protocol>://<Layer5-cloud-hostname>/<API> \
curl <protocol>://<Layer5-cloud-hostname>/api/identity/users/profile \
-H "Authorization: Bearer <token>"
```

- Replace `<protocol>` with `http` or `https` depending on your Layer5 Cloud instance.
- Replace `<Layer5-cloud-hostname>` with the hostname or IP address of your hosted Layer5 Cloud instance. For example, [`https://cloud.layer5.io`](https://cloud.layer5.io).
- Replace `<API>` with the API endpoint you want to access. For example, `/api/identity/users/profile`.
- Replace the path with the API endpoint you want to access.
- Replace `<token>` with the security token you generated.

## Specifying Organization Context
Expand All @@ -41,11 +41,9 @@ Include the `layer5-current-orgid` header with your organization's ID to specify

{{< tabpane >}}
{{< tab header="cURL" >}}
curl -X POST "https://cloud.layer5.io/api/pattern" \
curl -X GET "https://cloud.layer5.io/api/environments" \
-H "Authorization: Bearer <Your-Token>" \
-H "layer5-current-orgid: <Your-Organization-ID>" \
-H "Content-Type: application/json" \
-d '{"name": "my-design", "pattern_file": "..."}'
-H "layer5-current-orgid: <Your-Organization-ID>"

{{< /tab >}}

Expand All @@ -54,44 +52,33 @@ curl -X POST "https://cloud.layer5.io/api/pattern" \
const token = "Your-Token";
const orgId = "Your-Organization-ID";

async function createDesign() {
const res = await fetch("https://cloud.layer5.io/api/pattern", {
method: "POST",
async function listEnvironments() {
const res = await fetch("https://cloud.layer5.io/api/environments", {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
"layer5-current-orgid": orgId,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "my-design",
pattern_file: "...",
}),
});
const data = await res.json();
console.log(data);
}

createDesign();
listEnvironments();

{{< /tab >}}

{{< tab header="Python" >}}

import requests
import json

url = "https://cloud.layer5.io/api/pattern"
url = "https://cloud.layer5.io/api/environments"
headers = {
"Authorization": "Bearer <Your-Token>",
"layer5-current-orgid": "<Your-Organization-ID>",
"Content-Type": "application/json"
}
payload = {
"name": "my-design",
"pattern_file": "..."
"layer5-current-orgid": "<Your-Organization-ID>"
}

res = requests.post(url, headers=headers, data=json.dumps(payload))
res = requests.get(url, headers=headers)
print(res.json())

{{< /tab >}}
Expand Down Expand Up @@ -161,12 +148,6 @@ print(res.json())

{{< /tabpane >}}

## All API Endpoints

{{< alert type="info" >}}
<a href="https://cloud.layer5.io/system/api/docs" target="_blank">Open API Endpoints in new window <i class="fa fa-external-link" aria-hidden="true"></i></a>
{{< /alert >}}

## API Example

The following example demonstrate how to retrieve information from the Academy REST APIs.
Expand Down Expand Up @@ -270,3 +251,5 @@ This returns the number of Total registered learners:
```
130
```


13 changes: 13 additions & 0 deletions content/en/cloud/reference/api-reference/rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: REST API Reference
description: >
Complete reference of all Layer5 Cloud REST API endpoints
weight: 1
categories: [Reference]
tags: [extensibility]
layout: rest-apis
display_toc: false
body_class: rest-api-reference-page
hide_readingtime: true
---

28 changes: 28 additions & 0 deletions layouts/docs/rest-apis.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{ define "main" }}
<div class="td-content rest-api-content-shell" data-bs-theme="dark">
<h1>{{ .Title }}</h1>
{{ with .Params.description }}<div class="lead">{{ . | markdownify }}</div>{{ end }}
<header class="article-meta{{ if or .Params.categories .Params.tags }} article-meta-bg{{ end }}">
{{ partial "taxonomy_terms_article_wrapper.html" . -}}
{{ if (and (not .Params.hide_readingtime) (.Site.Params.ui.readingtime.enable)) -}}
{{ partial "reading-time.html" . -}}
{{ end -}}
</header>
{{ with .Params.plan }}
{{ partial "plan-info.html" (dict "plan" .) }}
{{ end }}
{{ .Content }}
{{ partial "rest-apis/viewer.html" . }}
{{ if (.Site.Config.Services.Disqus.Shortname) -}}
<br />
{{- partial "disqus-comment.html" . -}}
{{ end -}}
{{ partial "pager.html" . }}
{{ partial "page-meta-lastmod.html" . }}
</div>

{{ partial "video-section-related.html" . -}}
<div style="margin-top: 2rem;">
{{ partial "recent-discussions.html" . -}}
</div>
{{ end }}
30 changes: 30 additions & 0 deletions layouts/partials/rest-apis/auth-summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ $operation := .operation }}
{{ $schemes := .schemes | default dict }}
{{ $summary := "" }}

{{ if isset $operation "security" }}
{{ $security := index $operation "security" }}
{{ if not $security }}
{{ $summary = "No authentication required" }}
{{ else }}
{{ $summaries := slice }}
{{ range $security }}
{{ range $schemeName, $scopes := . }}
{{ $itemSummary := replace $schemeName "_" " " | title }}
{{ $scheme := index $schemes $schemeName }}
{{ if and $scheme (eq (lower (index $scheme "type")) "http") (eq (lower (index $scheme "scheme")) "bearer") }}
{{ $itemSummary = "Bearer JWT" }}
{{ end }}
{{ if gt (len $scopes) 0 }}
{{ $itemSummary = printf "%s (%s)" $itemSummary (delimit $scopes ", ") }}
{{ end }}
{{ if not (in $summaries $itemSummary) }}
{{ $summaries = $summaries | append $itemSummary }}
{{ end }}
{{ end }}
{{ end }}
{{ $summary = delimit $summaries " or " }}
{{ end }}
{{ end }}

{{- $summary -}}
34 changes: 34 additions & 0 deletions layouts/partials/rest-apis/content-example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{ $content := . }}
{{ $example := "" }}

{{ if $content }}
{{ if isset $content "example" }}
{{ $example = index $content "example" }}
{{ else }}
{{ $examples := index $content "examples" }}
{{ if and $examples (reflect.IsMap $examples) }}
{{ range $name, $item := $examples }}
{{ if not $example }}
{{ if and (reflect.IsMap $item) (isset $item "value") }}
{{ $example = index $item "value" }}
{{ else if and (reflect.IsMap $item) (isset $item "externalValue") }}
{{ $example = index $item "externalValue" }}
{{ else }}
{{ $example = $item }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}

{{ if not $example }}
{{ $schema := index $content "schema" }}
{{ if and $schema (isset $schema "example") }}
{{ $example = index $schema "example" }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}

{{- if $example -}}
{{- $example | jsonify -}}
{{- end -}}
21 changes: 21 additions & 0 deletions layouts/partials/rest-apis/is-operation-included.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{ $operation := .operation | default . }}
{{ $audience := .audience | default "cloud" }}
{{ $xInternal := index $operation "x-internal" }}
{{ $include := false }}

{{ if not $xInternal }}
{{ $include = true }}
{{ else }}
{{ $values := slice }}
{{ if reflect.IsSlice $xInternal }}
{{ $values = $xInternal }}
{{ else }}
{{ $values = slice $xInternal }}
{{ end }}

{{ if in $values $audience }}
{{ $include = true }}
{{ end }}
{{ end }}

{{- if $include -}}true{{- else -}}false{{- end -}}
35 changes: 35 additions & 0 deletions layouts/partials/rest-apis/schema-properties.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{ $schema := .schema | default . }}
{{ $schemas := .schemas | default dict }}
{{ $source := partial "rest-apis/schema-source.html" (dict "schema" $schema "schemas" $schemas) | transform.Unmarshal (dict "format" "json") }}
{{ $label := "Schema fields" }}
{{ $result := dict "label" $label "rows" (slice) }}

{{ if and (not (index $source "properties")) (eq (index $source "type") "array") (index $source "items") (index (index $source "items") "properties") }}
{{ $source = index $source "items" }}
{{ $label = "Array item fields" }}
{{ $result = dict "label" $label "rows" (slice) }}
{{ end }}

{{ $properties := index $source "properties" }}
{{ if $properties }}
{{ $required := index $source "required" | default (slice) }}
{{ $rows := slice }}

{{ range $name, $property := $properties }}
{{ $order := 9999 }}
{{ with index $property "x-order" }}
{{ $order = . }}
{{ end }}
{{ $rows = $rows | append (dict
"name" $name
"order" $order
"schema" $property
"required" (in $required $name)
) }}
{{ end }}

{{ $rows = sort (sort $rows "name") "order" }}
{{ $result = dict "label" $label "rows" $rows }}
{{ end }}

{{- $result | jsonify -}}
57 changes: 57 additions & 0 deletions layouts/partials/rest-apis/schema-source.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{ $schema := .schema | default dict }}
{{ $schemas := .schemas | default dict }}

{{ if not $schema }}
{{- dict | jsonify -}}
{{- return -}}
{{ end }}

{{ $resolved := $schema }}

{{ if and (reflect.IsMap $schema) (index $schema "$ref") }}
{{ $refName := replaceRE "^.*/" "" (index $schema "$ref") }}
{{ with index $schemas $refName }}
{{ $resolved = partial "rest-apis/schema-source.html" (dict "schema" . "schemas" $schemas) | transform.Unmarshal (dict "format" "json") }}
{{ end }}
{{ else if and (reflect.IsMap $schema) (index $schema "allOf") }}
{{ $properties := dict }}
{{ $required := slice }}
{{ $description := index $schema "description" | default "" }}
{{ $type := index $schema "type" | default "object" }}

{{ range index $schema "allOf" }}
{{ $part := partial "rest-apis/schema-source.html" (dict "schema" . "schemas" $schemas) | transform.Unmarshal (dict "format" "json") }}
{{ with index $part "properties" }}
{{ $properties = merge $properties . }}
{{ end }}
{{ range (index $part "required" | default (slice)) }}
{{ if not (in $required .) }}
{{ $required = $required | append . }}
{{ end }}
{{ end }}
{{ if and (eq $description "") (index $part "description") }}
{{ $description = index $part "description" }}
{{ end }}
{{ if and (eq $type "object") (index $part "type") }}
{{ $type = index $part "type" }}
{{ end }}
{{ end }}

{{ with index $schema "properties" }}
{{ $properties = merge $properties . }}
{{ end }}
{{ range (index $schema "required" | default (slice)) }}
{{ if not (in $required .) }}
{{ $required = $required | append . }}
{{ end }}
{{ end }}

{{ $resolved = dict "type" $type "properties" $properties "required" $required }}
{{ if $description }}
{{ $resolved = merge $resolved (dict "description" $description) }}
{{ end }}
{{ else if and (reflect.IsMap $schema) (eq (index $schema "type") "array") (index $schema "items") }}
{{ $resolved = merge $schema (dict "items" (partial "rest-apis/schema-source.html" (dict "schema" (index $schema "items") "schemas" $schemas) | transform.Unmarshal (dict "format" "json"))) }}
{{ end }}

{{- $resolved | jsonify -}}
Loading
Loading