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

Isolate all the Runfunctions to API & Represent output as YAML or JSON or Table #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
455 changes: 455 additions & 0 deletions api/apis.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -14,6 +14,7 @@ require (
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/adrg/xdg v0.4.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-openapi/analysis v0.20.1 // indirect
github.com/go-openapi/errors v0.20.1 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -23,6 +23,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI=
Expand Down
165 changes: 165 additions & 0 deletions internal/pkg/config/resourceStruct.go
@@ -0,0 +1,165 @@
package config

import "github.com/go-openapi/strfmt"

var (
OutputType string
WideOutput bool
)

type ListArtifactOptions struct {
ProjectName string
RepositoryName string
}

type ListArtifactRespTable struct {
Digest string
Tag string
Size string
Type string
PushTime string
ArtifactID string
Details []ListArtifactRespOtype
}

type ListArtifactRespOtype struct {
Labels any
Id int64
PullTime string
RepositoryID int64
ScanOverview any
}

type CreateProjectOptions struct {
ProjectName string
Public bool
RegistryID int64
StorageLimit int64
}

type DeleteProjectOptions struct {
ProjectNameOrID string
}

type ListProjectOptions struct {
Name string
Owner string
Page int64
PageSize int64
Public bool
Q string
Sort string
}

type ListProjectRespTable struct {
ProjectName string
AccessLevel string
Repositories int64
CreationTime strfmt.DateTime
Details []ListProjectRespOtype
}

type ListProjectRespOtype struct {
CVEAllowlist any
ProjectID int32
OwnerName string
Metadata any
}

type GetProjectOptions struct {
ProjectNameOrID string
}


type GetProjectRespTable struct {
ProjectName string
AccessLevel string
Repositories int64
CreationTime strfmt.DateTime
Details []GetProjectRespOtype
}

type GetProjectRespOtype struct {
CVEAllowlist any
ProjectID int32
OwnerName string
Metadata any
}
type CreateRegistrytOptions struct {
Name string
Type string
Url string
Description string
Insecure bool
Credential struct {
AccessKey string
AccessSecret string
Type string
}
}

type DeleteRegistryOptions struct {
Id int64
}

type ListRegistryOptions struct {
Page int64
PageSize int64
Q string
Sort string
}

type ListRegistryRespTable struct {
Name string
Status string
Type string
Url string
CreationTime strfmt.DateTime
}

type UpdateRegistrytOptions struct {
Id int64
Name string
Type string
Url string
Description string
Insecure bool
Credential struct {
AccessKey string
AccessSecret string
Type string
}
}

type GetRegistryOptions struct {
Id int64
}

type GetRegistryRespTable struct {
Name string
Status string
Type string
Url string
CreationTime strfmt.DateTime
}

type UpdateRepositoryOptions struct {
ProjectName string
RepositoryName string
Repository struct {
Id int64
ProjectId int64
Name string
Description string
ArtifactCount int64
PullCount int64

}
}

type LoginOptions struct {
Name string
ServerAddress string
Username string
Password string
}
Expand Up @@ -4,4 +4,4 @@ const (
HarborCredentialName = "HARBORCREDENTIALNAME"
CredentialNameOption = "credential-name"
CredentialNameHelp = "Name of the credential to use for authentication (defaults to the current logged in session)"
)
)
14 changes: 14 additions & 0 deletions internal/pkg/logger/main.go
@@ -0,0 +1,14 @@
package logger

type Logger struct {
Verbose bool
}

type LogFactory interface {
// will accept a string to be highlighted
Info(string, string)
Warn(string)
Print(string)
Err(string)
Normal(string)
}
75 changes: 75 additions & 0 deletions internal/pkg/logger/notemsg.go
@@ -0,0 +1,75 @@
package logger

import (
"fmt"
"log"
)

const (
GREEN = "\033[1;32m"
RED = "\033[1;31m"
YELLOW = "\033[1;33m"
BLUE = "\033[0;34m"
BLUE_BOLD = "\033[1;34m"
WHITE = "\033[0;0m"
WHITE_BOLD = "\033[1;1m"
RESET = "\033[0m"
)

func (logger *Logger) Info(message, resource string) {

if logger.Verbose {
if len(resource) == 0 {
log.Printf("%s[INFO] %s%v%s", GREEN, WHITE_BOLD, message, RESET)
} else {
log.Printf("%s[INFO] %s%v %s%v%s", GREEN, WHITE, message, GREEN, resource, RESET)
}
} else {
if len(resource) == 0 {
fmt.Printf("%s[INFO] %s%v%s\n", GREEN, WHITE_BOLD, message, RESET)
} else {
fmt.Printf("%s[INFO] %s%v %s%v%s\n", GREEN, WHITE, message, GREEN, resource, RESET)
}
}
}

func (logger *Logger) Print(message string) {
if logger.Verbose {
log.Println("[INFO] ", message)
} else {
fmt.Printf("%s%v%s\n", YELLOW, message, RESET)
}
}

func (logger *Logger) Normal(message string) {
if logger.Verbose {
log.Println("[INFO] ", message)
} else {
fmt.Printf("%s%v%s\n", GREEN, message, RESET)
}
}

func (logger *Logger) Message(message string) {

if logger.Verbose {
log.Printf("%s[MESSAGE] %v%s", BLUE_BOLD, message, RESET)
} else {
fmt.Printf("%s[MESSAGE] %v%s\n", BLUE_BOLD, message, RESET)
}
}

func (logger *Logger) Warn(message string) {
if logger.Verbose {
log.Printf("%s[WARN] %v%s", YELLOW, message, RESET)
} else {
fmt.Printf("%s[WARN] %v%s\n", YELLOW, message, RESET)
}
}

func (logger *Logger) Err(message string) {
if logger.Verbose {
log.Printf("%s[ERR] %v%s", RED, message, RESET)
} else {
fmt.Printf("%s[ERR] %v%s\n", RED, message, RESET)
}
}