1
0

initial commit

This commit is contained in:
2024-05-28 14:41:14 +03:00
commit ab6edbd967
24 changed files with 2044 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
// SPDX-License-Identifier: Apache-2.0
// (c) 2024, Konstantin Demin
package upload_spec
import (
f "git.krd.sh/krd/woodpecker-sonatype-nexus/nexus/upload_spec/field"
ftype "git.krd.sh/krd/woodpecker-sonatype-nexus/nexus/upload_spec/field_type"
)
var (
// keep map keys sorted
fallbackUploadSpec = map[string]UploadSpec{
"maven2": {
MultipleUpload: true,
ComponentFields: []f.UploadField{
{
Name: "groupId",
Type: ftype.String,
},
{
Name: "artifactId",
Type: ftype.String,
},
{
Name: "version",
Type: ftype.String,
},
{
Name: "generate-pom",
Type: ftype.Boolean,
Optional: true,
},
{
Name: "packaging",
Type: ftype.String,
Optional: true,
},
},
AssetFields: []f.UploadField{
{
Name: "extension",
Type: ftype.String,
},
{
Name: "classifier",
Type: ftype.String,
Optional: true,
},
},
},
"r": {
AssetFields: []f.UploadField{
{
Name: "pathId",
Type: ftype.String,
},
},
},
"raw": {
MultipleUpload: true,
ComponentFields: []f.UploadField{
{
Name: "directory",
Type: ftype.String,
},
},
AssetFields: []f.UploadField{
{
Name: "filename",
Type: ftype.String,
},
},
},
"yum": {
ComponentFields: []f.UploadField{
{
Name: "directory",
Type: ftype.String,
Optional: true,
},
},
AssetFields: []f.UploadField{
{
Name: "filename",
Type: ftype.String,
},
},
},
}
// keep array values sorted
fallbackSimpleSpecs = []string{
"apt",
"docker",
"helm",
"npm",
"nuget",
"pypi",
"rubygems",
}
)
func GetFallbackSpecs() map[string]UploadSpec {
rv := make(map[string]UploadSpec)
for t := range fallbackUploadSpec {
spec := fallbackUploadSpec[t]
spec.Format = t
rv[t] = spec
}
for _, t := range fallbackSimpleSpecs {
_, seen := rv[t]
if seen {
continue
}
rv[t] = UploadSpec{Format: t}
}
return rv
}

View File

@@ -0,0 +1,20 @@
// SPDX-License-Identifier: Apache-2.0
// (c) 2024, Konstantin Demin
package field
import (
ftype "git.krd.sh/krd/woodpecker-sonatype-nexus/nexus/upload_spec/field_type"
)
// repo: https://github.com/sonatype/nexus-public.git
// file: components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/upload/UploadFieldDefinition.java
type UploadField struct {
Name string `json:"name"`
Type ftype.UploadFieldType `json:"type,string"`
Optional bool `json:"optional"`
// optional fields
// Group string `json:"group,omitempty"`
// Description string `json:"description,omitempty"`
}

View File

@@ -0,0 +1,103 @@
// SPDX-License-Identifier: Apache-2.0
// (c) 2024, Konstantin Demin
package field_type
import (
"errors"
"reflect"
"strings"
)
type UploadFieldType uint8
// repo: https://github.com/sonatype/nexus-public.git
// file: components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/upload/UploadFieldDefinition.java
const (
// internal values
_Invariant UploadFieldType = iota
_Invalid
File
String
Boolean
)
var (
uploadFieldType_to_str map[UploadFieldType]string = map[UploadFieldType]string{
_Invariant: "",
_Invalid: "INVALID",
File: "file",
String: "string",
Boolean: "boolean",
}
uploadFieldType_to_reflect map[UploadFieldType]reflect.Kind = map[UploadFieldType]reflect.Kind{
_Invariant: reflect.Invalid,
_Invalid: reflect.Invalid,
File: reflect.String,
String: reflect.String,
Boolean: reflect.Bool,
}
uploadFieldType_from_str map[string]UploadFieldType = map[string]UploadFieldType{
"file": File,
"string": String,
"boolean": Boolean,
}
)
func (x UploadFieldType) IsInvariant() bool {
return x == _Invariant
}
func (x UploadFieldType) IsValid() bool {
switch x {
case File, String, Boolean:
return true
}
return false
}
func (x UploadFieldType) String() string {
s, ok := uploadFieldType_to_str[x]
if ok {
return s
}
return "INVARIANT"
}
func (x UploadFieldType) ToReflectKind() reflect.Kind {
t, ok := uploadFieldType_to_reflect[x]
if ok {
return t
}
return reflect.Invalid
}
func StringToUploadFieldType(s string) UploadFieldType {
if s == "" {
return _Invariant
}
x, ok := uploadFieldType_from_str[strings.ToLower(s)]
if ok {
return x
}
return _Invalid
}
func (x *UploadFieldType) UnmarshalJSON(b []byte) error {
s := string(b)
t := StringToUploadFieldType(s)
if !t.IsInvariant() {
if t.IsValid() {
*x = t
return nil
}
return errors.ErrUnsupported
}
return nil
}

21
nexus/upload_spec/spec.go Normal file
View File

@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0
// (c) 2024, Konstantin Demin
package upload_spec
import (
f "git.krd.sh/krd/woodpecker-sonatype-nexus/nexus/upload_spec/field"
)
// repo: https://github.com/sonatype/nexus-public.git
// files:
// - components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/rest/api/UploadDefinitionXO.groovy
// - components/nexus-repository-services/src/main/java/org/sonatype/nexus/repository/upload/UploadDefinition.java
type UploadSpec struct {
Format string `json:"format"`
MultipleUpload bool `json:"multipleUpload"`
ComponentFields []f.UploadField `json:"componentFields,omitempty"`
AssetFields []f.UploadField `json:"assetFields,omitempty"`
AllFieldNames map[string]bool
}