Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 85 additions & 3 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,71 @@ info:
title: "Artifact Store API specification"
version: "0.1.0"
paths:
/v1/repositories:
get:
summary: "Get all available repositories"
operationId: "getRepositories"
responses:
'200':
description: List of repositories
content:
application/json:
schema:
type: array
$ref: '#/components/schemas/Repository'
post:
summary: "Create repository"
operationId: "addRepository"
operation: addRepository
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
name:
type: string
repository:
type: string
artifact:
type: string
description: "The artifact kind the repository will host"
enum:
- helm
required:
- name
- repository
- artifact
responses:
'201':
description: "Repository created"
content:
application/json:
schema:
type: object
properties:
name:
type: string
required:
- name
'400':
description: "Bad request"
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'409':
description: "Conflict — repository already exists"
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: "Internal server error"
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/v1/helm:
get:
summary: "Get all available Helm charts"
Expand Down Expand Up @@ -61,18 +126,25 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/v1/helm/{name}/{version}:
/v1/helm/{repository}/{name}/{version}:
get:
summary: "Download version of Helm chart"
operationId: "getChart"
parameters:
- name: repository
in: path
required: false
schema:
type: string
default: default
description: "Chart repository"
- name: name
in: path
required: true
schema:
type: string
description: "Helm chart name"
- name: version
- name: version # TODO: make optional, default to 'latest'
in: path
required: true
schema:
Expand Down Expand Up @@ -103,14 +175,15 @@ paths:
summary: "Add Helm chart"
operationId: "addChart"
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
name:
type: string
repository:
type: string
chart:
type: string
format: binary
Expand Down Expand Up @@ -158,6 +231,15 @@ components:
type: integer
message:
type: string
Repository:
type: object
properties:
name:
type: string
artifact:
type: string
enum:
- chart
Chart:
type: object
properties:
Expand Down
111 changes: 105 additions & 6 deletions internal/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions internal/api/impl.go → internal/api/pkg_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,14 @@ import (
"net/http"
openapi_types "github.com/oapi-codegen/runtime/types"

"artifacts/internal/storage"
//"artifacts/internal/storage"
"artifacts/internal/storage/storage_error"
)

var chartMIMEType = []string{"application/gzip"}

type Server struct{
storageHandler storage.Storage
}

func NewServer(storageHandler storage.Storage) Server {
return Server{
storageHandler: storageHandler,
}
}
var chartMIMEType = []string{"application/octet-stream"}

func (s Server) GetCharts(w http.ResponseWriter, r *http.Request) {
data, err := s.storageHandler.Read("", "")
data, err := s.storageHandler.Read("", "", "")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
Expand All @@ -34,10 +24,10 @@ func (s Server) GetCharts(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(data)
}

func (s Server) GetChart(w http.ResponseWriter, r *http.Request, resource string, version string) {
func (s Server) GetChart(w http.ResponseWriter, r *http.Request, repository string, resource string, version string) {
w.Header().Set("Content-Type", "application/json")

data, err := s.storageHandler.Read(resource, version)
data, err := s.storageHandler.Read(repository, resource, version)

if err != nil {
if err == storage_error.NotFound {
Expand Down Expand Up @@ -89,6 +79,16 @@ func (s Server) AddChart(w http.ResponseWriter, r *http.Request) {
}
}()

repo := r.FormValue("repository")
if repo == "" {
w.WriteHeader(http.StatusBadRequest)
_ = json.NewEncoder(w).Encode(Error{
Code: new(int(http.StatusBadRequest)),
Message: new(string("Missing 'repository' parameter")),
})
return
}

// Extract chart name from form data
name := r.FormValue("name")
if name == "" {
Expand Down Expand Up @@ -144,7 +144,7 @@ func (s Server) AddChart(w http.ResponseWriter, r *http.Request) {
})
}

if err := s.storageHandler.Write(name, bytes); err != nil { // TODO: return created version
if err := s.storageHandler.Write(repo, name, bytes); err != nil { // TODO: return created version
w.WriteHeader(http.StatusInternalServerError)
_ = json.NewEncoder(w).Encode(Error{
Code: new(int(http.StatusInternalServerError)),
Expand Down
32 changes: 32 additions & 0 deletions internal/api/repositories.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package api

import (
"encoding/json"
// "fmt"
// "io"
// "slices"
"net/http"
//openapi_types "github.com/oapi-codegen/runtime/types"

// "artifacts/internal/storage"
// "artifacts/internal/storage/storage_error"
)

func (s Server) GetRepositories(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(Error{
Code: new(int(http.StatusOK)),
Message: new(string("")),
})
return
}

func (s Server) AddRepository(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(Error{
Code: new(int(http.StatusCreated)),
Message: new(string("Repository created")),
})
return
}
Loading