-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sensor yamls can now specify the workflow location as a url path with this change. Refs #41
- Loading branch information
Showing
8 changed files
with
611 additions
and
289 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,21 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Sensor | ||
metadata: | ||
name: url-example | ||
labels: | ||
sensors.argoproj.io/controller-instanceid: axis | ||
spec: | ||
signals: | ||
- name: time | ||
calendar: | ||
interval: 10s | ||
triggers: | ||
- name: url-workflow-trigger | ||
resource: | ||
namespace: default | ||
group: argoproj.io | ||
version: v1alpha1 | ||
kind: Workflow | ||
source: | ||
url: | ||
path: "https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml" |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,49 @@ | ||
package store | ||
|
||
import ( | ||
"crypto/tls" | ||
"errors" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" | ||
) | ||
|
||
// URLReader implements the ArtifactReader interface for urls | ||
type URLReader struct { | ||
urlArtifact *v1alpha1.URLArtifact | ||
} | ||
|
||
// NewURLReader creates a new ArtifactReader for workflows at URL endpoints. | ||
func NewURLReader(urlArtifact *v1alpha1.URLArtifact) (ArtifactReader, error) { | ||
if urlArtifact == nil { | ||
panic("URLArtifact cannot be empty") | ||
} | ||
return &URLReader{urlArtifact}, nil | ||
} | ||
|
||
func (reader *URLReader) Read() ([]byte, error) { | ||
tr := &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
} | ||
client := &http.Client{Transport: tr} | ||
resp, err := client.Get(reader.urlArtifact.Path) | ||
if err != nil { | ||
log.Printf("Failed to read url %s. Err: %s\n", reader.urlArtifact.Path, err) | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
log.Printf("Failed to read %s. Status code: %d\n", reader.urlArtifact.Path, resp.StatusCode) | ||
return nil, errors.New("Status code " + string(resp.StatusCode)) | ||
} | ||
|
||
content, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Printf("Failed to read url body for %s. Err %s\n", reader.urlArtifact.Path, err) | ||
return nil, err | ||
} | ||
return content, 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,18 @@ | ||
package store | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestURLReader(t *testing.T) { | ||
urlArtifact := v1alpha1.URLArtifact{Path: "https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml"} | ||
urlReader, err := NewURLReader(&urlArtifact) | ||
assert.NotNil(t, urlReader) | ||
assert.Nil(t, err) | ||
data, err := urlReader.Read() | ||
assert.NotNil(t, data) | ||
assert.Nil(t, err) | ||
} |