Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ k8s API v1alpha2. #665

Closed
wants to merge 4 commits into from
Closed
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
8 changes: 4 additions & 4 deletions addon/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (h *Task) Data() (d any) {
}

// DataWith populates the addon data object.
func (h *Task) DataWith(object interface{}) (err error) {
func (h *Task) DataWith(object any) (err error) {
b, _ := json.Marshal(h.task.Data)
err = json.Unmarshal(b, object)
return
Expand All @@ -114,7 +114,7 @@ func (h *Task) Succeeded() {

// Failed report addon failed.
// The reason can be a printf style format.
func (h *Task) Failed(reason string, v ...interface{}) {
func (h *Task) Failed(reason string, v ...any) {
reason = fmt.Sprintf(reason, v...)
h.Error(api.TaskError{
Severity: "Error",
Expand All @@ -128,7 +128,7 @@ func (h *Task) Failed(reason string, v ...interface{}) {
}

// Errorf report addon error.
func (h *Task) Errorf(severity, description string, v ...interface{}) {
func (h *Task) Errorf(severity, description string, v ...any) {
h.Error(api.TaskError{
Severity: severity,
Description: fmt.Sprintf(description, v...),
Expand All @@ -153,7 +153,7 @@ func (h *Task) Error(error ...api.TaskError) {

// Activity report addon activity.
// The description can be a printf style format.
func (h *Task) Activity(entry string, v ...interface{}) {
func (h *Task) Activity(entry string, v ...any) {
entry = fmt.Sprintf(entry, v...)
lines := strings.Split(entry, "\n")
for i := range lines {
Expand Down
2 changes: 1 addition & 1 deletion api/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8s "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ type DepAppReport struct {
}

// FactMap map.
type FactMap map[string]interface{}
type FactMap map[string]any

// IssueWriter used to create a file containing issues.
type IssueWriter struct {
Expand Down
12 changes: 6 additions & 6 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ func (h ApplicationHandler) FactList(ctx *gin.Context, key FactKey) {
facts := FactMap{}
for i := range list {
fact := &list[i]
var v interface{}
var v any
_ = json.Unmarshal(fact.Value, &v)
facts[fact.Key] = v
}
Expand Down Expand Up @@ -730,7 +730,7 @@ func (h ApplicationHandler) FactGet(ctx *gin.Context) {
return
}

var v interface{}
var v any
_ = json.Unmarshal(list[0].Value, &v)
h.Respond(ctx, http.StatusOK, v)
}
Expand Down Expand Up @@ -929,7 +929,7 @@ func (h ApplicationHandler) StakeholdersUpdate(ctx *gin.Context) {
}

db = h.DB(ctx).Model(m).Omit(clause.Associations, "BucketID")
result = db.Updates(map[string]interface{}{"OwnerID": r.ownerID()})
result = db.Updates(map[string]any{"OwnerID": r.ownerID()})
if result.Error != nil {
_ = ctx.Error(result.Error)
return
Expand Down Expand Up @@ -1246,9 +1246,9 @@ type Repository struct {

// Fact REST nested resource.
type Fact struct {
Key string `json:"key"`
Value interface{} `json:"value"`
Source string `json:"source"`
Key string `json:"key"`
Value any `json:"value"`
Source string `json:"source"`
}

func (r *Fact) With(m *model.Fact) {
Expand Down
22 changes: 11 additions & 11 deletions api/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (h *BaseHandler) preLoad(db *gorm.DB, fields ...string) (tx *gorm.DB) {
}

// fields builds a map of fields.
func (h *BaseHandler) fields(m interface{}) (mp map[string]interface{}) {
func (h *BaseHandler) fields(m any) (mp map[string]any) {
mp = reflect.Fields(m)
return
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (h *BaseHandler) HasScope(ctx *gin.Context, scope string) (b bool) {

// Bind based on Content-Type header.
// Opinionated towards json.
func (h *BaseHandler) Bind(ctx *gin.Context, r interface{}) (err error) {
func (h *BaseHandler) Bind(ctx *gin.Context, r any) (err error) {
switch ctx.ContentType() {
case "",
binding.MIMEPOSTForm,
Expand All @@ -144,7 +144,7 @@ func (h *BaseHandler) Bind(ctx *gin.Context, r interface{}) (err error) {

// BindJSON attempts to bind a request body to a struct, assuming that the body is JSON.
// Binding is strict: unknown fields in the input will cause binding to fail.
func (h *BaseHandler) BindJSON(ctx *gin.Context, r interface{}) (err error) {
func (h *BaseHandler) BindJSON(ctx *gin.Context, r any) (err error) {
if ctx.Request == nil || ctx.Request.Body == nil {
err = errors.New("invalid request")
return
Expand All @@ -162,7 +162,7 @@ func (h *BaseHandler) BindJSON(ctx *gin.Context, r interface{}) (err error) {

// BindYAML attempts to bind a request body to a struct, assuming that the body is YAML.
// Binding is strict: unknown fields in the input will cause binding to fail.
func (h *BaseHandler) BindYAML(ctx *gin.Context, r interface{}) (err error) {
func (h *BaseHandler) BindYAML(ctx *gin.Context, r any) (err error) {
if ctx.Request == nil || ctx.Request.Body == nil {
err = errors.New("invalid request")
return
Expand All @@ -179,7 +179,7 @@ func (h *BaseHandler) BindYAML(ctx *gin.Context, r interface{}) (err error) {
}

// Validate that the struct field values obey the binding field tags.
func (h *BaseHandler) Validate(r interface{}) (err error) {
func (h *BaseHandler) Validate(r any) (err error) {
if binding.Validator == nil {
return
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func (h *BaseHandler) Status(ctx *gin.Context, code int) {
}

// Respond sets the response.
func (h *BaseHandler) Respond(ctx *gin.Context, code int, r interface{}) {
func (h *BaseHandler) Respond(ctx *gin.Context, code int, r any) {
rtx := WithContext(ctx)
rtx.Respond(code, r)
}
Expand Down Expand Up @@ -308,14 +308,14 @@ func (r *Resource) With(m *model.Model) {
}

// ref with id and named model.
func (r *Resource) ref(id uint, m interface{}) (ref Ref) {
func (r *Resource) ref(id uint, m any) (ref Ref) {
ref.ID = id
ref.Name = r.nameOf(m)
return
}

// refPtr with id and named model.
func (r *Resource) refPtr(id *uint, m interface{}) (ref *Ref) {
func (r *Resource) refPtr(id *uint, m any) (ref *Ref) {
if id == nil {
return
}
Expand All @@ -334,7 +334,7 @@ func (r *Resource) idPtr(ref *Ref) (id *uint) {
}

// nameOf model.
func (r *Resource) nameOf(m interface{}) (name string) {
func (r *Resource) nameOf(m any) (name string) {
name = reflect.NameOf(m)
return
}
Expand Down Expand Up @@ -406,7 +406,7 @@ type Sort = sort.Sort

// Decoder binding decoder.
type Decoder interface {
Decode(r interface{}) (err error)
Decode(r any) (err error)
}

// Cursor Paginated rows iterator.
Expand All @@ -419,7 +419,7 @@ type Cursor struct {
}

// Next returns true when has next row.
func (r *Cursor) Next(m interface{}) (next bool) {
func (r *Cursor) Next(m any) (next bool) {
if r.Error != nil {
next = true
return
Expand Down
2 changes: 1 addition & 1 deletion api/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (h BatchHandler) TagsCreate(ctx *gin.Context) {
}

func (h BatchHandler) create(ctx *gin.Context, create gin.HandlerFunc) {
var resources []interface{}
var resources []any
err := h.Bind(ctx, &resources)
if err != nil {
_ = ctx.Error(err)
Expand Down
4 changes: 2 additions & 2 deletions api/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Context struct {
// Response values.
type Response struct {
Status int
Body interface{}
Body any
}

// Status sets the values to respond to the request with.
Expand All @@ -42,7 +42,7 @@ func (r *Context) Status(status int) {
}

// Respond sets the values to respond to the request with.
func (r *Context) Respond(status int, body interface{}) {
func (r *Context) Respond(status int, body any) {
r.Response = Response{
Status: status,
Body: body,
Expand Down
2 changes: 1 addition & 1 deletion api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type BatchError struct {

type BatchErrorItem struct {
Error error
Resource interface{}
Resource any
}

func (r BatchError) Error() string {
Expand Down
2 changes: 1 addition & 1 deletion api/filter/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (r *Error) Is(err error) (matched bool) {
}

// Errorf build error.
func Errorf(s string, v ...interface{}) (err error) {
func Errorf(s string, v ...any) (err error) {
err = &Error{fmt.Sprintf(s, v...)}
return
}
6 changes: 3 additions & 3 deletions api/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (f *Field) Where(in *gorm.DB) (out *gorm.DB) {

// SQL builds SQL.
// Returns statement and values (for ?).
func (f *Field) SQL() (s string, vList []interface{}) {
func (f *Field) SQL() (s string, vList []any) {
name := f.Name()
switch len(f.Value) {
case 0:
Expand Down Expand Up @@ -296,7 +296,7 @@ func (f *Field) SQL() (s string, vList []interface{}) {
s += ")"
default:
values := f.Value.ByKind(LITERAL, STRING)
var collection []interface{}
var collection []any
for i := range values {
v := AsValue(values[i])
collection = append(collection, v)
Expand Down Expand Up @@ -395,7 +395,7 @@ func (r *Assert) assert(p *Predicate) (err error) {
}

// AsValue returns the real value.
func AsValue(t Token) (object interface{}) {
func AsValue(t Token) (object any) {
v := t.Value
object = v
switch t.Kind {
Expand Down
4 changes: 2 additions & 2 deletions api/filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestFilter(t *testing.T) {
}))
sql, values := f.SQL()
g.Expect(sql).To(gomega.Equal("category IN ?"))
g.Expect(values[0]).To(gomega.Equal([]interface{}{"a", "b", "c"}))
g.Expect(values[0]).To(gomega.Equal([]any{"a", "b", "c"}))

f, found = filter.Field("name.first")
g.Expect(found).To(gomega.BeTrue())
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestFilter(t *testing.T) {
g.Expect(found).To(gomega.BeTrue())
sql, values = f.SQL()
g.Expect(sql).To(gomega.Equal("(category LIKE ? OR category LIKE ?)"))
g.Expect(values).To(gomega.Equal([]interface{}{"a", "b"}))
g.Expect(values).To(gomega.Equal([]any{"a", "b"}))
}

func TestValidation(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (h ImportHandler) applicationFromRow(fileName string, row []string) (app mo
}

// Import REST resource.
type Import map[string]interface{}
type Import map[string]any

// ImportSummary REST resource.
type ImportSummary struct {
Expand Down
4 changes: 2 additions & 2 deletions api/questionnaire.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ func (h QuestionnaireHandler) Update(ctx *gin.Context) {
updated := r.Model()
updated.ID = id
updated.UpdateUser = h.CurrentUser(ctx)
var fields map[string]interface{}
var fields map[string]any
if m.Builtin() {
fields = map[string]interface{}{
fields = map[string]any{
"updateUser": updated.UpdateUser,
"required": updated.Required,
}
Expand Down
10 changes: 5 additions & 5 deletions api/reflect/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

// Fields returns a map of fields.
func Fields(m interface{}) (mp map[string]interface{}) {
var inspect func(r interface{})
inspect = func(r interface{}) {
func Fields(m any) (mp map[string]any) {
var inspect func(r any)
inspect = func(r any) {
mt := reflect.TypeOf(r)
mv := reflect.ValueOf(r)
if mt.Kind() == reflect.Ptr {
Expand Down Expand Up @@ -55,13 +55,13 @@ func Fields(m interface{}) (mp map[string]interface{}) {
}
}
}
mp = map[string]interface{}{}
mp = map[string]any{}
inspect(m)
return
}

// NameOf returns the name of a model.
func NameOf(m interface{}) (name string) {
func NameOf(m any) (name string) {
mt := reflect.TypeOf(m)
mv := reflect.ValueOf(m)
if mv.IsNil() {
Expand Down
4 changes: 2 additions & 2 deletions api/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ func (h SettingHandler) Delete(ctx *gin.Context) {

// Setting REST Resource
type Setting struct {
Key string `json:"key"`
Value interface{} `json:"value"`
Key string `json:"key"`
Value any `json:"value"`
}

func (r *Setting) With(m *model.Setting) {
Expand Down
2 changes: 1 addition & 1 deletion api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/gin-gonic/gin"
qf "github.com/konveyor/tackle2-hub/api/filter"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
"github.com/konveyor/tackle2-hub/model"
"github.com/konveyor/tackle2-hub/tar"
tasking "github.com/konveyor/tackle2-hub/task"
Expand Down
2 changes: 1 addition & 1 deletion api/taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
"github.com/konveyor/tackle2-hub/model"
tasking "github.com/konveyor/tackle2-hub/task"
"gorm.io/gorm/clause"
Expand Down
2 changes: 1 addition & 1 deletion api/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ func (r *Ticket) Model() (m *model.Ticket) {
return
}

type Fields map[string]interface{}
type Fields map[string]any
2 changes: 1 addition & 1 deletion auth/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *Builtin) Authenticate(request *Request) (jwToken *jwt.Token, err error)
}
jwToken, err = jwt.Parse(
token,
func(jwToken *jwt.Token) (secret interface{}, err error) {
func(jwToken *jwt.Token) (secret any, err error) {
_, cast := jwToken.Method.(*jwt.SigningMethodHMAC)
if !cast {
err = liberr.Wrap(&NotAuthenticated{Token: token})
Expand Down
4 changes: 2 additions & 2 deletions binding/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (h *AppFacts) List() (facts api.FactMap, err error) {
}

// Get a fact.
func (h *AppFacts) Get(name string, value interface{}) (err error) {
func (h *AppFacts) Get(name string, value any) (err error) {
key := api.FactKey(name)
key.Qualify(h.source)
path := Path(api.ApplicationFactRoot).Inject(
Expand All @@ -252,7 +252,7 @@ func (h *AppFacts) Get(name string, value interface{}) (err error) {
}

// Set a fact (created as needed).
func (h *AppFacts) Set(name string, value interface{}) (err error) {
func (h *AppFacts) Set(name string, value any) (err error) {
key := api.FactKey(name)
key.Qualify(h.source)
path := Path(api.ApplicationFactRoot).Inject(
Expand Down
Loading
Loading