-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring chief, rewrite the submission API to use native golang fu…
…nction and minimizing bash call The only exec used is for gpg, after much considering and prototyping using the works one seems to be the wiser choice machinery done, tarball deleted
- Loading branch information
Showing
17 changed files
with
795 additions
and
135 deletions.
There are no files selected for viewing
Binary file not shown.
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
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 |
---|---|---|
@@ -1,30 +1,12 @@ | ||
package endpoint | ||
|
||
import ( | ||
"net/http" | ||
|
||
service "github.com/blankon/irgsh-go/internal/artifact/service" | ||
httputil "github.com/blankon/irgsh-go/pkg/httputil" | ||
) | ||
|
||
// ArtifactHTTPEndpoint http endpoint for artifact | ||
type ArtifactHTTPEndpoint struct { | ||
service *service.ArtifactService | ||
// SubmissionRequest request parameter | ||
type SubmissionRequest struct { | ||
Tarball string `json:"tarball"` | ||
} | ||
|
||
// NewArtifactHTTPEndpoint returns new artifact instance | ||
func NewArtifactHTTPEndpoint(service *service.ArtifactService) *ArtifactHTTPEndpoint { | ||
return &ArtifactHTTPEndpoint{ | ||
service: service, | ||
} | ||
} | ||
|
||
// GetArtifactListHandler get artifact | ||
func (A *ArtifactHTTPEndpoint) GetArtifactListHandler(w http.ResponseWriter, r *http.Request) { | ||
artifactList, err := A.service.GetArtifactList(1, 1) | ||
if err != nil { | ||
httputil.ResponseError("Can't get artifact", 500, w) | ||
} | ||
|
||
httputil.ResponseJSON(artifactList, 200, w) | ||
// SubmissionResponse response | ||
type SubmissionResponse struct { | ||
PipelineID string `json:"pipelineId"` | ||
Jobs []string `json:"jobs"` | ||
} |
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,62 @@ | ||
package endpoint | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
service "github.com/blankon/irgsh-go/internal/artifact/service" | ||
httputil "github.com/blankon/irgsh-go/pkg/httputil" | ||
) | ||
|
||
// ArtifactHTTPEndpoint http endpoint for artifact | ||
type ArtifactHTTPEndpoint struct { | ||
service *service.ArtifactService | ||
} | ||
|
||
// NewArtifactHTTPEndpoint returns new artifact instance | ||
func NewArtifactHTTPEndpoint(service *service.ArtifactService) *ArtifactHTTPEndpoint { | ||
return &ArtifactHTTPEndpoint{ | ||
service: service, | ||
} | ||
} | ||
|
||
// GetArtifactListHandler get artifact | ||
func (A *ArtifactHTTPEndpoint) GetArtifactListHandler(w http.ResponseWriter, r *http.Request) { | ||
artifactList, err := A.service.GetArtifactList(1, 1) | ||
if err != nil { | ||
httputil.ResponseError("Can't get artifact", http.StatusInternalServerError, w) | ||
} | ||
|
||
httputil.ResponseJSON(artifactList, http.StatusOK, w) | ||
} | ||
|
||
// SubmitPackageHandler submit package | ||
func (A *ArtifactHTTPEndpoint) SubmitPackageHandler(w http.ResponseWriter, r *http.Request) { | ||
var requestParam SubmissionRequest | ||
|
||
b, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
httputil.ResponseError("Can't read request body", http.StatusBadRequest, w) | ||
} | ||
defer r.Body.Close() | ||
|
||
err = json.Unmarshal(b, &requestParam) | ||
if err != nil { | ||
httputil.ResponseError("Can't read request body", http.StatusBadRequest, w) | ||
} | ||
|
||
jobDetail, err := A.service.SubmitPackage(requestParam.Tarball) | ||
if err != nil { | ||
httputil.ResponseError("Can't complete the submission", http.StatusInternalServerError, w) | ||
} | ||
|
||
httputil.ResponseJSON(submissionToSubmissionResponse(jobDetail), http.StatusOK, w) | ||
} | ||
|
||
func submissionToSubmissionResponse(job service.Submission) SubmissionResponse { | ||
return SubmissionResponse{ | ||
PipelineID: job.PipelineID, | ||
Jobs: job.Jobs, | ||
} | ||
} |
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,17 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
// Artifact represent artifact data | ||
type Artifact struct { | ||
Name string | ||
} | ||
|
||
// Submission represent submission data | ||
type Submission struct { | ||
TaskUUID string `json:"taskUUID"` | ||
Timestamp time.Time `json:"timestamp"` | ||
SourceURL string `json:"sourceUrl"` | ||
PackageURL string `json:"packageUrl"` | ||
Tarball string `json:"tarball"` | ||
} |
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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
package repo | ||
|
||
//go:generate moq -out artifact_repo_moq.go . Repo | ||
import ( | ||
model "github.com/blankon/irgsh-go/internal/artifact/model" | ||
) | ||
|
||
// ArtifactModel represent artifact data | ||
type ArtifactModel struct { | ||
Name string | ||
} | ||
//go:generate moq -out artifact_repo_moq.go . Repo | ||
|
||
// ArtifactList list of artifacts | ||
type ArtifactList struct { | ||
TotalData int | ||
Artifacts []ArtifactModel | ||
Artifacts []model.Artifact | ||
} | ||
|
||
// Repo interface to operate with artifact | ||
type Repo interface { | ||
GetArtifactList(pageNum int64, rows int64) (ArtifactList, error) | ||
PutTarballToFile(tarball *string, taskUUID string) error | ||
ExtractSubmittedTarball(taskUUID string, deleteTarball bool) error | ||
VerifyArtifact(taskUUID string) (bool, error) | ||
} |
Oops, something went wrong.