Browse Source

En cours de développement

master
mls-361 3 months ago
parent
commit
898c3c5035
  1. 3
      Taskfile.yml
  2. 64
      cmd/main.go
  3. 9
      go.mod
  4. 27
      go.sum
  5. 118
      internal/cmdline/cmdline.go

3
Taskfile.yml

@ -12,6 +12,8 @@ vars:
tasks:
update:
cmds:
- go get -u forge.chapril.org/mls-361/application
- go get -u forge.chapril.org/mls-361/crypto
- go mod tidy
lint:
cmds:
@ -27,7 +29,6 @@ tasks:
default:
cmds:
- task: update
- task: lint
- task: test
- task: build

64
cmd/main.go

@ -7,15 +7,10 @@
package main
import (
"time"
"os"
"forge.chapril.org/armen/factory"
"forge.chapril.org/armen/memory"
"forge.chapril.org/armen/model"
"forge.chapril.org/armen/runner"
"forge.chapril.org/armen/workers"
"forge.chapril.org/mls-361/logger"
"forge.chapril.org/mls-361/uuid"
"forge.chapril.org/armen/armen/internal/cmdline"
"forge.chapril.org/mls-361/application"
)
var (
@ -23,51 +18,24 @@ var (
_builtAt string
)
func main() {
logger, _ := logger.New(uuid.New(), "armen", "trace", logger.NewStderrOutput())
logger.Trace("armen", "version", _version, "builtAt", _builtAt)
m, _ := model.New(&model.Config{
Logger: logger,
Storage: memory.New(),
})
f := factory.New(m)
r := runner.New("namespace", m)
_ = r.AddJobHandler("type", runner.JHF(func(job *runner.Job) {
//panic("just a test")
job.Pending().SetDuration(2 * time.Second).SetError("une simple erreur")
}))
pool, err := workers.NewPool(&workers.Config{
Logger: logger,
PoolSize: 3,
Model: m,
})
func appRun() error {
app := application.New("armen", _version, _builtAt)
end, err := cmdline.Parse(app)
if err != nil {
logger.Fatal(err.Error())
return
return app.OnError(err)
}
_ = pool.AddRunner(r)
pool.Start()
time.Sleep(1 * time.Second)
_, _ = f.NewJob("namespace", "type").
SetName("name").
SetOrigin("origin").
SetPriorityLow().
SetRetries(1).
CreateJob()
time.Sleep(5 * time.Second)
if end {
return nil
}
pool.Stop()
return nil
}
time.Sleep(1 * time.Second)
func main() {
if appRun() != nil {
os.Exit(1)
}
}
/*

9
go.mod

@ -3,11 +3,6 @@ module forge.chapril.org/armen/armen
go 1.15
require (
forge.chapril.org/armen/factory v0.0.0-20210412162325-3fbf9dcda286
forge.chapril.org/armen/memory v0.0.0-20210412070352-66ed9edba502
forge.chapril.org/armen/model v0.0.0-20210412154311-d5c295c8948d
forge.chapril.org/armen/runner v0.0.0-20210412162406-3993ae556968
forge.chapril.org/armen/workers v0.0.0-20210412162520-403f2a709cb7
forge.chapril.org/mls-361/logger v0.0.0-20210412060637-c1e01ad8bf2c
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff
forge.chapril.org/mls-361/application v0.0.0-20210412203029-d86c7a878731
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb
)

27
go.sum

@ -1,25 +1,14 @@
forge.chapril.org/armen/factory v0.0.0-20210412162325-3fbf9dcda286 h1:mKMEQ5I0cEQyeXx5rBfvP3yfrzBO9UZ9RsbNAV4u3u8=
forge.chapril.org/armen/factory v0.0.0-20210412162325-3fbf9dcda286/go.mod h1:wW9UZaNl1UzC//HrndVNNy0OUoZq1eSkCU1uVLw5xLM=
forge.chapril.org/armen/jw v0.0.0-20210412070306-7ad253cf9fdc/go.mod h1:i2WfLLkjW4+W+hYB1LpIgZtq6RqSxacnb6Sw63REJHY=
forge.chapril.org/armen/jw v0.0.0-20210412154147-2607fdaab4da h1:C8j0L8C2Q5vcU51kllbEKWljnmWSpt3MnDqVb43jX/U=
forge.chapril.org/armen/jw v0.0.0-20210412154147-2607fdaab4da/go.mod h1:i2WfLLkjW4+W+hYB1LpIgZtq6RqSxacnb6Sw63REJHY=
forge.chapril.org/armen/memory v0.0.0-20210412070352-66ed9edba502 h1:LMZFcv/7WKE58oxf6fLRSBNpbR0jqfsrIYL8pkK9lSw=
forge.chapril.org/armen/memory v0.0.0-20210412070352-66ed9edba502/go.mod h1:/lpnWqjeupmKVbNGA8FpnDLNJuHal9Sdr4JaJEEHxug=
forge.chapril.org/armen/model v0.0.0-20210412154311-d5c295c8948d h1:/p3z9J6LY7bHMcgW+MOX4bMIfEVUZQ2X06YJv2KRNyo=
forge.chapril.org/armen/model v0.0.0-20210412154311-d5c295c8948d/go.mod h1:He+7rIfNjFsY4qzBPbrgmEDzrF5F/eBC7gJO/3NjAG0=
forge.chapril.org/armen/runner v0.0.0-20210412162406-3993ae556968 h1:QKOBxoRn68pVNJGzn8zNIHzuhN/7Vd/yLOihlwyWRt4=
forge.chapril.org/armen/runner v0.0.0-20210412162406-3993ae556968/go.mod h1:tcM/dpUVER2Dhg9MGyHPsnmtmrn0QBqXMripQBpNHVI=
forge.chapril.org/armen/workers v0.0.0-20210412162520-403f2a709cb7 h1:jRr23CCaKd/tPZ+LmObrbNXChj0f8WYc92XEFwoomoY=
forge.chapril.org/armen/workers v0.0.0-20210412162520-403f2a709cb7/go.mod h1:cHBLEwz3r5Q5iIe9zPpYogX9Ln1P2sHuvSE8gj1Urcs=
forge.chapril.org/mls-361/application v0.0.0-20210412203029-d86c7a878731 h1:eIX9CE+2WKXl8tm251W6iXlLkwtGp5SeFFcV+A5rjp0=
forge.chapril.org/mls-361/application v0.0.0-20210412203029-d86c7a878731/go.mod h1:POwqatcN6c54BNVrOlsJDSpRuSwoub8iRIruASBI0jM=
forge.chapril.org/mls-361/buffer v0.0.0-20210410182428-5dc7a7b2ae79 h1:Lh+y98uVFC7btl5FdxKNtokzHD2j14R4ZIgJECao6r4=
forge.chapril.org/mls-361/buffer v0.0.0-20210410182428-5dc7a7b2ae79/go.mod h1:JnOkXF+AEkQ4mv65rzW9eVLsauGzOYIUBQB0zUb5NGE=
forge.chapril.org/mls-361/failure v0.0.0-20210411202803-f4c2b4645ba6 h1:hCjlrpSSzJffmiTlFPWiazeuXz7L9ffqA16MK4YFZyw=
forge.chapril.org/mls-361/failure v0.0.0-20210411202803-f4c2b4645ba6/go.mod h1:DyK2Dj+C/nhpKvGiVsWEzK8mfkk140tJPdgIvUNWv9I=
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb h1:8pRlQkwpWHH/buFMBKBOJsuxXJebh/Gs4VFY641XDJc=
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb/go.mod h1:XwUr6twlpeCblJvXHeMkZxhIbX9ntiZC2KhQtyi79mo=
forge.chapril.org/mls-361/failure v0.0.0-20210412202827-a8d100489f9d h1:WXpstWIuCnizLHM/0XQJfGvElg/swaVgTp1YzPprEf4=
forge.chapril.org/mls-361/failure v0.0.0-20210412202827-a8d100489f9d/go.mod h1:DyK2Dj+C/nhpKvGiVsWEzK8mfkk140tJPdgIvUNWv9I=
forge.chapril.org/mls-361/fqdn v0.0.0-20210412202921-28941d70bb76 h1:P5+SUAuD9pu3+B5BkQkHtUip3VxsEdwfjgc4gzMx5QY=
forge.chapril.org/mls-361/fqdn v0.0.0-20210412202921-28941d70bb76/go.mod h1:Z0AMpAr8UFXBp6Qkl66KKlw/eb2tbliAMAWPRgC/5t4=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210411202715-0e7c3e922d37 h1:6e1Y7hTJ0B8BYStiZSCdW4+v686rOpstQh2B5SWOhZU=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210411202715-0e7c3e922d37/go.mod h1:bv44R0CAd8lQV4ub1hjLE3kWYwpfsW4Ro9zRnD4YOMU=
forge.chapril.org/mls-361/logger v0.0.0-20210412060637-c1e01ad8bf2c h1:HTrZT+qkWlypm8RD55FQd+dOGAQ6R+UIQv3tHAnhYBI=
forge.chapril.org/mls-361/logger v0.0.0-20210412060637-c1e01ad8bf2c/go.mod h1:ev/wJr88q2BWa/UJsWv6jNqybRhO2VAe4R+1m1ylAl0=
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff h1:N7L3nN/9Wlck9qtIxH6gbQ9sbWtsZ048+eDEdpvD09g=
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff/go.mod h1:OAYM+f6ErfC4jbruuG2crA5W7YSpr7+wEs2MrxIzR3Q=
github.com/jinzhu/copier v0.2.8 h1:N8MbL5niMwE3P4dOwurJixz5rMkKfujmMRFmAanSzWE=
github.com/jinzhu/copier v0.2.8/go.mod h1:24xnZezI2Yqac9J61UC6/dG/k76ttpq0DdJI3QmUvro=

118
internal/cmdline/cmdline.go

@ -0,0 +1,118 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### cmdline ####### Copyright (c) 2021 mls-361 ################################################# MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package cmdline
import (
"fmt"
"os"
"forge.chapril.org/mls-361/application"
"forge.chapril.org/mls-361/crypto"
)
func getCrypto(app *application.Application) (*crypto.Crypto, error) {
c := crypto.New()
key, ok := app.LookupEnv("KEY")
if !ok {
return c, nil
}
return c, c.SetKey(key)
}
func decrypt(app *application.Application) error {
if len(os.Args) != 3 {
help(app)
return nil
}
es := os.Args[2]
c, err := getCrypto(app)
if err != nil {
return err
}
ds, err := c.DecryptString(es)
if err != nil {
return err
}
fmt.Println(es, "===>>", ds)
return nil
}
func encrypt(app *application.Application) error {
if len(os.Args) != 3 {
help(app)
return nil
}
ds := os.Args[2]
c, err := getCrypto(app)
if err != nil {
return err
}
es, err := c.EncryptString(ds)
if err != nil {
return err
}
fmt.Println(ds, "===>>", es)
return nil
}
func version(app *application.Application) {
fmt.Println()
fmt.Println("------------------------------------------------")
fmt.Println(" application :", app.Name(), "v"+app.Version())
fmt.Println(" built at :", app.BuiltAt().String())
fmt.Println(" copyright :", "mls-361")
fmt.Println(" license :", "MIT")
fmt.Println("--------------------------------------@(°_°)@---")
fmt.Println()
}
func help(app *application.Application) {
fmt.Println()
fmt.Println("------------------------------------------------")
fmt.Println(" commands:")
fmt.Println(" [-[-]]decrypt|-d|-D <string>")
fmt.Println(" [-[-]]encrypt|-e|-E <string>")
fmt.Println(" [-[-]]version|-v|-V")
fmt.Println("--------------------------------------@(°_°)@---")
fmt.Println()
}
// Parse AFAIRE.
func Parse(app *application.Application) (bool, error) {
if len(os.Args) == 1 {
return false, nil
}
switch os.Args[1] {
case "decrypt", "-decrypt", "--decrypt", "-d", "-D":
return true, decrypt(app)
case "encrypt", "-encrypt", "--encrypt", "-e", "-E":
return true, encrypt(app)
case "version", "-version", "--version", "-v", "-V":
version(app)
default:
help(app)
}
return true, nil
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save