-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e5730cf
Showing
22 changed files
with
502 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: build | ||
|
||
on: push | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Install Opctl | ||
run: curl -L https://github.com/opctl/opctl/releases/download/0.1.45/opctl0.1.45.linux.tgz | sudo tar -xzv -C /usr/local/bin | ||
|
||
- name: Build | ||
run: opctl run build |
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,5 @@ | ||
# Jetbrains | ||
.idea/ | ||
|
||
# opctl | ||
*args*.yml |
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,10 @@ | ||
name: build | ||
description: builds the op | ||
run: | ||
serial: | ||
- op: | ||
ref: github.com/opspec-pkgs/_.op.bootstrap#4.1.1 | ||
inputs: | ||
srcDir: $(../..) | ||
- op: | ||
ref: test |
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,35 @@ | ||
name: e2eTest | ||
run: | ||
serial: | ||
- op: | ||
ref: $(../../) | ||
inputs: | ||
headers: | ||
Content-Type: | ||
- text/html | ||
url: https://google.com | ||
method: GET | ||
outputs: | ||
body: | ||
headers: | ||
protocol: | ||
statusCode: | ||
- container: | ||
image: | ||
ref: alpine | ||
cmd: | ||
- sh | ||
- -ce | ||
- | | ||
echo $(protocol) $(statusCode) | ||
echo 'Content-Type' | ||
echo $(headers[Content-Type][0]) | ||
echo 'headers' | ||
cat /headers | ||
echo "" | ||
echo "body" | ||
cat /body | ||
sleep 1 | ||
files: | ||
/body: $(body) | ||
/headers: $(headers) |
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,44 @@ | ||
name: provision-image | ||
description: | | ||
Provisions image for the op to [opspec-pkgs image registry](https://github.com/orgs/opspec-pkgs/packages) w/ name `$(opDotYml.name):${opDotYml.version}`. | ||
> Before first use, a Dockerfile MUST be added to `.opspec/provision-image` | ||
inputs: | ||
githubUsername: | ||
string: | ||
constraints: { minLength: 1 } | ||
description: user for logging in to github | ||
githubAccessToken: | ||
string: | ||
constraints: { minLength: 1 } | ||
description: accessToken for logging in to github | ||
isSecret: true | ||
run: | ||
serial: | ||
- op: | ||
ref: github.com/opspec-pkgs/yaml.parse#1.0.0 | ||
inputs: | ||
yaml: $(../../op.yml) | ||
outputs: | ||
result: $(opDotYml) | ||
- container: | ||
image: { ref: 'alpine:3.6' } | ||
cmd: [sh, -ce, 'echo -n ghcr.io/opspec-pkgs/${opName#*/*/}:$(opDotYml.version) > /imageName'] | ||
envVars: | ||
opName: $(opDotYml.name) | ||
files: | ||
/imageName: $(imageName) | ||
- op: | ||
ref: github.com/opspec-pkgs/docker.image.build#2.1.0 | ||
inputs: | ||
dockerfile: $(./Dockerfile) | ||
imageName: | ||
outputs: { imageTar } | ||
- op: | ||
ref: github.com/opspec-pkgs/docker.image.push#2.1.0 | ||
inputs: | ||
imageTar: | ||
imageName: | ||
registry: ghcr.io | ||
username: $(githubUsername) | ||
password: $(githubAccessToken) |
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,43 @@ | ||
name: release | ||
description: releases the op | ||
inputs: | ||
githubUsername: | ||
string: | ||
constraints: { minLength: 1 } | ||
description: user for logging in to github | ||
githubAccessToken: | ||
string: | ||
constraints: { minLength: 1 } | ||
description: accessToken for logging in to github | ||
isSecret: true | ||
run: | ||
serial: | ||
- op: | ||
ref: build | ||
- op: | ||
ref: github.com/opspec-pkgs/yaml.parse#1.0.0 | ||
inputs: | ||
yaml: $(../../op.yml) | ||
outputs: | ||
result: $(opDotYml) | ||
- op: | ||
ref: github.com/opspec-pkgs/git.repo.resolve-commit#1.0.2 | ||
inputs: { dotGitDir: $(../../.git) } | ||
outputs: { commit: } | ||
- container: | ||
image: { ref: 'alpine:3.6' } | ||
cmd: [sh, -ce, 'echo -n ${opName#*/*/} > /opRepo'] | ||
envVars: | ||
opName: $(opDotYml.name) | ||
files: | ||
/opRepo: $(opRepo) | ||
- op: | ||
ref: github.com/opspec-pkgs/github.release.create#1.1.0 | ||
inputs: | ||
owner: opspec-pkgs | ||
repo: $(opRepo) | ||
loginUsername: $(githubUsername) | ||
loginPassword: $(githubAccessToken) | ||
tag: $(opDotYml.version) | ||
commitish: $(commit) | ||
name: $(opDotYml.version) |
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,8 @@ | ||
name: test | ||
description: tests the op | ||
run: | ||
op: | ||
ref: github.com/opspec-pkgs/opctl.op.validate#1.0.0 | ||
inputs: | ||
opctlVersion: 0.1.53 | ||
op: $(../..) |
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,6 @@ | ||
# Change Log | ||
|
||
All notable changes will be documented in this file in accordance with | ||
[![keepachangelog 1.0.0](https://img.shields.io/badge/keepachangelog-1.0.0-brightgreen.svg)](http://keepachangelog.com/en/1.0.0/) | ||
|
||
## \[Unreleased] |
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 @@ | ||
* @opspec-pkgs/maintainers |
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,58 @@ | ||
[![Build Status](https://github.com/opspec-pkgs/http.send/workflows/build/badge.svg?branch=main)](https://github.com/opspec-pkgs/http.send/actions?query=workflow%3Abuild+branch%3Amain) | ||
|
||
<img src="icon.svg" alt="icon" height="100px"> | ||
|
||
# Problem statement | ||
|
||
Sends an http request | ||
|
||
# Example usage | ||
|
||
## Visualize | ||
|
||
```shell | ||
opctl ui github.com/opspec-pkgs/http.send#1.0.0 | ||
``` | ||
|
||
## Run | ||
|
||
``` | ||
opctl run github.com/opspec-pkgs/http.send#1.0.0 | ||
``` | ||
|
||
## Compose | ||
|
||
```yaml | ||
op: | ||
ref: github.com/opspec-pkgs/http.send#1.0.0 | ||
inputs: | ||
method: # 👈 required; provide a value | ||
url: # 👈 required; provide a value | ||
## uncomment to override defaults | ||
# body: "[object Object]" | ||
# headers: [object Object] | ||
outputs: | ||
body: | ||
headers: | ||
protocol: | ||
statusCode: | ||
``` | ||
# Support | ||
join us on | ||
[![Slack](https://img.shields.io/badge/slack-opctl-E01563.svg)](https://join.slack.com/t/opctl/shared_invite/zt-51zodvjn-Ul_UXfkhqYLWZPQTvNPp5w) | ||
or | ||
[open an issue](https://github.com/opspec-pkgs/http.send/issues) | ||
# Releases | ||
releases are versioned according to | ||
[![semver 2.0.0](https://img.shields.io/badge/semver-2.0.0-brightgreen.svg)](http://semver.org/spec/v2.0.0.html) | ||
and [tagged](https://git-scm.com/book/en/v2/Git-Basics-Tagging); see | ||
[CHANGELOG.md](CHANGELOG.md) for release notes | ||
# Contributing | ||
see | ||
[project/CONTRIBUTING.md](https://github.com/opspec-pkgs/project/blob/main/CONTRIBUTING.md) |
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,3 @@ | ||
module github.com/opspec-pkgs/http.send | ||
|
||
go 1.23.2 |
Empty file.
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,2 @@ | ||
// package inout is used to process op input to an http request and http response to op output | ||
package inout |
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,54 @@ | ||
package inout | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func getHeaders() ( | ||
map[string][]string, | ||
error, | ||
) { | ||
headersJSONBytes, err := os.ReadFile(HeadersFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rawHeaders := map[string][]interface{}{} | ||
if err := json.Unmarshal(headersJSONBytes, &rawHeaders); err != nil { | ||
return nil, err | ||
} | ||
|
||
headersMap := http.Header{} | ||
for k, vSlice := range rawHeaders { | ||
for _, rawV := range vSlice { | ||
v, err := convertToString(rawV) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
headersMap.Add(k, v) | ||
} | ||
} | ||
|
||
return headersMap, nil | ||
} | ||
|
||
func convertToString( | ||
in interface{}, | ||
) (string, error) { | ||
if s, ok := in.(string); ok { | ||
return s, nil | ||
} else if b, ok := in.(bool); ok { | ||
return strconv.FormatBool(b), nil | ||
} else if f, ok := in.(float64); ok { | ||
return strconv.FormatFloat(f, 'f', -1, 64), nil | ||
} else if i, ok := in.(int64); ok { | ||
return strconv.FormatInt(i, 10), nil | ||
} | ||
|
||
return "", fmt.Errorf("%+v not a valid header value", in) | ||
} |
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,46 @@ | ||
package inout | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func GetRequest() ( | ||
*http.Request, | ||
error, | ||
) { | ||
methodBytes, err := os.ReadFile(MethodFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
urlBytes, err := os.ReadFile(URLFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
reqBody, err := os.Open(BodyFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req, err := http.NewRequest( | ||
string(methodBytes), | ||
string(urlBytes), | ||
reqBody, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if req.ContentLength == 0 { | ||
req.Body = nil | ||
} | ||
|
||
req.Header, err = getHeaders() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return req, nil | ||
} |
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,10 @@ | ||
package inout | ||
|
||
const ( | ||
BodyFilePath = "/body.txt" | ||
HeadersFilePath = "/headers.json" | ||
MethodFilePath = "/method.txt" | ||
ProtocolFilePath = "/protocol.txt" | ||
StatusCodeFilePath = "/statusCode.txt" | ||
URLFilePath = "/url.txt" | ||
) |
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,20 @@ | ||
package inout | ||
|
||
import ( | ||
"io" | ||
"os" | ||
) | ||
|
||
func setBody( | ||
body io.ReadCloser, | ||
) error { | ||
bodyFile, err := os.Create(BodyFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
defer bodyFile.Close() | ||
|
||
_, err = io.Copy(bodyFile, body) | ||
defer body.Close() | ||
return err | ||
} |
Oops, something went wrong.