Browse Source

En cours de développement

master
mls-361 9 months ago
parent
commit
afc0546b4d
  1. 14
      go.mod
  2. 32
      go.sum
  3. 34
      internal/api/api.go
  4. 27
      internal/cli/cli.go
  5. 13
      internal/cli/job.go
  6. 26
      internal/cli/logger.go

14
go.mod

@ -3,17 +3,17 @@ module forge.chapril.org/armen/armen
go 1.16
require (
forge.chapril.org/armen/jw v0.0.0-20210818151220-edd8f137c57a
forge.chapril.org/armen/memory v0.0.0-20210818151319-7833375304b3
forge.chapril.org/armen/model v0.0.0-20210818151340-5240fd23add0
forge.chapril.org/armen/requestor v0.0.0-20210818162048-0aff3c672ef4
forge.chapril.org/armen/runner v0.0.0-20210818151447-f3652512c45d
forge.chapril.org/armen/workers v0.0.0-20210818151509-2e23246740d1
forge.chapril.org/armen/jw v0.0.0-20210818171942-8aa1b1ff4ef1
forge.chapril.org/armen/memory v0.0.0-20210818172030-e30bcad1d6b2
forge.chapril.org/armen/model v0.0.0-20210818172052-84cab7489598
forge.chapril.org/armen/requestor v0.0.0-20210818172815-857179e1f9c3
forge.chapril.org/armen/runner v0.0.0-20210818172841-6f4a75690ae2
forge.chapril.org/armen/workers v0.0.0-20210818172904-86e683e8a122
forge.chapril.org/mls-361/application v0.0.0-20210805205753-c663b93b7e1a
forge.chapril.org/mls-361/crypto v0.0.0-20210507222429-aa9bfa212956
forge.chapril.org/mls-361/errors v0.0.0-20210507222244-6017b9315140
forge.chapril.org/mls-361/jsonapi v0.0.0-20210808150555-87cb5ce9a0f4
forge.chapril.org/mls-361/logger v0.0.0-20210818151108-797b6727b77c
forge.chapril.org/mls-361/logger v0.0.0-20210818171859-19d94ac8deee
forge.chapril.org/mls-361/util v0.0.0-20210814211311-c698de227898
forge.chapril.org/mls-361/uuid v0.1.0
github.com/julienschmidt/httprouter v1.3.0

32
go.sum

@ -1,17 +1,17 @@
forge.chapril.org/armen/factory v0.0.0-20210818151254-4640deaf184d h1:Pzt5Co8BWTDdPmHMlzcRBjOZ2sy33XVNZZo9Xg95cws=
forge.chapril.org/armen/factory v0.0.0-20210818151254-4640deaf184d/go.mod h1:FZLH9x31U+D86Ua392Mes8xobtroiLat7gD0tauWjaU=
forge.chapril.org/armen/jw v0.0.0-20210818151220-edd8f137c57a h1:OCskF/tX2mFEj0HII2OMXRiGSW2OnX6RybfeMepPeo8=
forge.chapril.org/armen/jw v0.0.0-20210818151220-edd8f137c57a/go.mod h1:8r8yiwBtq8w74uQdLW7pxdNH2wut/VwjMDyep86GNTE=
forge.chapril.org/armen/memory v0.0.0-20210818151319-7833375304b3 h1:u48zZxALcdSjlT8j52Ovm+Hb8d+uEiD0PotCAbR0KbQ=
forge.chapril.org/armen/memory v0.0.0-20210818151319-7833375304b3/go.mod h1:xyl3FV9dHJficKKFfN2CUXYs9tCMmaqsYxxQNuBwE9E=
forge.chapril.org/armen/model v0.0.0-20210818151340-5240fd23add0 h1:wVhb7mYJkZrx/Xtk9b9/DWV2fDS45+Yj2JgKHe9j/tQ=
forge.chapril.org/armen/model v0.0.0-20210818151340-5240fd23add0/go.mod h1:vboGfVFhFMfEonHWaOkQqiEGbODOBbNWr0I4Dp3R3O4=
forge.chapril.org/armen/requestor v0.0.0-20210818162048-0aff3c672ef4 h1:nd56YmxR7wbW8ksyoRRe4dCvrw+yVJX062qmkurSHnk=
forge.chapril.org/armen/requestor v0.0.0-20210818162048-0aff3c672ef4/go.mod h1:mzGQhobQAY4mxaULS9gDL04Fi/yIwPijmW3CIopujjw=
forge.chapril.org/armen/runner v0.0.0-20210818151447-f3652512c45d h1:/X+rSbB043fdImXZ4PW4XsjrbmUbxk2lYGcj2ZKd6ec=
forge.chapril.org/armen/runner v0.0.0-20210818151447-f3652512c45d/go.mod h1:UElsW53JSF14TlZWr+Z1WYlRTXf90UNSBCq6WOzE8cE=
forge.chapril.org/armen/workers v0.0.0-20210818151509-2e23246740d1 h1:gpTGo6Abo4BrXFr9BZxHuNyyGMchI33hGvKVeUPbkr8=
forge.chapril.org/armen/workers v0.0.0-20210818151509-2e23246740d1/go.mod h1:WmgbPQtsUvnBmtkWn/aCHy2Mw+QonOXUU3fGwzuVAj4=
forge.chapril.org/armen/factory v0.0.0-20210818172011-f3cfe2263f91 h1:jZvsY6QUQyk2uO7kcsxqwoSUDwGuK3Wt2fpmX5kYpsM=
forge.chapril.org/armen/factory v0.0.0-20210818172011-f3cfe2263f91/go.mod h1:8FsPUUySsGQtQTKkWnKVY3p7mkUwVc/+3C1punnGUP8=
forge.chapril.org/armen/jw v0.0.0-20210818171942-8aa1b1ff4ef1 h1:e0TkafcDPaZRQvRM4cMP2lOUXWzni3z7S6LKQfA9t3E=
forge.chapril.org/armen/jw v0.0.0-20210818171942-8aa1b1ff4ef1/go.mod h1:kLvCjoMCnH7vj9ulAk1gcA0r9CpS9rBeeMq1Nu11emk=
forge.chapril.org/armen/memory v0.0.0-20210818172030-e30bcad1d6b2 h1:92iEK2OQIKrcAwB7mMBLvr5/0oo0RCgQ0YCZiD5wzcE=
forge.chapril.org/armen/memory v0.0.0-20210818172030-e30bcad1d6b2/go.mod h1:h31f46tV9ntcbFr4tqFOrNBLEh6Iqrjh855bmbgor8o=
forge.chapril.org/armen/model v0.0.0-20210818172052-84cab7489598 h1:VkcsXpDjPucYsXNl8og/djulyUIepEJBqg20bWv1YLw=
forge.chapril.org/armen/model v0.0.0-20210818172052-84cab7489598/go.mod h1:rVoJAcySb4Z4hsP3O+s5j9KtAB0TZfp/XuvHqMZR1jQ=
forge.chapril.org/armen/requestor v0.0.0-20210818172815-857179e1f9c3 h1:6FXXe5Ldb54bvV9DBp3yGPsxMY4uRRVLg9it+kUspMY=
forge.chapril.org/armen/requestor v0.0.0-20210818172815-857179e1f9c3/go.mod h1:yVBF/fCGC5WD4WwGjrftP9UlD3jNavXgc3PWMVnpxc8=
forge.chapril.org/armen/runner v0.0.0-20210818172841-6f4a75690ae2 h1:Qk2fN735wHeNeTDaUWTYMkht2hN9kMHskcmTD46cT6I=
forge.chapril.org/armen/runner v0.0.0-20210818172841-6f4a75690ae2/go.mod h1:jEz24GFudi2azgIoV2wzu7zoo4vmfK9MSNQu+BgfK5g=
forge.chapril.org/armen/workers v0.0.0-20210818172904-86e683e8a122 h1:fgmlhnNJhTRM6372QEhplJ9jWuQb7Z279OokcSuHLTI=
forge.chapril.org/armen/workers v0.0.0-20210818172904-86e683e8a122/go.mod h1:A2neAykqs244r9B5vnDIbDz24q8zfOYeNHXSpFt9Si4=
forge.chapril.org/mls-361/application v0.0.0-20210805205753-c663b93b7e1a h1:a/wz9VG0kz3/7irVFefvVpCzsHftOrVibIScG80G8x0=
forge.chapril.org/mls-361/application v0.0.0-20210805205753-c663b93b7e1a/go.mod h1:UO8SSkarQiA194I3h2T1EU0tASvsfemEcVn8RhA5EAE=
forge.chapril.org/mls-361/buffer v0.0.0-20210410182428-5dc7a7b2ae79 h1:Lh+y98uVFC7btl5FdxKNtokzHD2j14R4ZIgJECao6r4=
@ -26,8 +26,8 @@ forge.chapril.org/mls-361/jsonapi v0.0.0-20210808150555-87cb5ce9a0f4 h1:RFievukg
forge.chapril.org/mls-361/jsonapi v0.0.0-20210808150555-87cb5ce9a0f4/go.mod h1:Nc0FLjdJbMKeIJaVHYdTDj1b8GkioxqRfnlLxJBptB4=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210507213839-4f18d8b29e73 h1:OKwxmpmkdhy9SWwZcJrz7Fp57LWpY/PNloHdFiDc4Ek=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210507213839-4f18d8b29e73/go.mod h1:bv44R0CAd8lQV4ub1hjLE3kWYwpfsW4Ro9zRnD4YOMU=
forge.chapril.org/mls-361/logger v0.0.0-20210818151108-797b6727b77c h1:rOyVUAmlYtT6Kr8j1xra1ZSrwAS4kydfJZNDVYkv9CQ=
forge.chapril.org/mls-361/logger v0.0.0-20210818151108-797b6727b77c/go.mod h1:RMaXNoFyzv7q2enufpbRMCs6U6irdSt5S6l0DtaYFPg=
forge.chapril.org/mls-361/logger v0.0.0-20210818171859-19d94ac8deee h1:7ZQ52bgux+6pL2qRhfHU9W1ZRCwETnywd6SHqv0x/OQ=
forge.chapril.org/mls-361/logger v0.0.0-20210818171859-19d94ac8deee/go.mod h1:RMaXNoFyzv7q2enufpbRMCs6U6irdSt5S6l0DtaYFPg=
forge.chapril.org/mls-361/util v0.0.0-20210814211311-c698de227898 h1:JS6i7Nuy/pKyliRF3ZM8EH6WaVbQYNcTwMiUX376c8w=
forge.chapril.org/mls-361/util v0.0.0-20210814211311-c698de227898/go.mod h1:g+yFfYF/opBfo9CG7PKSSq1ih+g0ld+KjLUOujlMktI=
forge.chapril.org/mls-361/uuid v0.1.0 h1:qYPucVw9w8CzSD54bcsO7MSgx4NWIh5fT2YccP3mEb0=

34
internal/api/api.go

@ -50,10 +50,6 @@ func (api *api) trace(hf jsonapi.HandlerFunc) jsonapi.Handler {
)
}
func (api *api) loggers(r *jsonapi.Request) {
r.RenderJSON(http.StatusOK, logger.GetAll(), api.logger)
}
func (api *api) createJob(r *jsonapi.Request) {
job := new(jw.Job)
@ -84,6 +80,7 @@ func (api *api) nextJob(r *jsonapi.Request) {
namespace := r.Param("namespace")
if namespace == "" {
r.BadRequest(errors.New("namespace must not be empty")) ////////////////////////////////////////////////////////
return
}
job, err := api.model.NextJob(namespace)
@ -142,15 +139,42 @@ func (api *api) createWorkflow(r *jsonapi.Request) {
r.RenderJSON(http.StatusCreated, wf, api.logger)
}
func (api *api) adminListLogger(r *jsonapi.Request) {
r.RenderJSON(http.StatusOK, logger.All(), api.logger)
}
func (api *api) adminSetLoggerLevel(r *jsonapi.Request) {
loggerID := r.Param("logger")
if loggerID == "" {
r.BadRequest(errors.New("logger identifier must not be empty")) ////////////////////////////////////////////////
return
}
level := r.Param("level")
if level == "" {
r.BadRequest(errors.New("level must not be empty")) ////////////////////////////////////////////////////////////
return
}
if err := logger.SetLevel(loggerID, level); err != nil {
r.BadRequest(err)
return
}
r.RenderOK()
}
func Build(ccs *components.Components) {
api := newAPI(ccs)
router := ccs.Router
router.GetJSON("/api/loggers", api.debug(api.loggers))
router.PostJSON("/api/job/create", api.debug(api.createJob))
router.GetJSON("/api/job/next/:namespace", api.trace(api.nextJob))
router.PutJSON("/api/job/update", api.debug(api.updateJob))
router.PostJSON("/api/workflow/create", api.debug(api.createWorkflow))
router.GetJSON("/api/admin/logger/list", api.debug(api.adminListLogger))
router.PutJSON("/api/admin/logger/:logger/setlevel/:level", api.debug(api.adminSetLoggerLevel))
}
/*

27
internal/cli/cli.go

@ -91,7 +91,7 @@ The commands are:
decrypt <string>
encrypt <string>
jobs
job
create
-name <string>
-namespace <string> (required)
@ -99,10 +99,14 @@ The commands are:
-origin <string>
-priority <int>
-private <json>
-run_after <datetime> (RFC3339)
-runafter <datetime> (RFC3339)
-retries <int>
-category <string>
loggers
logger
list
setlevel
-id <string> (required)
-level <string> (required)
version
--@(°_°)@-------------------------------
@ -111,15 +115,18 @@ The commands are:
}
func Run(args []string, ccs *components.Components) error {
switch args[0] {
arg := args[0]
args = args[1:]
switch arg {
case "decrypt":
return decrypt(args[1:], ccs)
return decrypt(args, ccs)
case "encrypt":
return encrypt(args[1:], ccs)
case "jobs":
return jobs(args[1:], ccs)
case "loggers":
return loggers(args[1:], ccs)
return encrypt(args, ccs)
case "job":
return job(args, ccs)
case "logger":
return logger(args, ccs)
case "version":
version(ccs)
default:

13
internal/cli/jobs.go → internal/cli/job.go

@ -43,7 +43,7 @@ func setCategory(job *jw.Job, value string) error {
return nil
}
func jobCreate(args []string, ccs *components.Components) error {
func createJob(args []string, ccs *components.Components) error {
if len(args) < 2 {
help()
return _errArgs
@ -58,7 +58,7 @@ func jobCreate(args []string, ccs *components.Components) error {
fs.StringVar(&job.Origin, "origin", "", "")
fs.IntVar((*int)(&job.Priority), "priority", 0, "")
fs.Func("private", "", func(value string) error { return setPrivate(job, value) })
fs.Func("run_after", "", func(value string) error { return setRunAfter(job, value) })
fs.Func("runafter", "", func(value string) error { return setRunAfter(job, value) })
fs.IntVar(&job.Retries, "retries", 0, "")
fs.Func("category", "", func(value string) error { return setCategory(job, value) })
@ -79,15 +79,18 @@ func jobCreate(args []string, ccs *components.Components) error {
return displayResult(job)
}
func jobs(args []string, ccs *components.Components) error {
func job(args []string, ccs *components.Components) error {
if len(args) < 1 {
help()
return _errArgs
}
switch args[0] {
arg := args[0]
args = args[1:]
switch arg {
case "create":
return jobCreate(args[1:], ccs)
return createJob(args, ccs)
default:
help()
}

26
internal/cli/loggers.go → internal/cli/logger.go

@ -10,18 +10,38 @@ import (
"forge.chapril.org/armen/armen/internal/components"
)
func loggers(_ []string, ccs *components.Components) error {
func adminListLogger(ccs *components.Components) error {
requestor, err := newRequestor(ccs)
if err != nil {
return err
}
loggers, err := requestor.Loggers()
all, err := requestor.AdminListLogger()
if err != nil {
return err
}
return displayResult(loggers)
return displayResult(all)
}
func logger(args []string, ccs *components.Components) error {
if len(args) < 1 {
help()
return _errArgs
}
arg := args[0]
//args = args[1:]
switch arg {
case "list":
return adminListLogger(ccs)
case "setlevel":
default:
help()
}
return nil
}
/*
Loading…
Cancel
Save