Merge pull request #1066 from slumbering/universe-http
create http universe package
This commit is contained in:
commit
564ad09d2b
@ -26,6 +26,7 @@
|
||||
- [gcp/secretmanager](./gcp/secretmanager.md) - Google Cloud Secret Manager
|
||||
- [git](./git.md) - Git operations
|
||||
- [go](./go.md) - Go build operations
|
||||
- [http](./http.md) - -
|
||||
- [io](./io.md) - IO operations
|
||||
- [java/maven](./java/maven.md) - Maven is a build automation tool for Java
|
||||
- [js/yarn](./js/yarn.md) - Yarn is a package manager for Javascript applications
|
||||
|
74
docs/reference/http.md
Normal file
74
docs/reference/http.md
Normal file
@ -0,0 +1,74 @@
|
||||
---
|
||||
sidebar_label: http
|
||||
---
|
||||
|
||||
# alpha.dagger.io/http
|
||||
|
||||
```cue
|
||||
import "alpha.dagger.io/http"
|
||||
```
|
||||
|
||||
## http.#Delete
|
||||
|
||||
### http.#Delete Inputs
|
||||
|
||||
_No input._
|
||||
|
||||
### http.#Delete Outputs
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*statusCode* | `string` |- |
|
||||
|*body* | `string` |- |
|
||||
|
||||
## http.#Do
|
||||
|
||||
### http.#Do Inputs
|
||||
|
||||
_No input._
|
||||
|
||||
### http.#Do Outputs
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*statusCode* | `string` |- |
|
||||
|*body* | `string` |- |
|
||||
|
||||
## http.#Get
|
||||
|
||||
### http.#Get Inputs
|
||||
|
||||
_No input._
|
||||
|
||||
### http.#Get Outputs
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*statusCode* | `string` |- |
|
||||
|*body* | `string` |- |
|
||||
|
||||
## http.#Post
|
||||
|
||||
### http.#Post Inputs
|
||||
|
||||
_No input._
|
||||
|
||||
### http.#Post Outputs
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*statusCode* | `string` |- |
|
||||
|*body* | `string` |- |
|
||||
|
||||
## http.#Put
|
||||
|
||||
### http.#Put Inputs
|
||||
|
||||
_No input._
|
||||
|
||||
### http.#Put Outputs
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*statusCode* | `string` |- |
|
||||
|*body* | `string` |- |
|
2
stdlib/.dagger/env/http/.gitignore
vendored
Normal file
2
stdlib/.dagger/env/http/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# dagger state
|
||||
state/**
|
23
stdlib/.dagger/env/http/values.yaml
vendored
Normal file
23
stdlib/.dagger/env/http/values.yaml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
plan:
|
||||
package: ./http/tests
|
||||
name: http
|
||||
sops:
|
||||
kms: []
|
||||
gcp_kms: []
|
||||
azure_kv: []
|
||||
hc_vault: []
|
||||
age:
|
||||
- recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk
|
||||
enc: |
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBhYjNpR1NHc3V4aGxGNzQ1
|
||||
YlZuQ0hrZHBDWGw0elJWZWU3c0U4KzVodEhzCkowME9JVlpWVEc1L2dHUE80Q29t
|
||||
bEpKTzRwYmhyc2N2a3dhaWg4aWZVWTQKLS0tIHNPWDVaQmh6SllzK2V3QjNJSWVH
|
||||
NHkxc1VXWHBwZFN5WFNxamdPaGZLM3MKaZra2gWvKl7+pXSihV70/mQYel9697z2
|
||||
eBSMuRPuZSjrg3JCBLhXTdIgUYxbMgWhILLpN5UqhTBVboUlRsURQA==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
lastmodified: "2021-10-19T11:50:42Z"
|
||||
mac: ENC[AES256_GCM,data:iG/JWnCk8UpThscQBqd9l7R7k1Xae1ED7WbYqPQmK5GRXhb7hIZGENnjn1aARnFjlCtEob6WvutWaZe7q1P90ZCirwXVBGewAeHchHqFA0KmUORRdtjMkZjnlRLMDKYu6CeNkaVK1al+B87CPlCBKz5UMeL9gnvug0k298AxWLY=,iv:RZEtSdbkxwgq5xEucnC+qyD2RCMk1DuaShjCh5Ihe5M=,tag:swW4R7ni0zoxOrc9lrV9Ww==,type:str]
|
||||
pgp: []
|
||||
encrypted_suffix: secret
|
||||
version: 3.7.1
|
86
stdlib/http/http.cue
Normal file
86
stdlib/http/http.cue
Normal file
@ -0,0 +1,86 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"alpha.dagger.io/alpine"
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
#Get: #Do & {method: "GET"}
|
||||
#Post: #Do & {method: "POST"}
|
||||
#Put: #Do & {method: "PUT"}
|
||||
#Delete: #Do & {method: "DELETE"}
|
||||
#Do: {
|
||||
url: string
|
||||
method: "GET" | "POST" | "PUT" | "DELETE" | "PATH" | "HEAD"
|
||||
|
||||
request: {
|
||||
body: string | *""
|
||||
header: [string]: string | [...string]
|
||||
token: dagger.#Secret | *null
|
||||
}
|
||||
|
||||
ctr: os.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: curl: true
|
||||
package: bash: "=5.1.0-r0"
|
||||
package: jq: "~=1.6"
|
||||
}
|
||||
shell: path: "/bin/bash"
|
||||
always: true
|
||||
|
||||
env: {
|
||||
METHOD: method
|
||||
HEADERS: json.Marshal(request.header)
|
||||
BODY: request.body
|
||||
URL: url
|
||||
}
|
||||
if request.token != null {
|
||||
secret: "/token": request.token
|
||||
}
|
||||
command: #"""
|
||||
curlArgs=(
|
||||
"$URL"
|
||||
-L --fail --silent --show-error
|
||||
--write-out "%{http_code}"
|
||||
-X "$METHOD"
|
||||
-o /response
|
||||
)
|
||||
|
||||
[ -n "$BODY" ] && curlArgs+=("-d" "'$BODY'")
|
||||
|
||||
headers="$(echo $HEADERS | jq -r 'to_entries | map(.key + ": " + (.value | tostring) + "\n") | add')"
|
||||
while read h; do
|
||||
curlArgs+=("-H" "'$h'")
|
||||
done <<< "$headers"
|
||||
if [ -e /token ]; then
|
||||
curlArgs+=("-H" "Authorization: bearer $(cat /token)")
|
||||
fi
|
||||
|
||||
curl "${curlArgs[@]}" > /status
|
||||
"""#
|
||||
}
|
||||
|
||||
statusCode: {
|
||||
os.#File & {
|
||||
from: ctr
|
||||
path: "/status"
|
||||
}
|
||||
}.contents @dagger(output)
|
||||
|
||||
body: {
|
||||
os.#File & {
|
||||
from: ctr
|
||||
path: "/response"
|
||||
}
|
||||
}.contents @dagger(output)
|
||||
|
||||
// Force os.#File exec before Atoi
|
||||
response: {
|
||||
"body": body
|
||||
"statusCode": strconv.Atoi(statusCode)
|
||||
}
|
||||
}
|
32
stdlib/http/tests/http.cue
Normal file
32
stdlib/http/tests/http.cue
Normal file
@ -0,0 +1,32 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/alpine"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
TestRequest: {
|
||||
req: #Get & {
|
||||
url: "https://api.github.com/"
|
||||
request: header: Accept: "application/json"
|
||||
}
|
||||
|
||||
testRaw: os.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: jq: "~=1.6"
|
||||
package: bash: true
|
||||
}
|
||||
env: STATUS: "\(req.response.statusCode)"
|
||||
files: "/content.json": {
|
||||
content: req.response.body
|
||||
mode: 0o500
|
||||
}
|
||||
shell: args: ["--noprofile", "--norc", "-eo", "pipefail", "-c"]
|
||||
command: #Command
|
||||
}
|
||||
}
|
||||
|
||||
#Command: #"""
|
||||
test "$(cat /content.json | jq -r .current_user_url)" = 'https://api.github.com/user'
|
||||
test "$STATUS" = "200"
|
||||
"""#
|
@ -23,6 +23,10 @@ setup() {
|
||||
dagger -e go up
|
||||
}
|
||||
|
||||
@test "http" {
|
||||
dagger -e http up
|
||||
}
|
||||
|
||||
@test "js/yarn" {
|
||||
dagger -e js-yarn up
|
||||
}
|
||||
|
Reference in New Issue
Block a user