diff --git a/api/api.yaml b/api/api.yaml index b4ec1c4..85d6894 100644 --- a/api/api.yaml +++ b/api/api.yaml @@ -28,17 +28,16 @@ paths: properties: name: type: string - repository: - type: string - artifact: - type: string - description: "The artifact kind the repository will host" - enum: - - helm + artifacts: + type: array + items: + type: string + enum: + - helm required: - name - repository - - artifact + - artifacts responses: '201': description: "Repository created" @@ -81,7 +80,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/Chart' + $ref: '#/components/schemas/Artifact' '400': description: "Bad request" content: @@ -94,6 +93,57 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' + post: + 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 + description: "The packaged chart file (.tgz)" + responses: + '201': + description: "Helm chart created" + content: + application/json: + schema: + type: object + properties: + name: + type: string + version: + type: string + required: + - name + - version + '400': + description: "Bad request" + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + '409': + description: "Conflict — chart version 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/{name}/versions: get: summary: "Get list of versions for a Helm chart" @@ -170,57 +220,6 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - /v1/helm/: - post: - summary: "Add Helm chart" - operationId: "addChart" - requestBody: - content: - multipart/form-data: - schema: - type: object - properties: - name: - type: string - repository: - type: string - chart: - type: string - format: binary - description: "The packaged chart file (.tgz)" - responses: - '201': - description: "Helm chart created" - content: - application/json: - schema: - type: object - properties: - name: - type: string - version: - type: string - required: - - name - - version - '400': - description: "Bad request" - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - '409': - description: "Conflict — chart version already exists" - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - '500': - description: "Internal server error" - content: - application/json: - schema: - $ref: '#/components/schemas/Error' components: schemas: @@ -236,16 +235,39 @@ components: properties: name: type: string - artifact: + artifacts: + type: array + $ref: '#/components/schemas/Artifact' + Artifact: + type: object + properties: + id: + type: string + kind: type: string enum: - - chart + - helm + required: + - id + - kind + discriminator: + propertyName: kind + mapping: + helm: '#/components/schemas/Chart' + # TODO: add more as required, e.g. docker, npm, maven + oneOf: + - $ref: '#/components/schemas/Chart' + # TODO: add more as required, e.g. docker, npm, maven Chart: type: object properties: + kind: + type: string + enum: + - helm id: - type: integer - format: int64 + type: string name: type: string - + version: + type: string diff --git a/go.mod b/go.mod index 3de56bd..5b9390d 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/getkin/kin-openapi v0.135.0 // indirect github.com/go-openapi/jsonpointer v0.22.4 // indirect github.com/go-openapi/swag v0.23.0 // indirect + github.com/go-openapi/swag/jsonname v0.25.4 // indirect github.com/google/go-cmp v0.7.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -23,10 +24,12 @@ require ( github.com/oasdiff/yaml3 v0.0.9 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/speakeasy-api/jsonpath v0.6.3 // indirect + github.com/speakeasy-api/openapi v1.19.2 // indirect github.com/speakeasy-api/openapi-overlay v0.10.2 // indirect github.com/ugorji/go/codec v1.3.1 // indirect github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect github.com/woodsbury/decimal128 v1.4.0 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/mod v0.33.0 // indirect golang.org/x/net v0.52.0 // indirect golang.org/x/sync v0.20.0 // indirect diff --git a/go.sum b/go.sum index b5cdeea..2824e7e 100644 --- a/go.sum +++ b/go.sum @@ -16,12 +16,16 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/getkin/kin-openapi v0.133.0 h1:pJdmNohVIJ97r4AUFtEXRXwESr8b0bD721u/Tz6k8PQ= github.com/getkin/kin-openapi v0.133.0/go.mod h1:boAciF6cXk5FhPqe/NQeBTeenbjqU4LhWBf09ILVvWE= +github.com/getkin/kin-openapi v0.135.0 h1:751SjYfbiwqukYuVjwYEIKNfrSwS5YpA7DZnKSwQgtg= github.com/getkin/kin-openapi v0.135.0/go.mod h1:6dd5FJl6RdX4usBtFBaQhk9q62Yb2J0Mk5IhUO/QqFI= github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonpointer v0.22.4 h1:dZtK82WlNpVLDW2jlA1YCiVJFVqkED1MegOUy9kR5T4= github.com/go-openapi/jsonpointer v0.22.4/go.mod h1:elX9+UgznpFhgBuaMQ7iu4lvvX1nvNsesQ3oxmYTw80= github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/go-openapi/swag/jsonname v0.25.4 h1:bZH0+MsS03MbnwBXYhuTttMOqk+5KcQ9869Vye1bNHI= +github.com/go-openapi/swag/jsonname v0.25.4/go.mod h1:GPVEk9CWVhNvWhZgrnvRA6utbAltopbKwDu8mXNUMag= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= @@ -57,6 +61,7 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.9.1 h1:LbtsOm5WAswyWbvTEOqhypdPeZzHavpZx96/n553mR8= github.com/mailru/easyjson v0.9.1/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= @@ -65,14 +70,17 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oapi-codegen/oapi-codegen/v2 v2.6.0 h1:4i+F2cvwBFZeplxCssNdLy3MhNzUD87mI3HnayHZkAU= github.com/oapi-codegen/oapi-codegen/v2 v2.6.0/go.mod h1:eWHeJSohQJIINJZzzQriVynfGsnlQVh0UkN2UYYcw4Q= +github.com/oapi-codegen/oapi-codegen/v2 v2.7.0 h1:/8daqIYZfwnsHEAZdHUu9m0D5LA+5DoJCP7zLlT5Cs0= github.com/oapi-codegen/oapi-codegen/v2 v2.7.0/go.mod h1:qzFy6iuobJw/hD1aRILee4G87/ShmhR0xYCwcUtZMCw= github.com/oapi-codegen/runtime v1.4.0 h1:KLOSFOp7UzkbS7Cs1ms6NBEKYr0WmH2wZG0KKbd2er4= github.com/oapi-codegen/runtime v1.4.0/go.mod h1:5sw5fxCDmnOzKNYmkVNF8d34kyUeejJEY8HNT2WaPec= github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY= github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw= +github.com/oasdiff/yaml v0.0.9 h1:zQOvd2UKoozsSsAknnWoDJlSK4lC0mpmjfDsfqNwX48= github.com/oasdiff/yaml v0.0.9/go.mod h1:8lvhgJG4xiKPj3HN5lDow4jZHPlx1i7dIwzkdAo6oAM= github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c= github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o= +github.com/oasdiff/yaml3 v0.0.9 h1:rWPrKccrdUm8J0F3sGuU+fuh9+1K/RdJlWF7O/9yw2g= github.com/oasdiff/yaml3 v0.0.9/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -96,7 +104,10 @@ github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/speakeasy-api/jsonpath v0.6.0 h1:IhtFOV9EbXplhyRqsVhHoBmmYjblIRh5D1/g8DHMXJ8= github.com/speakeasy-api/jsonpath v0.6.0/go.mod h1:ymb2iSkyOycmzKwbEAYPJV/yi2rSmvBCLZJcyD+VVWw= +github.com/speakeasy-api/jsonpath v0.6.3 h1:c+QPwzAOdrWvzycuc9HFsIZcxKIaWcNpC+xhOW9rJxU= github.com/speakeasy-api/jsonpath v0.6.3/go.mod h1:2cXloNuQ+RSXi5HTRaeBh7JEmjRXTiaKpFTdZiL7URI= +github.com/speakeasy-api/openapi v1.19.2 h1:md90tE71/M8jS3cuRlsuWP5Aed4xoG5PSRvXeZgCv/M= +github.com/speakeasy-api/openapi v1.19.2/go.mod h1:UfKa7FqE4jgexJZuj51MmdHAFGmDv0Zaw3+yOd81YKU= github.com/speakeasy-api/openapi-overlay v0.10.2 h1:VOdQ03eGKeiHnpb1boZCGm7x8Haj6gST0P3SGTX95GU= github.com/speakeasy-api/openapi-overlay v0.10.2/go.mod h1:n0iOU7AqKpNFfEt6tq7qYITC4f0yzVVdFw0S7hukemg= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= @@ -112,8 +123,11 @@ github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9N github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ= github.com/woodsbury/decimal128 v1.3.0 h1:8pffMNWIlC0O5vbyHWFZAt5yWvWcrHA+3ovIIjVWss0= github.com/woodsbury/decimal128 v1.3.0/go.mod h1:C5UTmyTjW3JftjUFzOVhC20BEQa2a4ZKOB5I6Zjb+ds= +github.com/woodsbury/decimal128 v1.4.0 h1:xJATj7lLu4f2oObouMt2tgGiElE5gO6mSWUjQsBgUlc= github.com/woodsbury/decimal128 v1.4.0/go.mod h1:BP46FUrVjVhdTbKT+XuQh2xfQaGki9LMIRJSFuh6THU= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U= go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/internal/api/api.gen.go b/internal/api/api.gen.go index cf2f7ae..bc3c6b1 100644 --- a/internal/api/api.gen.go +++ b/internal/api/api.gen.go @@ -2,10 +2,12 @@ // Package api provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.7.0 DO NOT EDIT. package api import ( + "encoding/json" + "errors" "fmt" "net/http" @@ -13,28 +15,43 @@ import ( openapi_types "github.com/oapi-codegen/runtime/types" ) -// Defines values for RepositoryArtifact. +// Defines values for ArtifactKind. const ( - RepositoryArtifactChart RepositoryArtifact = "chart" + ArtifactKindHelm ArtifactKind = "helm" ) -// Valid indicates whether the value is a known member of the RepositoryArtifact enum. -func (e RepositoryArtifact) Valid() bool { +// Valid indicates whether the value is a known member of the ArtifactKind enum. +func (e ArtifactKind) Valid() bool { switch e { - case RepositoryArtifactChart: + case ArtifactKindHelm: return true default: return false } } -// Defines values for AddRepositoryMultipartBodyArtifact. +// Defines values for ChartKind. const ( - Helm AddRepositoryMultipartBodyArtifact = "helm" + ChartKindHelm ChartKind = "helm" ) -// Valid indicates whether the value is a known member of the AddRepositoryMultipartBodyArtifact enum. -func (e AddRepositoryMultipartBodyArtifact) Valid() bool { +// Valid indicates whether the value is a known member of the ChartKind enum. +func (e ChartKind) Valid() bool { + switch e { + case ChartKindHelm: + return true + default: + return false + } +} + +// Defines values for AddRepositoryMultipartBodyArtifacts. +const ( + Helm AddRepositoryMultipartBodyArtifacts = "helm" +) + +// Valid indicates whether the value is a known member of the AddRepositoryMultipartBodyArtifacts enum. +func (e AddRepositoryMultipartBodyArtifacts) Valid() bool { switch e { case Helm: return true @@ -43,12 +60,27 @@ func (e AddRepositoryMultipartBodyArtifact) Valid() bool { } } +// Artifact defines model for Artifact. +type Artifact struct { + Id string `json:"id"` + Kind ArtifactKind `json:"kind"` + union json.RawMessage +} + +// ArtifactKind defines model for Artifact.Kind. +type ArtifactKind string + // Chart defines model for Chart. type Chart struct { - Id *int64 `json:"id,omitempty"` - Name *string `json:"name,omitempty"` + Id *string `json:"id,omitempty"` + Kind *ChartKind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` } +// ChartKind defines model for Chart.Kind. +type ChartKind string + // Error defines model for Error. type Error struct { Code *int `json:"code,omitempty"` @@ -57,13 +89,10 @@ type Error struct { // Repository defines model for Repository. type Repository struct { - Artifact *RepositoryArtifact `json:"artifact,omitempty"` - Name *string `json:"name,omitempty"` + Artifacts *Artifact `json:"artifacts,omitempty"` + Name *string `json:"name,omitempty"` } -// RepositoryArtifact defines model for Repository.Artifact. -type RepositoryArtifact string - // AddChartMultipartBody defines parameters for AddChart. type AddChartMultipartBody struct { // Chart The packaged chart file (.tgz) @@ -74,14 +103,12 @@ type AddChartMultipartBody struct { // AddRepositoryMultipartBody defines parameters for AddRepository. type AddRepositoryMultipartBody struct { - // Artifact The artifact kind the repository will host - Artifact AddRepositoryMultipartBodyArtifact `json:"artifact"` - Name string `json:"name"` - Repository string `json:"repository"` + Artifacts []AddRepositoryMultipartBodyArtifacts `json:"artifacts"` + Name string `json:"name"` } -// AddRepositoryMultipartBodyArtifact defines parameters for AddRepository. -type AddRepositoryMultipartBodyArtifact string +// AddRepositoryMultipartBodyArtifacts defines parameters for AddRepository. +type AddRepositoryMultipartBodyArtifacts string // AddChartMultipartRequestBody defines body for AddChart for multipart/form-data ContentType. type AddChartMultipartRequestBody AddChartMultipartBody @@ -89,13 +116,119 @@ type AddChartMultipartRequestBody AddChartMultipartBody // AddRepositoryMultipartRequestBody defines body for AddRepository for multipart/form-data ContentType. type AddRepositoryMultipartRequestBody AddRepositoryMultipartBody +// AsChart returns the union data inside the Artifact as a Chart +func (t Artifact) AsChart() (Chart, error) { + var body Chart + err := json.Unmarshal(t.union, &body) + return body, err +} + +// FromChart overwrites any union data inside the Artifact as the provided Chart +func (t *Artifact) FromChart(v Chart) error { + t.Kind = "helm" + + b, err := json.Marshal(v) + t.union = b + return err +} + +// MergeChart performs a merge with any union data inside the Artifact, using the provided Chart +func (t *Artifact) MergeChart(v Chart) error { + t.Kind = "helm" + + b, err := json.Marshal(v) + if err != nil { + return err + } + + merged, err := runtime.JSONMerge(t.union, b) + t.union = merged + return err +} + +func (t Artifact) Discriminator() (string, error) { + var discriminator struct { + Discriminator string `json:"kind"` + } + err := json.Unmarshal(t.union, &discriminator) + return discriminator.Discriminator, err +} + +func (t Artifact) ValueByDiscriminator() (interface{}, error) { + discriminator, err := t.Discriminator() + if err != nil { + return nil, err + } + switch discriminator { + case "helm": + return t.AsChart() + default: + return nil, errors.New("unknown discriminator value: " + discriminator) + } +} + +func (t Artifact) MarshalJSON() ([]byte, error) { + b, err := t.union.MarshalJSON() + if err != nil { + return nil, err + } + object := make(map[string]json.RawMessage) + if t.union != nil { + err = json.Unmarshal(b, &object) + if err != nil { + return nil, err + } + } + + object["id"], err = json.Marshal(t.Id) + if err != nil { + return nil, fmt.Errorf("error marshaling 'id': %w", err) + } + + object["kind"], err = json.Marshal(t.Kind) + if err != nil { + return nil, fmt.Errorf("error marshaling 'kind': %w", err) + } + + b, err = json.Marshal(object) + return b, err +} + +func (t *Artifact) UnmarshalJSON(b []byte) error { + err := t.union.UnmarshalJSON(b) + if err != nil { + return err + } + object := make(map[string]json.RawMessage) + err = json.Unmarshal(b, &object) + if err != nil { + return err + } + + if raw, found := object["id"]; found { + err = json.Unmarshal(raw, &t.Id) + if err != nil { + return fmt.Errorf("error reading 'id': %w", err) + } + } + + if raw, found := object["kind"]; found { + err = json.Unmarshal(raw, &t.Kind) + if err != nil { + return fmt.Errorf("error reading 'kind': %w", err) + } + } + + return err +} + // ServerInterface represents all server handlers. type ServerInterface interface { // Get all available Helm charts // (GET /v1/helm) GetCharts(w http.ResponseWriter, r *http.Request) // Add Helm chart - // (POST /v1/helm/) + // (POST /v1/helm) AddChart(w http.ResponseWriter, r *http.Request) // Get list of versions for a Helm chart // (GET /v1/helm/{name}/versions) @@ -152,6 +285,7 @@ func (siw *ServerInterfaceWrapper) AddChart(w http.ResponseWriter, r *http.Reque func (siw *ServerInterfaceWrapper) GetChartVersions(w http.ResponseWriter, r *http.Request) { var err error + _ = err // ------------- Path parameter "name" ------------- var name string @@ -177,6 +311,7 @@ func (siw *ServerInterfaceWrapper) GetChartVersions(w http.ResponseWriter, r *ht func (siw *ServerInterfaceWrapper) GetChart(w http.ResponseWriter, r *http.Request) { var err error + _ = err // ------------- Path parameter "repository" ------------- var repository string @@ -318,10 +453,10 @@ func Handler(si ServerInterface) http.Handler { return HandlerWithOptions(si, StdHTTPServerOptions{}) } -// ServeMux is an abstraction of http.ServeMux. +// ServeMux is an abstraction of [http.ServeMux]. type ServeMux interface { HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) - ServeHTTP(w http.ResponseWriter, r *http.Request) + http.Handler } type StdHTTPServerOptions struct { @@ -364,12 +499,12 @@ func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.H ErrorHandlerFunc: options.ErrorHandlerFunc, } - m.HandleFunc("GET "+options.BaseURL+"/v1/helm", wrapper.GetCharts) - m.HandleFunc("POST "+options.BaseURL+"/v1/helm/", wrapper.AddChart) - m.HandleFunc("GET "+options.BaseURL+"/v1/helm/{name}/versions", wrapper.GetChartVersions) - m.HandleFunc("GET "+options.BaseURL+"/v1/helm/{repository}/{name}/{version}", wrapper.GetChart) - m.HandleFunc("GET "+options.BaseURL+"/v1/repositories", wrapper.GetRepositories) - m.HandleFunc("POST "+options.BaseURL+"/v1/repositories", wrapper.AddRepository) + m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/helm", wrapper.GetCharts) + m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/v1/helm", wrapper.AddChart) + m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/helm/{name}/versions", wrapper.GetChartVersions) + m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/helm/{repository}/{name}/{version}", wrapper.GetChart) + m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/repositories", wrapper.GetRepositories) + m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/v1/repositories", wrapper.AddRepository) return m } diff --git a/internal/api/repositories.go b/internal/api/repositories.go index 23fa4a0..4f7fb7e 100644 --- a/internal/api/repositories.go +++ b/internal/api/repositories.go @@ -2,31 +2,22 @@ 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) + w.WriteHeader(http.StatusNotImplemented) _ = json.NewEncoder(w).Encode(Error{ - Code: new(int(http.StatusOK)), - Message: new(string("")), + Code: new(int(http.StatusNotImplemented)), + Message: new(string("Not implemented")), }) - 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")), + Code: new(int(http.StatusNotImplemented)), + Message: new(string("Not implemented")), }) - return } diff --git a/internal/api/repositories_test.go b/internal/api/repositories_test.go index 0420c82..78c6d5a 100644 --- a/internal/api/repositories_test.go +++ b/internal/api/repositories_test.go @@ -18,10 +18,10 @@ func newTestHandler() http.Handler { func TestCreate(t *testing.T) { handler := newTestHandler() - tests := []struct{ - name string - method string - path string + tests := []struct { + name string + method string + path string wantCode int wantBody string }{ @@ -29,7 +29,7 @@ func TestCreate(t *testing.T) { "GET repositories found", "GET", "/v1/repositories", - http.StatusOK, + http.StatusNotImplemented, "{}", }, }