Skip to content

Commit e8f48af

Browse files
authored
Init http documentation (#2083)
* feat(http): init http documentation * fix: typo
1 parent c00ca8c commit e8f48af

File tree

3 files changed

+181
-0
lines changed

3 files changed

+181
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: End to end test of the 'http' resource kind
2+
pipelineid: "e2e/http"
3+
4+
# Sources of type http returns either the body or a header
5+
sources:
6+
# Returns the content of the 'maven-metadata.xml' file content as source (multi-line, direct HTTP/200)
7+
getJenkinsWarArtifactMetadatas:
8+
kind: http
9+
spec:
10+
url: https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
11+
# Returns the content of the 'checksums.txt' file content as source (multi-line, following redirections HTTP/3xx)
12+
getUpdatecli0.65.1Checksums:
13+
kind: http
14+
spec:
15+
url: https://github.com/updatecli/updatecli/releases/download/v0.65.1/checksums.txt # HTTP/302 (GitHub redirection to raw.githubusercontent.com)
16+
## Empty Source due to HTTP/3xx not followed (e.g. empty body)
17+
getUpdatecli0.65.1ChecksumsNoFollow:
18+
kind: http
19+
spec:
20+
url: https://github.com/updatecli/updatecli/releases/download/v0.65.1/checksums.txt # HTTP/302 (GitHub redirection to raw.githubusercontent.com)
21+
request:
22+
nofollowredirects: true # Default is false
23+
# Returns the content of the Header 'Location' (e.g. the target of the HTTP redirect)
24+
getRedirectLocationForUpdatecliLinuxAmd64Archive:
25+
kind: http
26+
spec:
27+
url: https://github.com/updatecli/updatecli/releases/download/v0.65.1/updatecli_Linux_arm64.tar.gz
28+
returnresponseheader: Location
29+
# Returns the content of the 'maven-metadata.xml' file from the private URL (custom headers for the request)
30+
getWithCustomRequest:
31+
kind: http
32+
spec:
33+
url: https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
34+
request:
35+
headers:
36+
Authorization: 'Bearer Token'
37+
Accept: 'application/xml'
38+
verb: GET
39+
## Source fails with an error: the URL returns HTTP/404 (same for server-side errors such as HTTP/5xx)
40+
# failOnHttpError:
41+
# kind: http
42+
# spec:
43+
# url: https://google.com/do-not-exist
44+
45+
46+
conditions:
47+
# Returns 'true' if the specified URL returns HTTP/1xx, HTTP/2xx or HTTP/3xx
48+
checkForURL:
49+
kind: http
50+
sourceid: getJenkinsWarArtifactMetadatas
51+
spec:
52+
url: https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
53+
## Conditions returns 'false' as the URL returns HTTP/404
54+
## If there is an HTTP/500 (server side error) then the conditions fails with an ERROR (different than returning false which "skips" the pipeline)
55+
# checkForNonExistingUrl:
56+
# kind: http
57+
# sourceid: getJenkinsWarArtifactMetadatas
58+
# spec:
59+
# url: https://google.com/do-not-exist
60+
# Returns 'true' if the specified URL returns HTTP/1xx, HTTP/2xx or HTTP/3xx to the custom request (custom verb and headers)
61+
checkWithCustomRequest:
62+
kind: http
63+
sourceid: getJenkinsWarArtifactMetadatas
64+
spec:
65+
url: https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
66+
request:
67+
headers:
68+
Authorization: 'Bearer Token'
69+
Accept: 'application/xml'
70+
verb: HEAD
71+
# Returns 'true' if the response code is HTTP/302 and has header "Content-Type" set to "application/xhtml"
72+
getUpdatecli0.65.1Checksums:
73+
kind: http
74+
sourceid: getJenkinsWarArtifactMetadatas
75+
spec:
76+
url: https://github.com/updatecli/updatecli/releases/download/v0.65.1/checksums.txt # HTTP/302 (GitHub redirection to raw.githubusercontent.com)
77+
responseasserts:
78+
statuscode: 302
79+
headers:
80+
Content-Type: "text/html; charset=utf-8"
81+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Basic Json Example
2+
3+
sources:
4+
http:
5+
name: Get value from json
6+
kind: json
7+
spec:
8+
file: https://www.updatecli.io/schema/latest/config.json
9+
key: $id
10+
semverVersion:
11+
kind: json
12+
name: Get latest version
13+
spec:
14+
file: https://www.updatecli.io/changelogs/updatecli/_index.json
15+
query: ".Changelogs.[*].Tag"
16+
versionfilter:
17+
kind: semver
18+
pattern: "v0.92.0"
19+
20+
conditions:
21+
http:
22+
name: Test value from json
23+
kind: json
24+
disablesourceinput: true
25+
spec:
26+
file: https://www.updatecli.io/schema/latest/config.json
27+
key: $schema
28+
value: http://json-schema.org/draft-04/schema
29+
30+
http-query:
31+
kind: json
32+
name: Get latest version
33+
disablesourceinput: true
34+
spec:
35+
file: https://www.updatecli.io/changelogs/updatecli/_index.json
36+
key: ".Changelogs.(Tag=v0.92.0).PublishedAt"
37+
value: "2025-01-12 08:14:30 +0000 UTC"
38+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "HTTP"
3+
description: "Run HTML request"
4+
lead: "kind: http"
5+
date: 2024-02-26T09:00:00+02:00
6+
draft: false
7+
images: []
8+
menu:
9+
docs:
10+
parent: "plugin-resource"
11+
toc: true
12+
plugins:
13+
- source
14+
- condition
15+
- target
16+
---
17+
// <!-- Required for asciidoctor -->
18+
:toc:
19+
// Set toclevels to be at least your hugo [markup.tableOfContents.endLevel] config key
20+
:toclevels: 4
21+
22+
[cols="1^,1^,1^",options=header]
23+
|===
24+
| source | condition | target
25+
| &#10004; | &#10004; | &#10004;
26+
|===
27+
28+
== Description
29+
30+
**source**
31+
32+
The HTML "source" retrieves an information from a HTTP request.
33+
34+
**condition**
35+
36+
The HTML "condition" tests that an information exist in a HTTP response.
37+
38+
**target**
39+
40+
The HTML "target" updates a HTTP response.
41+
42+
== Parameters
43+
44+
{{< resourceparameters "sources" "http" >}}
45+
46+
== Example
47+
48+
[source,yaml]
49+
----
50+
# updatecli.yaml
51+
{{<include "assets/code_example/docs/plugins/resources/http/updatecli.d/default.yaml">}}
52+
----
53+
54+
== Important
55+
56+
Most of the Updatecli plugins that manipulate files can usually specify the http scheme in the file path to retrieve the file from a remote location to be used in a source or a condition. But the HTTP plugin is designed to provide more flexibility when working with HTTP requests via additional settings like custom headers, or custom http verbs. Also worth mentioning the http plugin also works for targets.
57+
58+
[source,yaml]
59+
----
60+
# updatecli.yaml
61+
{{<include "assets/code_example/docs/plugins/resources/http/updatecli.d/json.yaml">}}
62+
----

0 commit comments

Comments
 (0)