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

Revert "removed logger from the common one" #33

Merged
merged 1 commit into from
Mar 3, 2023
Merged
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
19 changes: 0 additions & 19 deletions commands/execute_response.go

This file was deleted.

46 changes: 14 additions & 32 deletions commands/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"os/exec"
)

func Execute(command string, args ...string) (ExecuteResponse, error) {
result := ExecuteResponse{}
func Execute(command string, args ...string) (string, error) {
cmd := exec.Command(command, args...)
var stdOut, stdIn bytes.Buffer

Expand All @@ -18,66 +17,49 @@ func Execute(command string, args ...string) (ExecuteResponse, error) {
cmd.Stdin = &stdIn

if err := cmd.Run(); err != nil {
result.StdErr = stdOut.String()
result.StdOut = stdOut.String()
result.ErrorCode = err.Error()
return result, err
return stdOut.String(), err
}

result.StdErr = stdOut.String()
result.StdOut = stdOut.String()
return result, nil
return stdOut.String(), nil
}

func ExecuteWithNoOutput(command string, args ...string) (ExecuteResponse, error) {
result := ExecuteResponse{}
func ExecuteWithNoOutput(command string, args ...string) (string, error) {
cmd := exec.Command(command, args...)
var stdOut, stdIn, stdErr bytes.Buffer
var stdOut, stdIn bytes.Buffer

cmd.Stdout = &stdOut
cmd.Stderr = &stdErr
cmd.Stderr = &stdIn
cmd.Stdin = &stdIn

if err := cmd.Run(); err != nil {
result.StdErr = stdErr.String()
result.StdOut = stdOut.String()
return result, err
return stdOut.String(), err
}

result.StdErr = stdErr.String()
result.StdOut = stdOut.String()
return result, nil
return stdOut.String(), nil
}

func ExecuteAndWatch(command string, args ...string) (ExecuteResponse, error) {
result := ExecuteResponse{}
func ExecuteAndWatch(command string, args ...string) (string, error) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()

cmd := exec.CommandContext(ctx, command, args...)
var stdOut, stdErr, stdIn bytes.Buffer
var stdOut, stdIn bytes.Buffer

cmd.Stdout = io.MultiWriter(os.Stdout, &stdOut)
cmd.Stderr = io.MultiWriter(os.Stderr, &stdErr)
cmd.Stderr = io.MultiWriter(os.Stderr, &stdOut)
cmd.Stdin = &stdIn

if err := cmd.Start(); err != nil {
result.StdErr = stdErr.String()
result.StdOut = stdOut.String()
return result, err
return stdOut.String(), err
}

go func() {
<-ctx.Done()
}()

if err := cmd.Wait(); err != nil {
result.StdErr = stdErr.String()
result.StdOut = stdOut.String()
return result, err
return stdOut.String(), err
}

result.StdErr = stdErr.String()
result.StdOut = stdOut.String()
return result, nil
return stdOut.String(), nil
}
34 changes: 25 additions & 9 deletions execution_context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strings"

cryptorand "github.com/cjlapao/common-go-cryptorand"
"github.com/cjlapao/common-go-identity/authorization_context"
"github.com/cjlapao/common-go-identity/interfaces"
"github.com/cjlapao/common-go/cache"
"github.com/cjlapao/common-go/cache/jwt_token_cache"
"github.com/cjlapao/common-go/configuration"
Expand All @@ -17,15 +19,17 @@ var contextService *Context

// Context entity
type Context struct {
Configuration *configuration.ConfigurationService
Services *service_provider.ServiceProvider
Caches *cache.CacheService
TokenCache *jwt_token_cache.JwtTokenCacheProvider
CorrelationId string
Environment string
IsDevelopment bool
Debug bool
Init func() error
Configuration *configuration.ConfigurationService
Services *service_provider.ServiceProvider
Caches *cache.CacheService
TokenCache *jwt_token_cache.JwtTokenCacheProvider
Authorization *authorization_context.AuthorizationContext
UserDatabaseAdapter interfaces.UserContextAdapter
CorrelationId string
Environment string
IsDevelopment bool
Debug bool
Init func() error
}

func New() (*Context, error) {
Expand Down Expand Up @@ -95,6 +99,18 @@ func InitNewContext(init func() error) (*Context, error) {
return contextService, nil
}

func (c *Context) WithDefaultAuthorization() *Context {
// Authorization Context
contextService.Authorization = authorization_context.New()
return c
}

func (c *Context) WithAuthorization(options authorization_context.AuthorizationOptions) *Context {
// Authorization Context
contextService.Authorization = authorization_context.New().WithOptions(options)
return c
}

func (c *Context) Refresh() *Context {
c.CorrelationId = cryptorand.GetRandomString(constants.ID_SIZE)
os.Setenv("CORRELATION_ID", c.CorrelationId)
Expand Down
2 changes: 1 addition & 1 deletion fileproc/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fileproc

import (
log "github.com/cjlapao/common-go-logger"
log "github.com/cjlapao/common-go/log"
)

var logger = log.Get()
Expand Down
12 changes: 8 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ go 1.19

require (
github.com/cjlapao/common-go-cryptorand v0.0.4
github.com/cjlapao/common-go-logger v0.0.2
github.com/fatih/color v1.14.1
github.com/cjlapao/common-go-identity v0.0.3
github.com/fatih/color v1.13.0
github.com/go-redis/redis/v8 v8.11.5
github.com/pascaldekloe/jwt v1.12.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.1
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/sys v0.2.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)
39 changes: 30 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cjlapao/common-go-cryptorand v0.0.4 h1:M4hBZlxXJJ4yY3itQzDCGYJH0rmXYd1nOa8T97EPPpc=
github.com/cjlapao/common-go-cryptorand v0.0.4/go.mod h1:gUG7Bso/ZDD8tOoVmMvaYWMsglfAO9eg+p74OQH7Z2w=
github.com/cjlapao/common-go-logger v0.0.2 h1:6MBpTjxKIiM1SvEIMNgkYczzzjUZK68MVbgReVa6Euc=
github.com/cjlapao/common-go-logger v0.0.2/go.mod h1:bF2s2y2as4Fwz2Ox3QTkWw1Y02a07jX5ey8smY5inrU=
github.com/cjlapao/common-go-identity v0.0.3 h1:0/lZ6Ke9KErhM4ZeJIfmETq+zUdf2jl0CH+Kn6v+HgQ=
github.com/cjlapao/common-go-identity v0.0.3/go.mod h1:xuNepNCHVI/51Q6DQgNPYvx3HS0VaeEhGnp8YcDO/+I=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/pascaldekloe/jwt v1.12.0 h1:imQSkPOtAIBAXoKKjL9ZVJuF/rVqJ+ntiLGpLyeqMUQ=
github.com/pascaldekloe/jwt v1.12.0/go.mod h1:LiIl7EwaglmH1hWThd/AmydNCnHf/mmfluBlNqHbk8U=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -30,12 +44,19 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions helper/linux_service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func Status(svcName string) LinuxServiceState {
return LinuxServiceErrored
}

if strings.Contains(output.GetAllOutputs(), "is not running") {
if strings.Contains(output, "is not running") {
return LinuxServiceStopped
}

if strings.Contains(output.GetAllOutputs(), "is running") {
if strings.Contains(output, "is running") {
return LinuxServiceRunning
}

Expand Down
6 changes: 3 additions & 3 deletions helper/linux_user/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func Get(userName string) (*LinuxUser, error) {
return nil, errors.New("user does not exist")
}

if output.GetAllOutputs() == "" {
if output == "" {
return nil, errors.New("user does not exist")
}

user, err := Marshal(output.GetAllOutputs())
user, err := Marshal(output)

if err != nil {
return nil, err
Expand Down Expand Up @@ -125,7 +125,7 @@ func Create(userName string, userId int, options ...LinuxUserCreateOptions) erro
return fmt.Errorf("there was an error creating user %v with id %v, err %v", userName, userId, err.Error())
}

if strings.ContainsAny(output.GetAllOutputs(), "already exists") {
if strings.ContainsAny(output, "already exists") {
return fmt.Errorf("there was an error creating user %v with id %v, user already exists", userName, userId)
}

Expand Down
6 changes: 3 additions & 3 deletions helper/linux_user_group/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func Get(groupName string) (*LinuxUserGroup, error) {
return nil, errors.New("group does not exists")
}

if output.GetAllOutputs() == "" {
if output == "" {
return nil, errors.New("group does not exists")
}

group, err := Marshal(output.GetAllOutputs())
group, err := Marshal(output)

if err != nil {
return nil, err
Expand Down Expand Up @@ -90,7 +90,7 @@ func Create(groupName string, groupId int) error {
return fmt.Errorf("there was an error creating group %v with id %v, err %v", groupName, groupId, err.Error())
}

if strings.ContainsAny(output.GetAllOutputs(), "already exists") {
if strings.ContainsAny(output, "already exists") {
return fmt.Errorf("there was an error creating group %v with id %v, group already exists", groupName, groupId)
}

Expand Down
Loading