mirror of
https://github.com/nabbar/golib.git
synced 2025-09-26 20:01:15 +08:00
Rework Error interface
Package Errors: - add function to check & cast error interface into golib Error interface - update CodeError type to simplify management & error creation - add function to simplify call of Error function from a generic error interface - remove some useless function from Error interface All Other Packages: - apply change of package Errors into all other packages
This commit is contained in:
@@ -68,47 +68,47 @@ func ExtractFile(src, dst libfpg.Progress, fileNameContain, fileNameRegex string
|
||||
}()
|
||||
|
||||
if tmp, e = libfpg.Temp(""); e != nil {
|
||||
return ErrorFileOpen.ErrorParent(e)
|
||||
return ErrorFileOpen.Error(e)
|
||||
} else {
|
||||
dst.SetRegisterProgress(tmp)
|
||||
}
|
||||
|
||||
if _, e = src.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
// #nosec
|
||||
}
|
||||
|
||||
if err = libbz2.GetFile(src, tmp); err == nil {
|
||||
//logger.DebugLevel.Log("try another archive...")
|
||||
return ExtractFile(tmp, dst, fileNameContain, fileNameRegex)
|
||||
} else if err.IsCodeError(libbz2.ErrorIOCopy) {
|
||||
} else if err.IsCode(libbz2.ErrorIOCopy) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = libgzp.GetFile(src, tmp); err == nil {
|
||||
//logger.DebugLevel.Log("try another archive...")
|
||||
return ExtractFile(tmp, dst, fileNameContain, fileNameRegex)
|
||||
} else if !err.IsCodeError(libgzp.ErrorGZReader) {
|
||||
} else if !err.IsCode(libgzp.ErrorGZReader) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = libtar.GetFile(src, tmp, fileNameContain, fileNameRegex); err == nil {
|
||||
//logger.DebugLevel.Log("try another archive...")
|
||||
return ExtractFile(tmp, dst, fileNameContain, fileNameRegex)
|
||||
} else if !err.IsCodeError(libtar.ErrorTarNext) {
|
||||
} else if !err.IsCode(libtar.ErrorTarNext) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = libzip.GetFile(src, tmp, fileNameContain, fileNameRegex); err == nil {
|
||||
//logger.DebugLevel.Log("try another archive...")
|
||||
return ExtractFile(tmp, dst, fileNameContain, fileNameRegex)
|
||||
} else if !err.IsCodeError(libzip.ErrorZipOpen) {
|
||||
} else if !err.IsCode(libzip.ErrorZipOpen) {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, e = dst.ReadFrom(src); e != nil {
|
||||
//logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "reopening file", err)
|
||||
return ErrorIOCopy.ErrorParent(e)
|
||||
return ErrorIOCopy.Error(e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -137,20 +137,20 @@ func ExtractAll(src libfpg.Progress, originalName, outputPath string, defaultDir
|
||||
}()
|
||||
|
||||
if tmp, e = libfpg.Temp(""); e != nil {
|
||||
return ErrorFileOpen.ErrorParent(e)
|
||||
return ErrorFileOpen.Error(e)
|
||||
} else {
|
||||
src.SetRegisterProgress(tmp)
|
||||
}
|
||||
|
||||
if err = libbz2.GetFile(src, tmp); err == nil {
|
||||
return ExtractAll(tmp, originalName, outputPath, defaultDirPerm)
|
||||
} else if !err.IsCodeError(libbz2.ErrorIOCopy) {
|
||||
} else if !err.IsCode(libbz2.ErrorIOCopy) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = libgzp.GetFile(src, tmp); err == nil {
|
||||
return ExtractAll(tmp, originalName, outputPath, defaultDirPerm)
|
||||
} else if !err.IsCodeError(libgzp.ErrorGZReader) {
|
||||
} else if !err.IsCode(libgzp.ErrorGZReader) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -162,36 +162,36 @@ func ExtractAll(src libfpg.Progress, originalName, outputPath string, defaultDir
|
||||
//nolint #nosec
|
||||
/* #nosec */
|
||||
if e = os.MkdirAll(outputPath, permDir); e != nil {
|
||||
return ErrorDirCreate.ErrorParent(e)
|
||||
return ErrorDirCreate.Error(e)
|
||||
}
|
||||
} else if e != nil {
|
||||
return ErrorDirStat.ErrorParent(e)
|
||||
return ErrorDirStat.Error(e)
|
||||
} else if !i.IsDir() {
|
||||
return ErrorDirNotDir.Error(nil)
|
||||
}
|
||||
|
||||
if err = libtar.GetAll(src, outputPath, defaultDirPerm); err == nil {
|
||||
return nil
|
||||
} else if !err.IsCodeError(libtar.ErrorTarNext) {
|
||||
} else if !err.IsCode(libtar.ErrorTarNext) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = libzip.GetAll(src, outputPath, defaultDirPerm); err == nil {
|
||||
return nil
|
||||
} else if !err.IsCodeError(libzip.ErrorZipOpen) {
|
||||
} else if !err.IsCode(libzip.ErrorZipOpen) {
|
||||
return err
|
||||
}
|
||||
|
||||
if dst, e = libfpg.New(filepath.Join(outputPath, originalName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, permFile); e != nil {
|
||||
return ErrorFileOpen.ErrorParent(e)
|
||||
return ErrorFileOpen.Error(e)
|
||||
} else {
|
||||
src.SetRegisterProgress(dst)
|
||||
}
|
||||
|
||||
if _, e = src.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
} else if _, e = dst.ReadFrom(src); e != nil {
|
||||
return ErrorIOCopy.ErrorParent(e)
|
||||
return ErrorIOCopy.Error(e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -200,7 +200,7 @@ func ExtractAll(src libfpg.Progress, originalName, outputPath string, defaultDir
|
||||
func CreateArchive(archiveType ArchiveType, archive libfpg.Progress, stripPath string, comment string, pathContent ...string) (created bool, err liberr.Error) {
|
||||
if len(pathContent) < 1 {
|
||||
//nolint #goerr113
|
||||
return false, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathContent is empty"))
|
||||
return false, ErrorParamEmpty.Error(fmt.Errorf("pathContent is empty"))
|
||||
}
|
||||
|
||||
switch archiveType {
|
||||
|
@@ -34,9 +34,9 @@ import (
|
||||
|
||||
func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {
|
||||
if _, e := src.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
} else if _, e = dst.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
}
|
||||
|
||||
r := bzip2.NewReader(src)
|
||||
@@ -44,9 +44,9 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {
|
||||
//nolint #nosec
|
||||
/* #nosec */
|
||||
if _, e := io.Copy(dst, r); e != nil {
|
||||
return ErrorIOCopy.ErrorParent(e)
|
||||
return ErrorIOCopy.Error(e)
|
||||
} else if _, e = dst.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
@@ -34,14 +34,14 @@ import (
|
||||
|
||||
func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {
|
||||
if _, e := src.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
} else if _, e = dst.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
}
|
||||
|
||||
r, e := gz.NewReader(src)
|
||||
if e != nil {
|
||||
return ErrorGZReader.ErrorParent(e)
|
||||
return ErrorGZReader.Error(e)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -51,9 +51,9 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {
|
||||
//nolint #nosec
|
||||
/* #nosec */
|
||||
if _, e = io.Copy(dst, r); e != nil {
|
||||
return ErrorIOCopy.ErrorParent(e)
|
||||
return ErrorIOCopy.Error(e)
|
||||
} else if _, e := dst.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
@@ -46,15 +46,15 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
|
||||
if len(content) != 1 {
|
||||
//nolint #goerr113
|
||||
return false, ErrorParamMismatching.ErrorParent(fmt.Errorf("content path must be limited to strictly one contents"))
|
||||
return false, ErrorParamMismatching.Error(fmt.Errorf("content path must be limited to strictly one contents"))
|
||||
}
|
||||
|
||||
if _, err = archive.Seek(0, io.SeekStart); err != nil {
|
||||
return false, ErrorFileSeek.ErrorParent(err)
|
||||
return false, ErrorFileSeek.Error(err)
|
||||
}
|
||||
|
||||
if _, err = os.Stat(content[0]); err != nil {
|
||||
return false, ErrorParamEmpty.ErrorParent(err)
|
||||
return false, ErrorParamEmpty.Error(err)
|
||||
}
|
||||
|
||||
w = gzip.NewWriter(archive)
|
||||
@@ -66,7 +66,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
}()
|
||||
|
||||
if f, err = os.Open(content[0]); err != nil {
|
||||
return false, ErrorFileOpen.ErrorParent(err)
|
||||
return false, ErrorFileOpen.Error(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -76,15 +76,15 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
}()
|
||||
|
||||
if _, err = io.Copy(w, f); err != nil {
|
||||
return false, ErrorIOCopy.ErrorParent(err)
|
||||
return false, ErrorIOCopy.Error(err)
|
||||
}
|
||||
|
||||
if err = w.Close(); err != nil {
|
||||
return false, ErrorGZCreate.ErrorParent(err)
|
||||
return false, ErrorGZCreate.Error(err)
|
||||
}
|
||||
|
||||
if _, err = archive.Seek(0, io.SeekStart); err != nil {
|
||||
return false, ErrorFileSeek.ErrorParent(err)
|
||||
return false, ErrorFileSeek.Error(err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
@@ -42,9 +42,9 @@ import (
|
||||
func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) liberr.Error {
|
||||
|
||||
if _, e := src.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
} else if _, e = dst.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
}
|
||||
|
||||
r := tar.NewReader(src)
|
||||
@@ -54,7 +54,7 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li
|
||||
if e != nil && e == io.EOF {
|
||||
return nil
|
||||
} else if e != nil {
|
||||
return ErrorTarNext.ErrorParent(e)
|
||||
return ErrorTarNext.Error(e)
|
||||
}
|
||||
|
||||
if h.FileInfo().Mode()&os.ModeType == os.ModeType {
|
||||
@@ -67,9 +67,9 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li
|
||||
/* #nosec */
|
||||
if f.MatchingFullPath(filenameContain) || f.RegexFullPath(filenameRegex) {
|
||||
if _, e = dst.ReadFrom(r); e != nil {
|
||||
return ErrorIOCopy.ErrorParent(e)
|
||||
return ErrorIOCopy.Error(e)
|
||||
} else if _, e = dst.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li
|
||||
func GetAll(src io.ReadSeeker, outputFolder string, defaultDirPerm os.FileMode) liberr.Error {
|
||||
|
||||
if _, e := src.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
}
|
||||
|
||||
r := tar.NewReader(src)
|
||||
@@ -90,7 +90,7 @@ func GetAll(src io.ReadSeeker, outputFolder string, defaultDirPerm os.FileMode)
|
||||
if e != nil && e == io.EOF {
|
||||
return nil
|
||||
} else if e != nil {
|
||||
return ErrorTarNext.ErrorParent(e)
|
||||
return ErrorTarNext.Error(e)
|
||||
}
|
||||
|
||||
//nolint #nosec
|
||||
@@ -116,8 +116,8 @@ func writeContent(r io.Reader, h *tar.Header, out string, defaultDirPerm os.File
|
||||
defer func() {
|
||||
if dst != nil {
|
||||
if e := dst.Close(); e != nil {
|
||||
err = ErrorFileClose.ErrorParent(e)
|
||||
err.AddParentError(err)
|
||||
err = ErrorFileClose.Error(e)
|
||||
err.Add(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -134,11 +134,11 @@ func writeContent(r io.Reader, h *tar.Header, out string, defaultDirPerm os.File
|
||||
}
|
||||
|
||||
if dst, e = libfpg.New(out, os.O_RDWR|os.O_CREATE|os.O_TRUNC, inf.Mode()); e != nil {
|
||||
return ErrorFileOpen.ErrorParent(e)
|
||||
return ErrorFileOpen.Error(e)
|
||||
} else if _, e = io.Copy(dst, r); e != nil {
|
||||
return ErrorIOCopy.ErrorParent(e)
|
||||
return ErrorIOCopy.Error(e)
|
||||
} else if e = dst.Close(); e != nil {
|
||||
return ErrorFileClose.ErrorParent(e)
|
||||
return ErrorFileClose.Error(e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -147,10 +147,10 @@ func writeContent(r io.Reader, h *tar.Header, out string, defaultDirPerm os.File
|
||||
func dirIsExistOrCreate(dirname string, dirPerm os.FileMode) liberr.Error {
|
||||
if i, e := os.Stat(dirname); e != nil && os.IsNotExist(e) {
|
||||
if e = os.MkdirAll(dirname, dirPerm); e != nil {
|
||||
return ErrorDirCreate.ErrorParent(e)
|
||||
return ErrorDirCreate.Error(e)
|
||||
}
|
||||
} else if e != nil {
|
||||
return ErrorDestinationStat.ErrorParent(e)
|
||||
return ErrorDestinationStat.Error(e)
|
||||
} else if !i.IsDir() {
|
||||
return ErrorDestinationIsNotDir.Error(nil)
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func notDirExistCannotClean(filename string, flag byte, targetLink string) liber
|
||||
if _, e := os.Stat(filename); e != nil && os.IsNotExist(e) {
|
||||
return nil
|
||||
} else if e != nil {
|
||||
return ErrorDestinationStat.ErrorParent(e)
|
||||
return ErrorDestinationStat.Error(e)
|
||||
} else if flag&tar.TypeLink == tar.TypeLink || flag&tar.TypeSymlink == tar.TypeSymlink {
|
||||
if hasFSLink(filename) && compareLinkTarget(filename, targetLink) {
|
||||
return nil
|
||||
@@ -178,7 +178,7 @@ func notDirExistCannotClean(filename string, flag byte, targetLink string) liber
|
||||
}
|
||||
|
||||
if e := os.Remove(filename); e != nil {
|
||||
err := ErrorDestinationRemove.ErrorParent(e)
|
||||
err := ErrorDestinationRemove.Error(e)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ func createLink(link, target string, sym bool) liberr.Error {
|
||||
}
|
||||
|
||||
if _, e := os.Stat(link); e != nil && !os.IsNotExist(e) {
|
||||
return ErrorDestinationStat.ErrorParent(e)
|
||||
return ErrorDestinationStat.Error(e)
|
||||
} else if e == nil {
|
||||
return nil
|
||||
} else if compareLinkTarget(link, target) {
|
||||
@@ -211,12 +211,12 @@ func createLink(link, target string, sym bool) liberr.Error {
|
||||
if sym {
|
||||
err := os.Symlink(libarc.CleanPath(target), libarc.CleanPath(link))
|
||||
if err != nil {
|
||||
return ErrorLinkCreate.ErrorParent(err)
|
||||
return ErrorLinkCreate.Error(err)
|
||||
}
|
||||
} else {
|
||||
err := os.Link(libarc.CleanPath(target), libarc.CleanPath(link))
|
||||
if err != nil {
|
||||
return ErrorLinkCreate.ErrorParent(err)
|
||||
return ErrorLinkCreate.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ import (
|
||||
func Create(archive io.WriteSeeker, stripPath string, comment string, content ...string) (bool, liberr.Error) {
|
||||
|
||||
if _, err := archive.Seek(0, io.SeekStart); err != nil {
|
||||
return false, ErrorFileSeek.ErrorParent(err)
|
||||
return false, ErrorFileSeek.Error(err)
|
||||
}
|
||||
|
||||
if ok, err := createTar(archive, stripPath, content...); err != nil || !ok {
|
||||
@@ -50,7 +50,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
}
|
||||
|
||||
if _, err := archive.Seek(0, io.SeekStart); err != nil {
|
||||
return false, ErrorFileSeek.ErrorParent(err)
|
||||
return false, ErrorFileSeek.Error(err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -59,7 +59,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
func CreateGzip(archive io.WriteSeeker, stripPath string, comment string, content ...string) (bool, liberr.Error) {
|
||||
|
||||
if _, err := archive.Seek(0, io.SeekStart); err != nil {
|
||||
return false, ErrorFileSeek.ErrorParent(err)
|
||||
return false, ErrorFileSeek.Error(err)
|
||||
}
|
||||
|
||||
z := gzip.NewWriter(archive)
|
||||
@@ -69,11 +69,11 @@ func CreateGzip(archive io.WriteSeeker, stripPath string, comment string, conten
|
||||
}
|
||||
|
||||
if err := z.Close(); err != nil {
|
||||
return false, ErrorGzipCreate.ErrorParent(err)
|
||||
return false, ErrorGzipCreate.Error(err)
|
||||
}
|
||||
|
||||
if _, err := archive.Seek(0, io.SeekStart); err != nil {
|
||||
return false, ErrorFileSeek.ErrorParent(err)
|
||||
return false, ErrorFileSeek.Error(err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -147,7 +147,7 @@ func createTar(w io.Writer, stripPath string, content ...string) (bool, liberr.E
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
lEr.AddParent(err)
|
||||
lEr.Add(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -158,13 +158,13 @@ func createTar(w io.Writer, stripPath string, content ...string) (bool, liberr.E
|
||||
}
|
||||
|
||||
//nolint #goerr113
|
||||
return false, ErrorTarCreate.ErrorParent(fmt.Errorf("no file to add in archive"))
|
||||
return false, ErrorTarCreate.Error(fmt.Errorf("no file to add in archive"))
|
||||
} else if !lEr.HasParent() {
|
||||
lEr = nil
|
||||
}
|
||||
|
||||
if err = t.Close(); err != nil {
|
||||
return false, ErrorTarCreate.ErrorParent(err)
|
||||
return false, ErrorTarCreate.Error(err)
|
||||
}
|
||||
|
||||
return true, lEr
|
||||
|
@@ -45,13 +45,13 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li
|
||||
)
|
||||
|
||||
if _, err = src.Seek(0, io.SeekStart); err != nil {
|
||||
return ErrorFileSeek.ErrorParent(err)
|
||||
return ErrorFileSeek.Error(err)
|
||||
} else if _, err = dst.Seek(0, io.SeekStart); err != nil {
|
||||
return ErrorFileSeek.ErrorParent(err)
|
||||
return ErrorFileSeek.Error(err)
|
||||
} else if inf, err = src.Stat(); err != nil {
|
||||
return ErrorFileStat.ErrorParent(err)
|
||||
return ErrorFileStat.Error(err)
|
||||
} else if arc, err = zip.NewReader(src, inf.Size()); err != nil {
|
||||
return ErrorZipOpen.ErrorParent(err)
|
||||
return ErrorZipOpen.Error(err)
|
||||
}
|
||||
|
||||
for _, f := range arc.File {
|
||||
@@ -73,7 +73,7 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li
|
||||
|
||||
if r, e = f.Open(); e != nil {
|
||||
//logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "open zipped file reader", err)
|
||||
return ErrorZipFileOpen.ErrorParent(e)
|
||||
return ErrorZipFileOpen.Error(e)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -84,12 +84,12 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li
|
||||
/* #nosec */
|
||||
if _, e = dst.ReadFrom(r); e != nil {
|
||||
//logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "copy buffer from archive reader", err)
|
||||
return ErrorIOCopy.ErrorParent(e)
|
||||
return ErrorIOCopy.Error(e)
|
||||
}
|
||||
|
||||
if _, e = dst.Seek(0, io.SeekStart); e != nil {
|
||||
//logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "seeking temp file", err)
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -107,11 +107,11 @@ func GetAll(src libfpg.Progress, outputFolder string, defaultDirPerm os.FileMode
|
||||
)
|
||||
|
||||
if _, e = src.Seek(0, io.SeekStart); e != nil {
|
||||
return ErrorFileSeek.ErrorParent(e)
|
||||
return ErrorFileSeek.Error(e)
|
||||
} else if i, e = src.Stat(); e != nil {
|
||||
return ErrorFileStat.ErrorParent(e)
|
||||
return ErrorFileStat.Error(e)
|
||||
} else if r, e = zip.NewReader(src, i.Size()); e != nil {
|
||||
return ErrorZipOpen.ErrorParent(e)
|
||||
return ErrorZipOpen.Error(e)
|
||||
}
|
||||
|
||||
for _, f := range r.File {
|
||||
@@ -145,8 +145,8 @@ func writeContent(f *zip.File, out string, defaultDirPerm os.FileMode) (err libe
|
||||
defer func() {
|
||||
if dst != nil {
|
||||
if e = dst.Close(); e != nil {
|
||||
err = ErrorFileClose.ErrorParent(e)
|
||||
err.AddParentError(err)
|
||||
err = ErrorFileClose.Error(e)
|
||||
err.Add(err)
|
||||
}
|
||||
}
|
||||
if r != nil {
|
||||
@@ -166,21 +166,21 @@ func writeContent(f *zip.File, out string, defaultDirPerm os.FileMode) (err libe
|
||||
}
|
||||
|
||||
if dst, e = libfpg.New(out, os.O_RDWR|os.O_CREATE|os.O_TRUNC, inf.Mode()); e != nil {
|
||||
return ErrorFileOpen.ErrorParent(e)
|
||||
return ErrorFileOpen.Error(e)
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
if r, e = f.Open(); e != nil {
|
||||
return ErrorZipFileOpen.ErrorParent(e)
|
||||
return ErrorZipFileOpen.Error(e)
|
||||
}
|
||||
|
||||
//nolint #nosec
|
||||
/* #nosec */
|
||||
if _, e = io.Copy(dst, r); e != nil {
|
||||
return ErrorIOCopy.ErrorParent(e)
|
||||
return ErrorIOCopy.Error(e)
|
||||
} else if e = dst.Close(); e != nil {
|
||||
return ErrorFileClose.ErrorParent(e)
|
||||
return ErrorFileClose.Error(e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -189,10 +189,10 @@ func writeContent(f *zip.File, out string, defaultDirPerm os.FileMode) (err libe
|
||||
func dirIsExistOrCreate(dirname string, dirPerm os.FileMode) liberr.Error {
|
||||
if i, e := os.Stat(filepath.Dir(dirname)); e != nil && os.IsNotExist(e) {
|
||||
if e = os.MkdirAll(filepath.Dir(dirname), dirPerm); e != nil {
|
||||
return ErrorDirCreate.ErrorParent(e)
|
||||
return ErrorDirCreate.Error(e)
|
||||
}
|
||||
} else if e != nil {
|
||||
return ErrorDestinationStat.ErrorParent(e)
|
||||
return ErrorDestinationStat.Error(e)
|
||||
} else if !i.IsDir() {
|
||||
return ErrorDestinationIsNotDir.Error(nil)
|
||||
}
|
||||
@@ -202,12 +202,12 @@ func dirIsExistOrCreate(dirname string, dirPerm os.FileMode) liberr.Error {
|
||||
|
||||
func notDirExistCannotClean(filename string) liberr.Error {
|
||||
if i, e := os.Stat(filename); e != nil && !os.IsNotExist(e) {
|
||||
return ErrorDestinationStat.ErrorParent(e)
|
||||
return ErrorDestinationStat.Error(e)
|
||||
} else if e == nil && i.IsDir() {
|
||||
return ErrorDestinationIsDir.Error(nil)
|
||||
} else if e == nil {
|
||||
if e = os.Remove(filename); e != nil {
|
||||
return ErrorDestinationRemove.ErrorParent(e)
|
||||
return ErrorDestinationRemove.Error(e)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@@ -40,7 +40,7 @@ import (
|
||||
func Create(archive io.WriteSeeker, stripPath string, comment string, content ...string) (bool, liberr.Error) {
|
||||
|
||||
if _, err := archive.Seek(0, io.SeekStart); err != nil {
|
||||
return false, ErrorFileSeek.ErrorParent(err)
|
||||
return false, ErrorFileSeek.Error(err)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -57,7 +57,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
|
||||
if comment != "" {
|
||||
if e := z.SetComment(comment); e != nil {
|
||||
return false, ErrorZipComment.ErrorParent(e)
|
||||
return false, ErrorZipComment.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
}
|
||||
|
||||
if _, err := archive.Seek(0, io.SeekStart); err != nil {
|
||||
return false, ErrorFileSeek.ErrorParent(err)
|
||||
return false, ErrorFileSeek.Error(err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -138,7 +138,7 @@ func addFileToZip(z *zip.Writer, stripPath string, content ...string) (bool, lib
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
lEr.AddParent(err)
|
||||
lEr.Add(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -148,13 +148,13 @@ func addFileToZip(z *zip.Writer, stripPath string, content ...string) (bool, lib
|
||||
return false, lEr
|
||||
}
|
||||
|
||||
return false, ErrorZipCreate.ErrorParent(fmt.Errorf("no file to add in archive"))
|
||||
return false, ErrorZipCreate.Error(fmt.Errorf("no file to add in archive"))
|
||||
} else if !lEr.HasParent() {
|
||||
lEr = nil
|
||||
}
|
||||
|
||||
if err = z.Close(); err != nil {
|
||||
return false, ErrorZipCreate.ErrorParent(err)
|
||||
return false, ErrorZipCreate.Error(err)
|
||||
}
|
||||
|
||||
return true, lEr
|
||||
|
@@ -48,9 +48,9 @@ const (
|
||||
type Client interface {
|
||||
artcli.ArtifactManagement
|
||||
|
||||
ListReleases() (releases hscvrs.Collection, err liberr.Error)
|
||||
GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error)
|
||||
Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error
|
||||
ListReleases() (releases hscvrs.Collection, err error)
|
||||
GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error)
|
||||
Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error
|
||||
}
|
||||
|
||||
func CheckRegex(name, regex string) bool {
|
||||
@@ -61,7 +61,7 @@ func CheckRegex(name, regex string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func DownloadRelease(link string) (file os.File, err liberr.Error) {
|
||||
func DownloadRelease(link string) (file os.File, err error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
|
@@ -27,15 +27,14 @@ package client
|
||||
|
||||
import (
|
||||
hscvrs "github.com/hashicorp/go-version"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type ArtifactManagement interface {
|
||||
ListReleasesOrder() (releases map[int]map[int]hscvrs.Collection, err liberr.Error)
|
||||
ListReleasesMajor(major int) (releases hscvrs.Collection, err liberr.Error)
|
||||
ListReleasesMinor(major, minor int) (releases hscvrs.Collection, err liberr.Error)
|
||||
ListReleasesOrder() (releases map[int]map[int]hscvrs.Collection, err error)
|
||||
ListReleasesMajor(major int) (releases hscvrs.Collection, err error)
|
||||
ListReleasesMinor(major, minor int) (releases hscvrs.Collection, err error)
|
||||
|
||||
GetLatest() (release *hscvrs.Version, err liberr.Error)
|
||||
GetLatestMajor(major int) (release *hscvrs.Version, err liberr.Error)
|
||||
GetLatestMinor(major, minor int) (release *hscvrs.Version, err liberr.Error)
|
||||
GetLatest() (release *hscvrs.Version, err error)
|
||||
GetLatestMajor(major int) (release *hscvrs.Version, err error)
|
||||
GetLatestMinor(major, minor int) (release *hscvrs.Version, err error)
|
||||
}
|
||||
|
@@ -29,14 +29,13 @@ import (
|
||||
"sort"
|
||||
|
||||
hscvrs "github.com/hashicorp/go-version"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type ClientHelper struct {
|
||||
F func() (releases hscvrs.Collection, err liberr.Error)
|
||||
F func() (releases hscvrs.Collection, err error)
|
||||
}
|
||||
|
||||
func (g *ClientHelper) listReleasesOrderMajor() (releases map[int]hscvrs.Collection, err liberr.Error) {
|
||||
func (g *ClientHelper) listReleasesOrderMajor() (releases map[int]hscvrs.Collection, err error) {
|
||||
var (
|
||||
vers hscvrs.Collection
|
||||
)
|
||||
@@ -58,7 +57,7 @@ func (g *ClientHelper) listReleasesOrderMajor() (releases map[int]hscvrs.Collect
|
||||
return
|
||||
}
|
||||
|
||||
func (g *ClientHelper) ListReleasesOrder() (releases map[int]map[int]hscvrs.Collection, err liberr.Error) {
|
||||
func (g *ClientHelper) ListReleasesOrder() (releases map[int]map[int]hscvrs.Collection, err error) {
|
||||
var (
|
||||
vers map[int]hscvrs.Collection
|
||||
)
|
||||
@@ -86,7 +85,7 @@ func (g *ClientHelper) ListReleasesOrder() (releases map[int]map[int]hscvrs.Coll
|
||||
return
|
||||
}
|
||||
|
||||
func (g *ClientHelper) ListReleasesMajor(major int) (releases hscvrs.Collection, err liberr.Error) {
|
||||
func (g *ClientHelper) ListReleasesMajor(major int) (releases hscvrs.Collection, err error) {
|
||||
var (
|
||||
vers map[int]hscvrs.Collection
|
||||
)
|
||||
@@ -106,7 +105,7 @@ func (g *ClientHelper) ListReleasesMajor(major int) (releases hscvrs.Collection,
|
||||
return
|
||||
}
|
||||
|
||||
func (g *ClientHelper) ListReleasesMinor(major, minor int) (releases hscvrs.Collection, err liberr.Error) {
|
||||
func (g *ClientHelper) ListReleasesMinor(major, minor int) (releases hscvrs.Collection, err error) {
|
||||
var (
|
||||
vers map[int]map[int]hscvrs.Collection
|
||||
)
|
||||
@@ -130,7 +129,7 @@ func (g *ClientHelper) ListReleasesMinor(major, minor int) (releases hscvrs.Coll
|
||||
return
|
||||
}
|
||||
|
||||
func (g *ClientHelper) GetLatest() (release *hscvrs.Version, err liberr.Error) {
|
||||
func (g *ClientHelper) GetLatest() (release *hscvrs.Version, err error) {
|
||||
var (
|
||||
vers map[int]map[int]hscvrs.Collection
|
||||
major int
|
||||
@@ -156,7 +155,7 @@ func (g *ClientHelper) GetLatest() (release *hscvrs.Version, err liberr.Error) {
|
||||
return g.GetLatestMinor(major, minor)
|
||||
}
|
||||
|
||||
func (g *ClientHelper) GetLatestMajor(major int) (release *hscvrs.Version, err liberr.Error) {
|
||||
func (g *ClientHelper) GetLatestMajor(major int) (release *hscvrs.Version, err error) {
|
||||
var (
|
||||
vers map[int]map[int]hscvrs.Collection
|
||||
minor int
|
||||
@@ -179,7 +178,7 @@ func (g *ClientHelper) GetLatestMajor(major int) (release *hscvrs.Version, err l
|
||||
return g.GetLatestMinor(major, minor)
|
||||
}
|
||||
|
||||
func (g *ClientHelper) GetLatestMinor(major, minor int) (release *hscvrs.Version, err liberr.Error) {
|
||||
func (g *ClientHelper) GetLatestMinor(major, minor int) (release *hscvrs.Version, err error) {
|
||||
var (
|
||||
vers hscvrs.Collection
|
||||
)
|
||||
|
@@ -33,7 +33,6 @@ import (
|
||||
github "github.com/google/go-github/v33/github"
|
||||
libart "github.com/nabbar/golib/artifact"
|
||||
artcli "github.com/nabbar/golib/artifact/client"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func getOrgProjectFromRepos(repos string) (owner string, project string) {
|
||||
@@ -45,7 +44,7 @@ func getOrgProjectFromRepos(repos string) (owner string, project string) {
|
||||
return lst[0], lst[1]
|
||||
}
|
||||
|
||||
func NewGithub(ctx context.Context, httpcli *http.Client, repos string) (cli libart.Client, err liberr.Error) {
|
||||
func NewGithub(ctx context.Context, httpcli *http.Client, repos string) (cli libart.Client, err error) {
|
||||
o, p := getOrgProjectFromRepos(repos)
|
||||
|
||||
a := &githubModel{
|
||||
@@ -61,7 +60,7 @@ func NewGithub(ctx context.Context, httpcli *http.Client, repos string) (cli lib
|
||||
return a, err
|
||||
}
|
||||
|
||||
func NewGithubWithTokenOAuth(ctx context.Context, repos string, oauth2client *http.Client) (cli libart.Client, err liberr.Error) {
|
||||
func NewGithubWithTokenOAuth(ctx context.Context, repos string, oauth2client *http.Client) (cli libart.Client, err error) {
|
||||
o, p := getOrgProjectFromRepos(repos)
|
||||
|
||||
a := &githubModel{
|
||||
|
@@ -36,7 +36,6 @@ import (
|
||||
hscvrs "github.com/hashicorp/go-version"
|
||||
libart "github.com/nabbar/golib/artifact"
|
||||
artcli "github.com/nabbar/golib/artifact/client"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libfpg "github.com/nabbar/golib/file/progress"
|
||||
)
|
||||
|
||||
@@ -53,7 +52,7 @@ type githubModel struct {
|
||||
p string
|
||||
}
|
||||
|
||||
func (g *githubModel) ListReleases() (releases hscvrs.Collection, err liberr.Error) {
|
||||
func (g *githubModel) ListReleases() (releases hscvrs.Collection, err error) {
|
||||
var (
|
||||
e error
|
||||
lopt = &github.ListOptions{
|
||||
@@ -70,7 +69,7 @@ func (g *githubModel) ListReleases() (releases hscvrs.Collection, err liberr.Err
|
||||
)
|
||||
|
||||
if rels, resp, e = g.c.Repositories.ListReleases(g.x, g.o, g.p, lopt); e != nil {
|
||||
return nil, ErrorGithubList.ErrorParent(e)
|
||||
return nil, ErrorGithubList.Error(e)
|
||||
} else {
|
||||
curr++
|
||||
}
|
||||
@@ -92,14 +91,14 @@ func (g *githubModel) ListReleases() (releases hscvrs.Collection, err liberr.Err
|
||||
}
|
||||
}
|
||||
|
||||
func (g *githubModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) {
|
||||
func (g *githubModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) {
|
||||
var (
|
||||
rels *github.RepositoryRelease
|
||||
e error
|
||||
)
|
||||
|
||||
if rels, _, e = g.c.Repositories.GetReleaseByTag(g.x, g.o, g.p, release.Original()); e != nil {
|
||||
return "", ErrorGithubGetRelease.ErrorParent(e)
|
||||
return "", ErrorGithubGetRelease.Error(e)
|
||||
}
|
||||
|
||||
for _, a := range rels.Assets {
|
||||
@@ -113,13 +112,13 @@ func (g *githubModel) GetArtifact(containName string, regexName string, release
|
||||
return "", ErrorGithubNotFound.Error(nil)
|
||||
}
|
||||
|
||||
func (g *githubModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error {
|
||||
func (g *githubModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error {
|
||||
var (
|
||||
uri string
|
||||
rsp *github.Response
|
||||
req *http.Request
|
||||
err error
|
||||
e liberr.Error
|
||||
e error
|
||||
n int64
|
||||
)
|
||||
|
||||
@@ -135,23 +134,23 @@ func (g *githubModel) Download(dst libfpg.Progress, containName string, regexNam
|
||||
if uri, e = g.GetArtifact(containName, regexName, release); e != nil {
|
||||
return e
|
||||
} else if req, err = g.c.NewRequest(http.MethodGet, uri, nil); err != nil {
|
||||
return ErrorGithubRequestNew.ErrorParent(err)
|
||||
return ErrorGithubRequestNew.Error(err)
|
||||
} else if rsp, err = g.c.Do(g.x, req, nil); err != nil {
|
||||
return ErrorGithubRequestRun.ErrorParent(err)
|
||||
return ErrorGithubRequestRun.Error(err)
|
||||
} else if rsp.StatusCode < 200 || rsp.StatusCode > 299 {
|
||||
return ErrorGithubResponse.ErrorParent(errResponseCode)
|
||||
return ErrorGithubResponse.Error(errResponseCode)
|
||||
} else if rsp.ContentLength < 1 {
|
||||
return ErrorGithubResponse.ErrorParent(errResponseContents)
|
||||
return ErrorGithubResponse.Error(errResponseContents)
|
||||
} else if rsp.Body == nil {
|
||||
return ErrorGithubResponse.ErrorParent(errResponseBodyEmpty)
|
||||
return ErrorGithubResponse.Error(errResponseBodyEmpty)
|
||||
} else {
|
||||
dst.Reset(rsp.ContentLength)
|
||||
}
|
||||
|
||||
if n, err = io.Copy(dst, rsp.Body); err != nil {
|
||||
return ErrorGithubIOCopy.ErrorParent(err)
|
||||
return ErrorGithubIOCopy.Error(err)
|
||||
} else if n != rsp.ContentLength {
|
||||
return ErrorDestinationSize.ErrorParent(errMisMatchingSize)
|
||||
return ErrorDestinationSize.Error(errMisMatchingSize)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -33,7 +33,6 @@ import (
|
||||
|
||||
libart "github.com/nabbar/golib/artifact"
|
||||
artcli "github.com/nabbar/golib/artifact/client"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
gitlab "github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
@@ -42,7 +41,7 @@ const (
|
||||
GitlabAPIVersion = "/v4"
|
||||
)
|
||||
|
||||
func getGitlbaOptions(baseUrl string, httpcli *http.Client) (opt []gitlab.ClientOptionFunc, err liberr.Error) {
|
||||
func getGitlbaOptions(baseUrl string, httpcli *http.Client) (opt []gitlab.ClientOptionFunc, err error) {
|
||||
var (
|
||||
u *url.URL
|
||||
e error
|
||||
@@ -51,7 +50,7 @@ func getGitlbaOptions(baseUrl string, httpcli *http.Client) (opt []gitlab.Client
|
||||
opt = make([]gitlab.ClientOptionFunc, 0)
|
||||
|
||||
if u, e = url.Parse(baseUrl); e != nil {
|
||||
return opt, ErrorURLParse.ErrorParent(e)
|
||||
return opt, ErrorURLParse.Error(e)
|
||||
}
|
||||
|
||||
if !strings.Contains(u.Path, GitlabAPIBase) {
|
||||
@@ -84,7 +83,7 @@ func newGitlab(ctx context.Context, c *gitlab.Client, projectId int) libart.Clie
|
||||
return a
|
||||
}
|
||||
|
||||
func NewGitlabAuthUser(ctx context.Context, httpcli *http.Client, user, pass, baseUrl string, projectId int) (cli libart.Client, err liberr.Error) {
|
||||
func NewGitlabAuthUser(ctx context.Context, httpcli *http.Client, user, pass, baseUrl string, projectId int) (cli libart.Client, err error) {
|
||||
var (
|
||||
o []gitlab.ClientOptionFunc
|
||||
c *gitlab.Client
|
||||
@@ -96,13 +95,13 @@ func NewGitlabAuthUser(ctx context.Context, httpcli *http.Client, user, pass, ba
|
||||
}
|
||||
|
||||
if c, e = gitlab.NewBasicAuthClient(user, pass, o...); e != nil {
|
||||
return nil, ErrorClientInit.ErrorParent(e)
|
||||
return nil, ErrorClientInit.Error(e)
|
||||
}
|
||||
|
||||
return newGitlab(ctx, c, projectId), err
|
||||
}
|
||||
|
||||
func NewGitlabOAuth(ctx context.Context, httpcli *http.Client, oAuthToken, baseUrl string, projectId int) (cli libart.Client, err liberr.Error) {
|
||||
func NewGitlabOAuth(ctx context.Context, httpcli *http.Client, oAuthToken, baseUrl string, projectId int) (cli libart.Client, err error) {
|
||||
var (
|
||||
o []gitlab.ClientOptionFunc
|
||||
c *gitlab.Client
|
||||
@@ -114,13 +113,13 @@ func NewGitlabOAuth(ctx context.Context, httpcli *http.Client, oAuthToken, baseU
|
||||
}
|
||||
|
||||
if c, e = gitlab.NewOAuthClient(oAuthToken, o...); e != nil {
|
||||
return nil, ErrorClientInit.ErrorParent(e)
|
||||
return nil, ErrorClientInit.Error(e)
|
||||
}
|
||||
|
||||
return newGitlab(ctx, c, projectId), err
|
||||
}
|
||||
|
||||
func NewGitlabPrivateToken(ctx context.Context, httpcli *http.Client, token, baseUrl string, projectId int) (cli libart.Client, err liberr.Error) {
|
||||
func NewGitlabPrivateToken(ctx context.Context, httpcli *http.Client, token, baseUrl string, projectId int) (cli libart.Client, err error) {
|
||||
var (
|
||||
o []gitlab.ClientOptionFunc
|
||||
c *gitlab.Client
|
||||
@@ -132,7 +131,7 @@ func NewGitlabPrivateToken(ctx context.Context, httpcli *http.Client, token, bas
|
||||
}
|
||||
|
||||
if c, e = gitlab.NewClient(token, o...); e != nil {
|
||||
return nil, ErrorClientInit.ErrorParent(e)
|
||||
return nil, ErrorClientInit.Error(e)
|
||||
}
|
||||
|
||||
return newGitlab(ctx, c, projectId), err
|
||||
|
@@ -36,7 +36,6 @@ import (
|
||||
hscvrs "github.com/hashicorp/go-version"
|
||||
libart "github.com/nabbar/golib/artifact"
|
||||
artcli "github.com/nabbar/golib/artifact/client"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libfpg "github.com/nabbar/golib/file/progress"
|
||||
gitlab "github.com/xanzy/go-gitlab"
|
||||
)
|
||||
@@ -53,7 +52,7 @@ type gitlabModel struct {
|
||||
p int
|
||||
}
|
||||
|
||||
func (g *gitlabModel) ListReleases() (releases hscvrs.Collection, err liberr.Error) {
|
||||
func (g *gitlabModel) ListReleases() (releases hscvrs.Collection, err error) {
|
||||
var (
|
||||
e error
|
||||
lopt = &gitlab.ListReleasesOptions{
|
||||
@@ -71,7 +70,7 @@ func (g *gitlabModel) ListReleases() (releases hscvrs.Collection, err liberr.Err
|
||||
)
|
||||
|
||||
if rels, resp, e = g.c.Releases.ListReleases(g.p, lopt, gitlab.WithContext(g.x)); e != nil {
|
||||
return nil, ErrorGitlabList.ErrorParent(e)
|
||||
return nil, ErrorGitlabList.Error(e)
|
||||
}
|
||||
|
||||
for _, r := range rels {
|
||||
@@ -91,14 +90,14 @@ func (g *gitlabModel) ListReleases() (releases hscvrs.Collection, err liberr.Err
|
||||
}
|
||||
}
|
||||
|
||||
func (g *gitlabModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) {
|
||||
func (g *gitlabModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) {
|
||||
var (
|
||||
vers *gitlab.Release
|
||||
e error
|
||||
)
|
||||
|
||||
if vers, _, e = g.c.Releases.GetRelease(g.p, release.Original(), gitlab.WithContext(g.x)); e != nil {
|
||||
return "", ErrorGitlabGetRelease.ErrorParent(e)
|
||||
return "", ErrorGitlabGetRelease.Error(e)
|
||||
}
|
||||
|
||||
for _, l := range vers.Assets.Links {
|
||||
@@ -112,13 +111,13 @@ func (g *gitlabModel) GetArtifact(containName string, regexName string, release
|
||||
return "", ErrorGitlabNotFound.Error(nil)
|
||||
}
|
||||
|
||||
func (g *gitlabModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error {
|
||||
func (g *gitlabModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error {
|
||||
var (
|
||||
uri string
|
||||
rsp *gitlab.Response
|
||||
req *hschtc.Request
|
||||
err error
|
||||
e liberr.Error
|
||||
e error
|
||||
n int64
|
||||
)
|
||||
|
||||
@@ -134,23 +133,23 @@ func (g *gitlabModel) Download(dst libfpg.Progress, containName string, regexNam
|
||||
if uri, e = g.GetArtifact(containName, regexName, release); e != nil {
|
||||
return e
|
||||
} else if req, err = g.c.NewRequest(http.MethodGet, uri, nil, nil); err != nil {
|
||||
return ErrorGitlabRequestNew.ErrorParent(err)
|
||||
return ErrorGitlabRequestNew.Error(err)
|
||||
} else if rsp, err = g.c.Do(req, nil); err != nil {
|
||||
return ErrorGitlabRequestRun.ErrorParent(err)
|
||||
return ErrorGitlabRequestRun.Error(err)
|
||||
} else if rsp.StatusCode < 200 || rsp.StatusCode > 299 {
|
||||
return ErrorGitlabResponse.ErrorParent(errResponseCode)
|
||||
return ErrorGitlabResponse.Error(errResponseCode)
|
||||
} else if rsp.ContentLength < 1 {
|
||||
return ErrorGitlabResponse.ErrorParent(errResponseContents)
|
||||
return ErrorGitlabResponse.Error(errResponseContents)
|
||||
} else if rsp.Body == nil {
|
||||
return ErrorGitlabResponse.ErrorParent(errResponseBodyEmpty)
|
||||
return ErrorGitlabResponse.Error(errResponseBodyEmpty)
|
||||
} else {
|
||||
dst.Reset(rsp.ContentLength)
|
||||
}
|
||||
|
||||
if n, err = io.Copy(dst, rsp.Body); err != nil {
|
||||
return ErrorGitlabIOCopy.ErrorParent(err)
|
||||
return ErrorGitlabIOCopy.Error(err)
|
||||
} else if n != rsp.ContentLength {
|
||||
return ErrorDestinationSize.ErrorParent(errMisMatchingSize)
|
||||
return ErrorDestinationSize.Error(errMisMatchingSize)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -32,12 +32,11 @@ import (
|
||||
|
||||
libart "github.com/nabbar/golib/artifact"
|
||||
artcli "github.com/nabbar/golib/artifact/client"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func NewArtifactory(ctx context.Context, Do func(req *http.Request) (*http.Response, error), uri, releaseRegex string, releaseGroup int, reposPath ...string) (libart.Client, liberr.Error) {
|
||||
func NewArtifactory(ctx context.Context, Do func(req *http.Request) (*http.Response, error), uri, releaseRegex string, releaseGroup int, reposPath ...string) (libart.Client, error) {
|
||||
if u, e := url.Parse(uri); e != nil {
|
||||
return nil, ErrorURLParse.ErrorParent(e)
|
||||
return nil, ErrorURLParse.Error(e)
|
||||
} else {
|
||||
a := &artifactoryModel{
|
||||
ClientHelper: artcli.ClientHelper{},
|
||||
|
@@ -42,7 +42,6 @@ import (
|
||||
hscvrs "github.com/hashicorp/go-version"
|
||||
libart "github.com/nabbar/golib/artifact"
|
||||
artcli "github.com/nabbar/golib/artifact/client"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libfpg "github.com/nabbar/golib/file/progress"
|
||||
)
|
||||
|
||||
@@ -97,7 +96,7 @@ type ResponseReposStorage struct {
|
||||
Children []ResponseReposChildrenStorage
|
||||
}
|
||||
|
||||
func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr.Error {
|
||||
func (a *artifactoryModel) request(uri string, bodyResponse interface{}) error {
|
||||
var (
|
||||
ctx context.Context
|
||||
cnl context.CancelFunc
|
||||
@@ -138,7 +137,7 @@ func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr.
|
||||
u.Path = path.Clean(u.Path)
|
||||
|
||||
if req, e = http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil); e != nil {
|
||||
return ErrorRequestInit.ErrorParent(e)
|
||||
return ErrorRequestInit.Error(e)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -148,7 +147,7 @@ func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr.
|
||||
}()
|
||||
|
||||
if rsp, e = a.Do(req); e != nil {
|
||||
return ErrorRequestDo.ErrorParent(e)
|
||||
return ErrorRequestDo.Error(e)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -159,18 +158,18 @@ func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr.
|
||||
|
||||
if rsp.StatusCode >= http.StatusBadRequest {
|
||||
//nolint #goerr113
|
||||
return ErrorRequestResponse.ErrorParent(fmt.Errorf("status: %v", rsp.Status))
|
||||
return ErrorRequestResponse.Error(fmt.Errorf("status: %v", rsp.Status))
|
||||
}
|
||||
|
||||
if rsp.Body == nil {
|
||||
//nolint #goerr113
|
||||
return ErrorRequestResponseBodyEmpty.ErrorParent(fmt.Errorf("status: %v", rsp.Status))
|
||||
return ErrorRequestResponseBodyEmpty.Error(fmt.Errorf("status: %v", rsp.Status))
|
||||
}
|
||||
|
||||
if buf, e := ioutil.ReadAll(rsp.Body); e != nil {
|
||||
return ErrorRequestResponseBodyDecode.ErrorParent(e)
|
||||
return ErrorRequestResponseBodyDecode.Error(e)
|
||||
} else if e = json.Unmarshal(buf, bodyResponse); e != nil {
|
||||
return ErrorRequestResponseBodyDecode.ErrorParent(e)
|
||||
return ErrorRequestResponseBodyDecode.Error(e)
|
||||
}
|
||||
|
||||
cnl()
|
||||
@@ -180,7 +179,7 @@ func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr.
|
||||
|
||||
}
|
||||
|
||||
func (a *artifactoryModel) getStorageList() (sto []ResponseStorage, err liberr.Error) {
|
||||
func (a *artifactoryModel) getStorageList() (sto []ResponseStorage, err error) {
|
||||
var (
|
||||
lst = ResponseReposStorage{}
|
||||
reg = regexp.MustCompile(a.regex)
|
||||
@@ -188,12 +187,12 @@ func (a *artifactoryModel) getStorageList() (sto []ResponseStorage, err liberr.E
|
||||
|
||||
if a.regex == "" {
|
||||
//nolint #goerr113
|
||||
return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("regex is empty: %s", a.regex))
|
||||
return nil, ErrorParamEmpty.Error(fmt.Errorf("regex is empty: %s", a.regex))
|
||||
}
|
||||
|
||||
if a.group < 1 {
|
||||
//nolint #goerr113
|
||||
return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("group extracted from regex is empty: %s - %v", a.regex, a.group))
|
||||
return nil, ErrorParamEmpty.Error(fmt.Errorf("group extracted from regex is empty: %s - %v", a.regex, a.group))
|
||||
}
|
||||
|
||||
if err = a.request("", &lst); err != nil {
|
||||
@@ -223,7 +222,7 @@ func (a *artifactoryModel) getStorageList() (sto []ResponseStorage, err liberr.E
|
||||
}
|
||||
|
||||
if res.size, e = strconv.ParseInt(res.Size, 10, 64); e != nil {
|
||||
return nil, ErrorRequestResponseBodyDecode.ErrorParent(e)
|
||||
return nil, ErrorRequestResponseBodyDecode.Error(e)
|
||||
}
|
||||
|
||||
sto = append(sto, res)
|
||||
@@ -242,7 +241,7 @@ func (a *artifactoryModel) releasesAppendNotExist(releases hscvrs.Collection, ve
|
||||
return append(releases, vers)
|
||||
}
|
||||
|
||||
func (a *artifactoryModel) ListReleases() (releases hscvrs.Collection, err liberr.Error) {
|
||||
func (a *artifactoryModel) ListReleases() (releases hscvrs.Collection, err error) {
|
||||
var (
|
||||
reg = regexp.MustCompile(a.regex)
|
||||
sto []ResponseStorage
|
||||
@@ -271,7 +270,7 @@ func (a *artifactoryModel) ListReleases() (releases hscvrs.Collection, err liber
|
||||
return releases, nil
|
||||
}
|
||||
|
||||
func (a *artifactoryModel) getArtifact(containName string, regexName string, release *hscvrs.Version) (art *ResponseStorage, err liberr.Error) {
|
||||
func (a *artifactoryModel) getArtifact(containName string, regexName string, release *hscvrs.Version) (art *ResponseStorage, err error) {
|
||||
var (
|
||||
reg = regexp.MustCompile(a.regex)
|
||||
rg2 *regexp.Regexp
|
||||
@@ -312,7 +311,7 @@ func (a *artifactoryModel) getArtifact(containName string, regexName string, rel
|
||||
return nil, ErrorArtifactoryNotFound.Error(nil)
|
||||
}
|
||||
|
||||
func (a *artifactoryModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) {
|
||||
func (a *artifactoryModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) {
|
||||
if art, err := a.getArtifact(containName, regexName, release); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
@@ -320,13 +319,13 @@ func (a *artifactoryModel) GetArtifact(containName string, regexName string, rel
|
||||
}
|
||||
}
|
||||
|
||||
func (a *artifactoryModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error {
|
||||
func (a *artifactoryModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error {
|
||||
var (
|
||||
e error
|
||||
n int64
|
||||
|
||||
art *ResponseStorage
|
||||
err liberr.Error
|
||||
err error
|
||||
req *http.Request
|
||||
rsp *http.Response
|
||||
)
|
||||
@@ -348,21 +347,21 @@ func (a *artifactoryModel) Download(dst libfpg.Progress, containName string, reg
|
||||
}
|
||||
|
||||
if req, e = http.NewRequestWithContext(a.ctx, http.MethodGet, art.DownloadUri, nil); e != nil {
|
||||
return ErrorRequestInit.ErrorParent(e)
|
||||
return ErrorRequestInit.Error(e)
|
||||
} else if rsp, e = a.Do(req); e != nil {
|
||||
return ErrorRequestDo.ErrorParent(e)
|
||||
return ErrorRequestDo.Error(e)
|
||||
} else if rsp.StatusCode >= http.StatusBadRequest {
|
||||
//nolint #goerr113
|
||||
return ErrorRequestResponse.ErrorParent(fmt.Errorf("status: %v", rsp.Status))
|
||||
return ErrorRequestResponse.Error(fmt.Errorf("status: %v", rsp.Status))
|
||||
} else if rsp.Body == nil {
|
||||
//nolint #goerr113
|
||||
return ErrorRequestResponseBodyEmpty.ErrorParent(fmt.Errorf("status: %v", rsp.Status))
|
||||
return ErrorRequestResponseBodyEmpty.Error(fmt.Errorf("status: %v", rsp.Status))
|
||||
} else if n, e = io.Copy(dst, rsp.Body); e != nil {
|
||||
return ErrorArtifactoryDownload.ErrorParent(e)
|
||||
return ErrorArtifactoryDownload.Error(e)
|
||||
} else if n != art.size {
|
||||
return ErrorDestinationSize.ErrorParent(errMisMatchingSize)
|
||||
return ErrorDestinationSize.Error(errMisMatchingSize)
|
||||
} else if n != rsp.ContentLength {
|
||||
return ErrorDestinationSize.ErrorParent(errMisMatchingSize)
|
||||
return ErrorDestinationSize.Error(errMisMatchingSize)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -36,7 +36,6 @@ import (
|
||||
libart "github.com/nabbar/golib/artifact"
|
||||
artcli "github.com/nabbar/golib/artifact/client"
|
||||
libaws "github.com/nabbar/golib/aws"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libfpg "github.com/nabbar/golib/file/progress"
|
||||
)
|
||||
|
||||
@@ -49,9 +48,9 @@ type s3awsModel struct {
|
||||
group int
|
||||
}
|
||||
|
||||
func (s *s3awsModel) ListReleases() (releases hscvrs.Collection, err liberr.Error) {
|
||||
func (s *s3awsModel) ListReleases() (releases hscvrs.Collection, err error) {
|
||||
var (
|
||||
e liberr.Error
|
||||
e error
|
||||
r *regexp.Regexp
|
||||
l []string
|
||||
)
|
||||
@@ -70,7 +69,7 @@ func (s *s3awsModel) ListReleases() (releases hscvrs.Collection, err liberr.Erro
|
||||
grp := r.FindStringSubmatch(o)
|
||||
|
||||
if len(grp) < s.group {
|
||||
return nil, ErrorS3AWSRegex.ErrorParent(getError(errRegexGroup, s.regex, len(grp), s.group))
|
||||
return nil, ErrorS3AWSRegex.Error(getError(errRegexGroup, s.regex, len(grp), s.group))
|
||||
}
|
||||
|
||||
if v, e := hscvrs.NewVersion(grp[s.group]); e != nil {
|
||||
@@ -94,7 +93,7 @@ func (s *s3awsModel) ListReleases() (releases hscvrs.Collection, err liberr.Erro
|
||||
return releases, nil
|
||||
}
|
||||
|
||||
func (s *s3awsModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) {
|
||||
func (s *s3awsModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) {
|
||||
var (
|
||||
e error
|
||||
k bool
|
||||
@@ -117,11 +116,11 @@ func (s *s3awsModel) GetArtifact(containName string, regexName string, release *
|
||||
grp := r.FindStringSubmatch(o)
|
||||
|
||||
if len(grp) < s.group {
|
||||
return "", ErrorS3AWSRegex.ErrorParent(getError(errRegexGroup, s.regex, len(grp), s.group))
|
||||
return "", ErrorS3AWSRegex.Error(getError(errRegexGroup, s.regex, len(grp), s.group))
|
||||
}
|
||||
|
||||
if v, e = hscvrs.NewVersion(grp[s.group]); e != nil {
|
||||
return "", ErrorS3AWSNewVers.ErrorParent(getError(errVersion, grp[s.group]), e)
|
||||
return "", ErrorS3AWSNewVers.Error(getError(errVersion, grp[s.group]), e)
|
||||
} else if v.Equal(release) {
|
||||
uri := s.c.Config().GetEndpoint()
|
||||
uri.Path += "/" + s.c.GetBucketName() + "/" + o
|
||||
@@ -143,10 +142,10 @@ func (s *s3awsModel) GetArtifact(containName string, regexName string, release *
|
||||
}
|
||||
}
|
||||
|
||||
return "", ErrorS3AWSNotFound.ErrorParent(getError(errVersRequest, release.String()))
|
||||
return "", ErrorS3AWSNotFound.Error(getError(errVersRequest, release.String()))
|
||||
}
|
||||
|
||||
func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error {
|
||||
func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error {
|
||||
var (
|
||||
e error
|
||||
r *regexp.Regexp
|
||||
@@ -154,7 +153,7 @@ func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName
|
||||
v *hscvrs.Version
|
||||
k bool
|
||||
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if s.regex == "" {
|
||||
@@ -171,11 +170,11 @@ func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName
|
||||
grp := r.FindStringSubmatch(o)
|
||||
|
||||
if len(grp) < s.group {
|
||||
return ErrorS3AWSRegex.ErrorParent(getError(errRegexGroup, s.regex, len(grp), s.group))
|
||||
return ErrorS3AWSRegex.Error(getError(errRegexGroup, s.regex, len(grp), s.group))
|
||||
}
|
||||
|
||||
if v, e = hscvrs.NewVersion(grp[s.group]); e != nil {
|
||||
return ErrorS3AWSNewVers.ErrorParent(getError(errVersion, grp[s.group]), e)
|
||||
return ErrorS3AWSNewVers.Error(getError(errVersion, grp[s.group]), e)
|
||||
} else if v.Equal(release) {
|
||||
if containName != "" && strings.Contains(o, containName) {
|
||||
return s.downloadObject(dst, o)
|
||||
@@ -193,17 +192,17 @@ func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorS3AWSNotFound.ErrorParent(getError(errVersRequest, release.String()))
|
||||
return ErrorS3AWSNotFound.Error(getError(errVersRequest, release.String()))
|
||||
}
|
||||
|
||||
func (s *s3awsModel) downloadObject(dst libfpg.Progress, object string) liberr.Error {
|
||||
func (s *s3awsModel) downloadObject(dst libfpg.Progress, object string) error {
|
||||
var (
|
||||
r *sdksss.GetObjectOutput
|
||||
e error
|
||||
j int64
|
||||
n int64
|
||||
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
defer func() {
|
||||
@@ -213,25 +212,25 @@ func (s *s3awsModel) downloadObject(dst libfpg.Progress, object string) liberr.E
|
||||
}()
|
||||
|
||||
if j, err = s.c.Object().Size(object); err != nil {
|
||||
err = ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object))
|
||||
err.AddParentError(err)
|
||||
return err
|
||||
er := ErrorS3AWSDownloadError.Error(getError(errObject, object))
|
||||
er.Add(err)
|
||||
return er
|
||||
} else if j < 1 {
|
||||
return ErrorS3AWSDownloadError.ErrorParent(getError(errObjectEmpty, object))
|
||||
return ErrorS3AWSDownloadError.Error(getError(errObjectEmpty, object))
|
||||
} else {
|
||||
dst.Reset(j)
|
||||
}
|
||||
|
||||
if r, err = s.c.Object().Get(object); err != nil {
|
||||
err = ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object))
|
||||
err.AddParentError(err)
|
||||
return err
|
||||
er := ErrorS3AWSDownloadError.Error(getError(errObject, object))
|
||||
er.Add(err)
|
||||
return er
|
||||
} else if r.Body == nil {
|
||||
return ErrorS3AWSIOReaderError.ErrorParent(getError(errObject, object))
|
||||
return ErrorS3AWSIOReaderError.Error(getError(errObject, object))
|
||||
} else if n, e = io.Copy(dst, r.Body); e != nil {
|
||||
return ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object), e)
|
||||
return ErrorS3AWSDownloadError.Error(getError(errObject, object), e)
|
||||
} else if n != j {
|
||||
return ErrorS3AWSDownloadError.ErrorParent(getError(errObjectSize, object))
|
||||
return ErrorS3AWSDownloadError.Error(getError(errObjectSize, object))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -32,13 +32,12 @@ import (
|
||||
libart "github.com/nabbar/golib/artifact"
|
||||
artcli "github.com/nabbar/golib/artifact/client"
|
||||
libaws "github.com/nabbar/golib/aws"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func NewS3AWS(ctx context.Context, cfg libaws.Config, httpcli *http.Client, forceModePath bool, releaseRegex string, releaseGroup int) (cli libart.Client, err liberr.Error) {
|
||||
func NewS3AWS(ctx context.Context, cfg libaws.Config, httpcli *http.Client, forceModePath bool, releaseRegex string, releaseGroup int) (cli libart.Client, err error) {
|
||||
var (
|
||||
c libaws.AWS
|
||||
e liberr.Error
|
||||
e error
|
||||
)
|
||||
|
||||
if c, e = libaws.New(ctx, cfg, httpcli); e != nil {
|
||||
|
@@ -26,11 +26,10 @@
|
||||
package bucket
|
||||
|
||||
import (
|
||||
adkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type ACLHeader uint8
|
||||
@@ -49,7 +48,7 @@ type ACLHeaders map[ACLHeader]string
|
||||
// for GetACL
|
||||
// see : https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketAcl.html
|
||||
|
||||
func (cli *client) GetACL() (*sdkstp.AccessControlPolicy, liberr.Error) {
|
||||
func (cli *client) GetACL() (*sdkstp.AccessControlPolicy, error) {
|
||||
out, err := cli.s3.GetBucketAcl(cli.GetContext(), &sdksss.GetBucketAclInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
@@ -83,7 +82,7 @@ func (cli *client) GetACL() (*sdkstp.AccessControlPolicy, liberr.Error) {
|
||||
//example value : uri="http://acs.amazonaws.com/groups/s3/LogDelivery", emailAddress="xyz@amazon.com"
|
||||
// for more info, see : https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketAcl.html#API_PutBucketAcl_RequestSyntax
|
||||
|
||||
func (cli *client) SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error {
|
||||
func (cli *client) SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error {
|
||||
in := &sdksss.PutBucketAclInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
}
|
||||
@@ -91,7 +90,7 @@ func (cli *client) SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.Buck
|
||||
return cli.setACLInput(in, ACP, cannedACL, header)
|
||||
}
|
||||
|
||||
func (cli *client) SetACLPolicy(ACP *sdkstp.AccessControlPolicy) liberr.Error {
|
||||
func (cli *client) SetACLPolicy(ACP *sdkstp.AccessControlPolicy) error {
|
||||
in := &sdksss.PutBucketAclInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
}
|
||||
@@ -99,7 +98,7 @@ func (cli *client) SetACLPolicy(ACP *sdkstp.AccessControlPolicy) liberr.Error {
|
||||
return cli.setACLInput(in, ACP, "", nil)
|
||||
}
|
||||
|
||||
func (cli *client) SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error {
|
||||
func (cli *client) SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error {
|
||||
in := &sdksss.PutBucketAclInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
}
|
||||
@@ -107,7 +106,7 @@ func (cli *client) SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHead
|
||||
return cli.setACLInput(in, nil, cannedACL, header)
|
||||
}
|
||||
|
||||
func (cli *client) setACLInput(in *sdksss.PutBucketAclInput, ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error {
|
||||
func (cli *client) setACLInput(in *sdksss.PutBucketAclInput, ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error {
|
||||
if ACP != nil {
|
||||
in.AccessControlPolicy = ACP
|
||||
}
|
||||
@@ -120,15 +119,15 @@ func (cli *client) setACLInput(in *sdksss.PutBucketAclInput, ACP *sdkstp.AccessC
|
||||
for k, v := range header {
|
||||
switch k {
|
||||
case ACLHeaderFullControl:
|
||||
in.GrantFullControl = adkaws.String(v)
|
||||
in.GrantFullControl = sdkaws.String(v)
|
||||
case ACLHeaderRead:
|
||||
in.GrantRead = adkaws.String(v)
|
||||
in.GrantRead = sdkaws.String(v)
|
||||
case ACLHeaderWrite:
|
||||
in.GrantWrite = adkaws.String(v)
|
||||
in.GrantWrite = sdkaws.String(v)
|
||||
case ACLHeaderReadACP:
|
||||
in.GrantReadACP = adkaws.String(v)
|
||||
in.GrantReadACP = sdkaws.String(v)
|
||||
case ACLHeaderWriteACP:
|
||||
in.GrantWriteACP = adkaws.String(v)
|
||||
in.GrantWriteACP = sdkaws.String(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,10 +31,9 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) Check() liberr.Error {
|
||||
func (cli *client) Check() error {
|
||||
out, err := cli.s3.HeadBucket(cli.GetContext(), &sdksss.HeadBucketInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
@@ -43,21 +42,21 @@ func (cli *client) Check() liberr.Error {
|
||||
return cli.GetError(err)
|
||||
} else if out == nil {
|
||||
//nolint #goerr113
|
||||
return libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
return libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) Create(RegionConstraint string) liberr.Error {
|
||||
func (cli *client) Create(RegionConstraint string) error {
|
||||
return cli._create(RegionConstraint, false)
|
||||
}
|
||||
|
||||
func (cli *client) CreateWithLock(RegionConstraint string) liberr.Error {
|
||||
func (cli *client) CreateWithLock(RegionConstraint string) error {
|
||||
return cli._create(RegionConstraint, true)
|
||||
}
|
||||
|
||||
func (cli *client) _create(RegionConstraint string, lockEnable bool) liberr.Error {
|
||||
func (cli *client) _create(RegionConstraint string, lockEnable bool) error {
|
||||
in := &sdksss.CreateBucketInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
CreateBucketConfiguration: &sdkstp.CreateBucketConfiguration{},
|
||||
@@ -83,7 +82,7 @@ func (cli *client) _create(RegionConstraint string, lockEnable bool) liberr.Erro
|
||||
|
||||
}
|
||||
|
||||
func (cli *client) Delete() liberr.Error {
|
||||
func (cli *client) Delete() error {
|
||||
_, err := cli.s3.DeleteBucket(cli.GetContext(), &sdksss.DeleteBucketInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
@@ -91,7 +90,7 @@ func (cli *client) Delete() liberr.Error {
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) List() ([]sdkstp.Bucket, liberr.Error) {
|
||||
func (cli *client) List() ([]sdkstp.Bucket, error) {
|
||||
out, err := cli.s3.ListBuckets(cli.GetContext(), nil)
|
||||
|
||||
if err != nil {
|
||||
@@ -103,7 +102,7 @@ func (cli *client) List() ([]sdkstp.Bucket, liberr.Error) {
|
||||
return out.Buckets, nil
|
||||
}
|
||||
|
||||
func (cli *client) Walk(f WalkFunc) liberr.Error {
|
||||
func (cli *client) Walk(f WalkFunc) error {
|
||||
out, err := cli.s3.ListBuckets(cli.GetContext(), nil)
|
||||
|
||||
if err != nil {
|
||||
@@ -112,7 +111,7 @@ func (cli *client) Walk(f WalkFunc) liberr.Error {
|
||||
return libhlp.ErrorAwsEmpty.Error(nil)
|
||||
}
|
||||
|
||||
var e liberr.Error
|
||||
var e error
|
||||
for _, b := range out.Buckets {
|
||||
if b.Name == nil || b.CreationDate == nil || len(*b.Name) < 3 || b.CreationDate.IsZero() {
|
||||
continue
|
||||
|
@@ -29,10 +29,9 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) GetCORS() ([]sdkstp.CORSRule, liberr.Error) {
|
||||
func (cli *client) GetCORS() ([]sdkstp.CORSRule, error) {
|
||||
out, err := cli.s3.GetBucketCors(cli.GetContext(), &sdksss.GetBucketCorsInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
@@ -49,7 +48,7 @@ func (cli *client) GetCORS() ([]sdkstp.CORSRule, liberr.Error) {
|
||||
return out.CORSRules, nil
|
||||
}
|
||||
|
||||
func (cli *client) SetCORS(cors []sdkstp.CORSRule) liberr.Error {
|
||||
func (cli *client) SetCORS(cors []sdkstp.CORSRule) error {
|
||||
_, err := cli.s3.PutBucketCors(cli.GetContext(), &sdksss.PutBucketCorsInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
CORSConfiguration: &sdkstp.CORSConfiguration{
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
@@ -41,41 +40,41 @@ type client struct {
|
||||
s3 *sdksss.Client
|
||||
}
|
||||
|
||||
type WalkFunc func(err liberr.Error, bucket sdkstp.Bucket) liberr.Error
|
||||
type WalkFunc func(err error, bucket sdkstp.Bucket) error
|
||||
|
||||
type Bucket interface {
|
||||
Check() liberr.Error
|
||||
Check() error
|
||||
|
||||
List() ([]sdkstp.Bucket, liberr.Error)
|
||||
Walk(f WalkFunc) liberr.Error
|
||||
Create(RegionConstraint string) liberr.Error
|
||||
CreateWithLock(RegionConstraint string) liberr.Error
|
||||
Delete() liberr.Error
|
||||
List() ([]sdkstp.Bucket, error)
|
||||
Walk(f WalkFunc) error
|
||||
Create(RegionConstraint string) error
|
||||
CreateWithLock(RegionConstraint string) error
|
||||
Delete() error
|
||||
|
||||
//FindObject(pattern string) ([]string, errors.Error)
|
||||
|
||||
SetVersioning(state bool) liberr.Error
|
||||
GetVersioning() (string, liberr.Error)
|
||||
SetVersioning(state bool) error
|
||||
GetVersioning() (string, error)
|
||||
|
||||
LoadReplication() (*sdkstp.ReplicationConfiguration, liberr.Error)
|
||||
EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) liberr.Error
|
||||
DeleteReplication() liberr.Error
|
||||
LoadReplication() (*sdkstp.ReplicationConfiguration, error)
|
||||
EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) error
|
||||
DeleteReplication() error
|
||||
|
||||
PutWebsite(index, error string) liberr.Error
|
||||
GetWebsite() (*sdksss.GetBucketWebsiteOutput, liberr.Error)
|
||||
PutWebsite(index, error string) error
|
||||
GetWebsite() (*sdksss.GetBucketWebsiteOutput, error)
|
||||
|
||||
SetCORS(cors []sdkstp.CORSRule) liberr.Error
|
||||
GetCORS() ([]sdkstp.CORSRule, liberr.Error)
|
||||
SetCORS(cors []sdkstp.CORSRule) error
|
||||
GetCORS() ([]sdkstp.CORSRule, error)
|
||||
|
||||
GetACL() (*sdkstp.AccessControlPolicy, liberr.Error)
|
||||
SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error
|
||||
SetACLPolicy(ACP *sdkstp.AccessControlPolicy) liberr.Error
|
||||
SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error
|
||||
GetACL() (*sdkstp.AccessControlPolicy, error)
|
||||
SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error
|
||||
SetACLPolicy(ACP *sdkstp.AccessControlPolicy) error
|
||||
SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error
|
||||
|
||||
GetLifeCycle() ([]sdkstp.LifecycleRule, liberr.Error)
|
||||
SetLifeCycle(rules ...sdkstp.LifecycleRule) liberr.Error
|
||||
GetLock() (*sdkstp.ObjectLockConfiguration, liberr.Error)
|
||||
SetLock(cfg sdkstp.ObjectLockConfiguration, token string) liberr.Error
|
||||
GetLifeCycle() ([]sdkstp.LifecycleRule, error)
|
||||
SetLifeCycle(rules ...sdkstp.LifecycleRule) error
|
||||
GetLock() (*sdkstp.ObjectLockConfiguration, error)
|
||||
SetLock(cfg sdkstp.ObjectLockConfiguration, token string) error
|
||||
}
|
||||
|
||||
func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Bucket {
|
||||
|
@@ -33,10 +33,9 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) GetLifeCycle() ([]sdkstp.LifecycleRule, liberr.Error) {
|
||||
func (cli *client) GetLifeCycle() ([]sdkstp.LifecycleRule, error) {
|
||||
out, err := cli.s3.GetBucketLifecycleConfiguration(cli.GetContext(), &sdksss.GetBucketLifecycleConfigurationInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
@@ -45,13 +44,13 @@ func (cli *client) GetLifeCycle() ([]sdkstp.LifecycleRule, liberr.Error) {
|
||||
return nil, cli.GetError(err)
|
||||
} else if out == nil {
|
||||
//nolint #goerr113
|
||||
return nil, libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
return nil, libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
}
|
||||
|
||||
return out.Rules, nil
|
||||
}
|
||||
|
||||
func (cli *client) SetLifeCycle(rules ...sdkstp.LifecycleRule) liberr.Error {
|
||||
func (cli *client) SetLifeCycle(rules ...sdkstp.LifecycleRule) error {
|
||||
out, err := cli.s3.PutBucketLifecycleConfiguration(cli.GetContext(), &sdksss.PutBucketLifecycleConfigurationInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
LifecycleConfiguration: &sdkstp.BucketLifecycleConfiguration{
|
||||
@@ -63,13 +62,13 @@ func (cli *client) SetLifeCycle(rules ...sdkstp.LifecycleRule) liberr.Error {
|
||||
return cli.GetError(err)
|
||||
} else if out == nil {
|
||||
//nolint #goerr113
|
||||
return libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
return libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) GetLock() (*sdkstp.ObjectLockConfiguration, liberr.Error) {
|
||||
func (cli *client) GetLock() (*sdkstp.ObjectLockConfiguration, error) {
|
||||
out, err := cli.s3.GetObjectLockConfiguration(cli.GetContext(), &sdksss.GetObjectLockConfigurationInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
@@ -78,13 +77,13 @@ func (cli *client) GetLock() (*sdkstp.ObjectLockConfiguration, liberr.Error) {
|
||||
return nil, cli.GetError(err)
|
||||
} else if out == nil {
|
||||
//nolint #goerr113
|
||||
return nil, libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
return nil, libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
}
|
||||
|
||||
return out.ObjectLockConfiguration, nil
|
||||
}
|
||||
|
||||
func (cli *client) SetLock(cfg sdkstp.ObjectLockConfiguration, token string) liberr.Error {
|
||||
func (cli *client) SetLock(cfg sdkstp.ObjectLockConfiguration, token string) error {
|
||||
in := &sdksss.PutObjectLockConfigurationInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
ObjectLockConfiguration: &cfg,
|
||||
@@ -100,7 +99,7 @@ func (cli *client) SetLock(cfg sdkstp.ObjectLockConfiguration, token string) lib
|
||||
return cli.GetError(err)
|
||||
} else if out == nil {
|
||||
//nolint #goerr113
|
||||
return libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
return libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName()))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -30,10 +30,9 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) LoadReplication() (*sdkstp.ReplicationConfiguration, liberr.Error) {
|
||||
func (cli *client) LoadReplication() (*sdkstp.ReplicationConfiguration, error) {
|
||||
in := sdksss.GetBucketReplicationInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
}
|
||||
@@ -49,7 +48,7 @@ func (cli *client) LoadReplication() (*sdkstp.ReplicationConfiguration, liberr.E
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) liberr.Error {
|
||||
func (cli *client) EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) error {
|
||||
var status sdkstp.ReplicationRuleStatus = libhlp.STATE_ENABLED
|
||||
|
||||
_, err := cli.s3.PutBucketReplication(cli.GetContext(), &sdksss.PutBucketReplicationInput{
|
||||
@@ -71,7 +70,7 @@ func (cli *client) EnableReplication(srcRoleARN, dstRoleARN, dstBucketName strin
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) DeleteReplication() liberr.Error {
|
||||
func (cli *client) DeleteReplication() error {
|
||||
_, err := cli.s3.DeleteBucketReplication(cli.GetContext(), &sdksss.DeleteBucketReplicationInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
|
@@ -29,10 +29,9 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) SetVersioning(state bool) liberr.Error {
|
||||
func (cli *client) SetVersioning(state bool) error {
|
||||
var status sdkstp.BucketVersioningStatus = libhlp.STATE_ENABLED
|
||||
if !state {
|
||||
status = libhlp.STATE_SUSPENDED
|
||||
@@ -48,7 +47,7 @@ func (cli *client) SetVersioning(state bool) liberr.Error {
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) GetVersioning() (string, liberr.Error) {
|
||||
func (cli *client) GetVersioning() (string, error) {
|
||||
out, err := cli.s3.GetBucketVersioning(cli.GetContext(), &sdksss.GetBucketVersioningInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
|
@@ -30,10 +30,9 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) PutWebsite(index, error string) liberr.Error {
|
||||
func (cli *client) PutWebsite(index, error string) error {
|
||||
_, err := cli.s3.PutBucketWebsite(cli.GetContext(), &sdksss.PutBucketWebsiteInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
WebsiteConfiguration: &sdkstp.WebsiteConfiguration{
|
||||
@@ -49,7 +48,7 @@ func (cli *client) PutWebsite(index, error string) liberr.Error {
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) GetWebsite() (*sdksss.GetBucketWebsiteOutput, liberr.Error) {
|
||||
func (cli *client) GetWebsite() (*sdksss.GetBucketWebsiteOutput, error) {
|
||||
out, err := cli.s3.GetBucketWebsite(cli.GetContext(), &sdksss.GetBucketWebsiteInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
})
|
||||
|
@@ -34,17 +34,16 @@ import (
|
||||
sdkcfg "github.com/aws/aws-sdk-go-v2/config"
|
||||
sdkcrd "github.com/aws/aws-sdk-go-v2/credentials"
|
||||
libaws "github.com/nabbar/golib/aws"
|
||||
"github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func GetConfigModel() interface{} {
|
||||
return Model{}
|
||||
}
|
||||
|
||||
func NewConfigJsonUnmashal(p []byte) (libaws.Config, errors.Error) {
|
||||
func NewConfigJsonUnmashal(p []byte) (libaws.Config, error) {
|
||||
c := Model{}
|
||||
if err := json.Unmarshal(p, &c); err != nil {
|
||||
return nil, ErrorConfigJsonUnmarshall.ErrorParent(err)
|
||||
return nil, ErrorConfigJsonUnmarshall.Error(err)
|
||||
}
|
||||
|
||||
return &awsModel{
|
||||
@@ -53,10 +52,10 @@ func NewConfigJsonUnmashal(p []byte) (libaws.Config, errors.Error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, errors.Error) {
|
||||
func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, error) {
|
||||
c := ModelStatus{}
|
||||
if err := json.Unmarshal(p, &c); err != nil {
|
||||
return nil, ErrorConfigJsonUnmarshall.ErrorParent(err)
|
||||
return nil, ErrorConfigJsonUnmarshall.Error(err)
|
||||
}
|
||||
|
||||
return &awsModel{
|
||||
@@ -89,14 +88,14 @@ func (c *awsModel) Clone() libaws.Config {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, errors.Error) {
|
||||
func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, error) {
|
||||
var (
|
||||
cfg sdkaws.Config
|
||||
err error
|
||||
)
|
||||
|
||||
if cfg, err = sdkcfg.LoadDefaultConfig(ctx); err != nil {
|
||||
return nil, ErrorConfigLoader.ErrorParent(err)
|
||||
return nil, ErrorConfigLoader.Error(err)
|
||||
}
|
||||
|
||||
if c.AccessKey != "" && c.SecretKey != "" {
|
||||
|
@@ -31,12 +31,10 @@ import (
|
||||
"net"
|
||||
"net/url"
|
||||
|
||||
libreq "github.com/nabbar/golib/request"
|
||||
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
libval "github.com/go-playground/validator/v10"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libhtc "github.com/nabbar/golib/httpcli"
|
||||
libreq "github.com/nabbar/golib/request"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
@@ -57,17 +55,17 @@ type awsModel struct {
|
||||
retryer func() sdkaws.Retryer
|
||||
}
|
||||
|
||||
func (c *awsModel) Validate() liberr.Error {
|
||||
func (c *awsModel) Validate() error {
|
||||
err := ErrorConfigValidator.Error(nil)
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,11 +88,11 @@ func (c *awsModel) SetCredentials(accessKey, secretKey string) {
|
||||
func (c *awsModel) ResetRegionEndpoint() {
|
||||
}
|
||||
|
||||
func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error {
|
||||
func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *awsModel) RegisterRegionAws(endpoint *url.URL) liberr.Error {
|
||||
func (c *awsModel) RegisterRegionAws(endpoint *url.URL) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -137,14 +135,14 @@ func (c *awsModel) SetRetryer(retryer func() sdkaws.Retryer) {
|
||||
c.retryer = retryer
|
||||
}
|
||||
|
||||
func (c *awsModel) Check(ctx context.Context) liberr.Error {
|
||||
func (c *awsModel) Check(ctx context.Context) error {
|
||||
var (
|
||||
cfg *sdkaws.Config
|
||||
con net.Conn
|
||||
end sdkaws.Endpoint
|
||||
adr *url.URL
|
||||
err error
|
||||
e liberr.Error
|
||||
e error
|
||||
)
|
||||
|
||||
if cfg, e = c.GetConfig(ctx, nil); e != nil {
|
||||
@@ -156,15 +154,15 @@ func (c *awsModel) Check(ctx context.Context) liberr.Error {
|
||||
}
|
||||
|
||||
if end, err = cfg.EndpointResolverWithOptions.ResolveEndpoint("s3", c.GetRegion()); err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
}
|
||||
|
||||
if adr, err = url.Parse(end.URL); err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
}
|
||||
|
||||
if _, err = cfg.Credentials.Retrieve(ctx); err != nil {
|
||||
return ErrorCredentialsInvalid.ErrorParent(err)
|
||||
return ErrorCredentialsInvalid.Error(err)
|
||||
}
|
||||
|
||||
d := net.Dialer{
|
||||
@@ -181,7 +179,7 @@ func (c *awsModel) Check(ctx context.Context) liberr.Error {
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -35,17 +35,16 @@ import (
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkcrd "github.com/aws/aws-sdk-go-v2/credentials"
|
||||
libaws "github.com/nabbar/golib/aws"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func GetConfigModel() interface{} {
|
||||
return Model{}
|
||||
}
|
||||
|
||||
func NewConfigJsonUnmashal(p []byte) (libaws.Config, liberr.Error) {
|
||||
func NewConfigJsonUnmashal(p []byte) (libaws.Config, error) {
|
||||
c := Model{}
|
||||
if err := json.Unmarshal(p, &c); err != nil {
|
||||
return nil, ErrorConfigJsonUnmarshall.ErrorParent(err)
|
||||
return nil, ErrorConfigJsonUnmarshall.Error(err)
|
||||
}
|
||||
|
||||
return &awsModel{
|
||||
@@ -55,10 +54,10 @@ func NewConfigJsonUnmashal(p []byte) (libaws.Config, liberr.Error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, liberr.Error) {
|
||||
func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, error) {
|
||||
c := ModelStatus{}
|
||||
if err := json.Unmarshal(p, &c); err != nil {
|
||||
return nil, ErrorConfigJsonUnmarshall.ErrorParent(err)
|
||||
return nil, ErrorConfigJsonUnmarshall.Error(err)
|
||||
}
|
||||
|
||||
return &awsModel{
|
||||
@@ -104,7 +103,7 @@ func (c *awsModel) Clone() libaws.Config {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, liberr.Error) {
|
||||
func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, error) {
|
||||
|
||||
cfg := sdkaws.NewConfig()
|
||||
|
||||
|
@@ -34,7 +34,6 @@ import (
|
||||
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
libval "github.com/go-playground/validator/v10"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libhtc "github.com/nabbar/golib/httpcli"
|
||||
libreq "github.com/nabbar/golib/request"
|
||||
)
|
||||
@@ -61,26 +60,26 @@ type awsModel struct {
|
||||
mapRegion map[string]*url.URL
|
||||
}
|
||||
|
||||
func (c *awsModel) Validate() liberr.Error {
|
||||
func (c *awsModel) Validate() error {
|
||||
err := ErrorConfigValidator.Error(nil)
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
if c.Endpoint != "" && c.endpoint == nil {
|
||||
var e error
|
||||
if c.endpoint, e = url.Parse(c.Endpoint); e != nil {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
} else if er := c.RegisterRegionAws(c.endpoint); er != nil {
|
||||
err.AddParentError(er)
|
||||
err.Add(er)
|
||||
}
|
||||
} else if !err.HasParent() && c.endpoint != nil && c.Endpoint == "" {
|
||||
c.Endpoint = c.endpoint.String()
|
||||
@@ -88,7 +87,7 @@ func (c *awsModel) Validate() liberr.Error {
|
||||
|
||||
if !err.HasParent() && c.endpoint != nil && c.Region != "" {
|
||||
if e := c.RegisterRegionEndpoint("", c.endpoint); e != nil {
|
||||
err.AddParentError(e)
|
||||
err.Add(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,13 +111,13 @@ func (c *awsModel) ResetRegionEndpoint() {
|
||||
c.mapRegion = make(map[string]*url.URL)
|
||||
}
|
||||
|
||||
func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error {
|
||||
func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) error {
|
||||
if endpoint == nil && c.endpoint != nil {
|
||||
endpoint = c.endpoint
|
||||
} else if endpoint == nil && c.Endpoint != "" {
|
||||
var err error
|
||||
if endpoint, err = url.Parse(c.Endpoint); err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,9 +132,9 @@ func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) libe
|
||||
val := libval.New()
|
||||
|
||||
if err := val.Var(endpoint, "url,required"); err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
} else if err := val.Var(region, "printascii,required"); err != nil {
|
||||
return ErrorRegionInvalid.ErrorParent(err)
|
||||
return ErrorRegionInvalid.Error(err)
|
||||
}
|
||||
|
||||
if c.mapRegion == nil {
|
||||
@@ -147,13 +146,13 @@ func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) libe
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *awsModel) RegisterRegionAws(endpoint *url.URL) liberr.Error {
|
||||
func (c *awsModel) RegisterRegionAws(endpoint *url.URL) error {
|
||||
if endpoint == nil && c.endpoint != nil {
|
||||
endpoint = c.endpoint
|
||||
} else if endpoint == nil && c.Endpoint != "" {
|
||||
var err error
|
||||
if endpoint, err = url.Parse(c.Endpoint); err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +162,7 @@ func (c *awsModel) RegisterRegionAws(endpoint *url.URL) liberr.Error {
|
||||
|
||||
val := libval.New()
|
||||
if err := val.Var(endpoint, "url,required"); err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
}
|
||||
|
||||
if c.Region == "" {
|
||||
@@ -264,12 +263,12 @@ func (c *awsModel) SetRetryer(retryer func() sdkaws.Retryer) {
|
||||
c.retryer = retryer
|
||||
}
|
||||
|
||||
func (c *awsModel) Check(ctx context.Context) liberr.Error {
|
||||
func (c *awsModel) Check(ctx context.Context) error {
|
||||
var (
|
||||
cfg *sdkaws.Config
|
||||
con net.Conn
|
||||
err error
|
||||
e liberr.Error
|
||||
e error
|
||||
)
|
||||
|
||||
if cfg, e = c.GetConfig(ctx, nil); e != nil {
|
||||
@@ -281,11 +280,11 @@ func (c *awsModel) Check(ctx context.Context) liberr.Error {
|
||||
}
|
||||
|
||||
if _, err = cfg.EndpointResolverWithOptions.ResolveEndpoint("s3", c.GetRegion()); err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
}
|
||||
|
||||
if _, err = cfg.Credentials.Retrieve(ctx); err != nil {
|
||||
return ErrorCredentialsInvalid.ErrorParent(err)
|
||||
return ErrorCredentialsInvalid.Error(err)
|
||||
}
|
||||
|
||||
d := net.Dialer{
|
||||
@@ -308,7 +307,7 @@ func (c *awsModel) Check(ctx context.Context) liberr.Error {
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
return ErrorEndpointInvalid.ErrorParent(err)
|
||||
return ErrorEndpointInvalid.Error(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -26,13 +26,12 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
"github.com/nabbar/golib/errors"
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
)
|
||||
|
||||
func (cli *client) List() (map[string]string, errors.Error) {
|
||||
if out, err := cli.iam.ListGroups(cli.GetContext(), &iam.ListGroupsInput{}); err != nil {
|
||||
func (cli *client) List() (map[string]string, error) {
|
||||
if out, err := cli.iam.ListGroups(cli.GetContext(), &sdkiam.ListGroupsInput{}); err != nil {
|
||||
return nil, cli.GetError(err)
|
||||
} else {
|
||||
var res = make(map[string]string)
|
||||
@@ -45,17 +44,17 @@ func (cli *client) List() (map[string]string, errors.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Add(groupName string) errors.Error {
|
||||
_, err := cli.iam.CreateGroup(cli.GetContext(), &iam.CreateGroupInput{
|
||||
GroupName: aws.String(groupName),
|
||||
func (cli *client) Add(groupName string) error {
|
||||
_, err := cli.iam.CreateGroup(cli.GetContext(), &sdkiam.CreateGroupInput{
|
||||
GroupName: sdkaws.String(groupName),
|
||||
})
|
||||
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) Remove(groupName string) errors.Error {
|
||||
_, err := cli.iam.DeleteGroup(cli.GetContext(), &iam.DeleteGroupInput{
|
||||
GroupName: aws.String(groupName),
|
||||
func (cli *client) Remove(groupName string) error {
|
||||
_, err := cli.iam.DeleteGroup(cli.GetContext(), &sdkiam.DeleteGroupInput{
|
||||
GroupName: sdkaws.String(groupName),
|
||||
})
|
||||
|
||||
return cli.GetError(err)
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
awshlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
@@ -41,23 +40,23 @@ type client struct {
|
||||
s3 *sdksss.Client
|
||||
}
|
||||
|
||||
type PoliciesWalkFunc func(err liberr.Error, pol sdktps.AttachedPolicy) liberr.Error
|
||||
type PoliciesWalkFunc func(err error, pol sdktps.AttachedPolicy) error
|
||||
|
||||
type Group interface {
|
||||
UserList(username string) ([]string, liberr.Error)
|
||||
UserCheck(username, groupName string) (liberr.Error, bool)
|
||||
UserAdd(username, groupName string) liberr.Error
|
||||
UserRemove(username, groupName string) liberr.Error
|
||||
UserList(username string) ([]string, error)
|
||||
UserCheck(username, groupName string) (error, bool)
|
||||
UserAdd(username, groupName string) error
|
||||
UserRemove(username, groupName string) error
|
||||
|
||||
List() (map[string]string, liberr.Error)
|
||||
Add(groupName string) liberr.Error
|
||||
Remove(groupName string) liberr.Error
|
||||
List() (map[string]string, error)
|
||||
Add(groupName string) error
|
||||
Remove(groupName string) error
|
||||
|
||||
PolicyList(groupName string) (map[string]string, liberr.Error)
|
||||
PolicyAttach(groupName, polArn string) liberr.Error
|
||||
PolicyDetach(groupName, polArn string) liberr.Error
|
||||
PolicyAttachedList(groupName, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error)
|
||||
PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) liberr.Error
|
||||
PolicyList(groupName string) (map[string]string, error)
|
||||
PolicyAttach(groupName, polArn string) error
|
||||
PolicyDetach(groupName, polArn string) error
|
||||
PolicyAttachedList(groupName, marker string) ([]sdktps.AttachedPolicy, string, error)
|
||||
PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) error
|
||||
}
|
||||
|
||||
func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Group {
|
||||
|
@@ -29,10 +29,9 @@ import (
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) PolicyList(groupName string) (map[string]string, liberr.Error) {
|
||||
func (cli *client) PolicyList(groupName string) (map[string]string, error) {
|
||||
out, _, err := cli.PolicyAttachedList(groupName, "")
|
||||
|
||||
if err != nil {
|
||||
@@ -48,7 +47,7 @@ func (cli *client) PolicyList(groupName string) (map[string]string, liberr.Error
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttach(groupName, polArn string) liberr.Error {
|
||||
func (cli *client) PolicyAttach(groupName, polArn string) error {
|
||||
_, err := cli.iam.AttachGroupPolicy(cli.GetContext(), &sdkiam.AttachGroupPolicyInput{
|
||||
GroupName: sdkaws.String(groupName),
|
||||
PolicyArn: sdkaws.String(polArn),
|
||||
@@ -57,7 +56,7 @@ func (cli *client) PolicyAttach(groupName, polArn string) liberr.Error {
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) PolicyDetach(groupName, polArn string) liberr.Error {
|
||||
func (cli *client) PolicyDetach(groupName, polArn string) error {
|
||||
_, err := cli.iam.DetachGroupPolicy(cli.GetContext(), &sdkiam.DetachGroupPolicyInput{
|
||||
GroupName: sdkaws.String(groupName),
|
||||
PolicyArn: sdkaws.String(polArn),
|
||||
@@ -66,7 +65,7 @@ func (cli *client) PolicyDetach(groupName, polArn string) liberr.Error {
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttachedList(groupName, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) {
|
||||
func (cli *client) PolicyAttachedList(groupName, marker string) ([]sdktps.AttachedPolicy, string, error) {
|
||||
in := &sdkiam.ListAttachedGroupPoliciesInput{
|
||||
GroupName: sdkaws.String(groupName),
|
||||
MaxItems: sdkaws.Int32(1000),
|
||||
@@ -89,7 +88,7 @@ func (cli *client) PolicyAttachedList(groupName, marker string) ([]sdktps.Attach
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) liberr.Error {
|
||||
func (cli *client) PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) error {
|
||||
var m *string
|
||||
|
||||
in := &sdkiam.ListAttachedGroupPoliciesInput{
|
||||
@@ -112,7 +111,7 @@ func (cli *client) PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) li
|
||||
return nil
|
||||
}
|
||||
|
||||
var e liberr.Error
|
||||
var e error
|
||||
for _, p := range lst.AttachedPolicies {
|
||||
e = fct(e, p)
|
||||
}
|
||||
|
@@ -26,14 +26,13 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
"github.com/nabbar/golib/errors"
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
)
|
||||
|
||||
func (cli *client) UserCheck(username, groupName string) (errors.Error, bool) {
|
||||
out, err := cli.iam.ListGroupsForUser(cli.GetContext(), &iam.ListGroupsForUserInput{
|
||||
UserName: aws.String(username),
|
||||
func (cli *client) UserCheck(username, groupName string) (error, bool) {
|
||||
out, err := cli.iam.ListGroupsForUser(cli.GetContext(), &sdkiam.ListGroupsForUserInput{
|
||||
UserName: sdkaws.String(username),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -49,9 +48,9 @@ func (cli *client) UserCheck(username, groupName string) (errors.Error, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (cli *client) UserList(username string) ([]string, errors.Error) {
|
||||
out, err := cli.iam.ListGroupsForUser(cli.GetContext(), &iam.ListGroupsForUserInput{
|
||||
UserName: aws.String(username),
|
||||
func (cli *client) UserList(username string) ([]string, error) {
|
||||
out, err := cli.iam.ListGroupsForUser(cli.GetContext(), &sdkiam.ListGroupsForUserInput{
|
||||
UserName: sdkaws.String(username),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -67,19 +66,19 @@ func (cli *client) UserList(username string) ([]string, errors.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) UserAdd(username, groupName string) errors.Error {
|
||||
_, err := cli.iam.AddUserToGroup(cli.GetContext(), &iam.AddUserToGroupInput{
|
||||
UserName: aws.String(username),
|
||||
GroupName: aws.String(groupName),
|
||||
func (cli *client) UserAdd(username, groupName string) error {
|
||||
_, err := cli.iam.AddUserToGroup(cli.GetContext(), &sdkiam.AddUserToGroupInput{
|
||||
UserName: sdkaws.String(username),
|
||||
GroupName: sdkaws.String(groupName),
|
||||
})
|
||||
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) UserRemove(username, groupName string) errors.Error {
|
||||
_, err := cli.iam.RemoveUserFromGroup(cli.GetContext(), &iam.RemoveUserFromGroupInput{
|
||||
UserName: aws.String(username),
|
||||
GroupName: aws.String(groupName),
|
||||
func (cli *client) UserRemove(username, groupName string) error {
|
||||
_, err := cli.iam.RemoveUserFromGroup(cli.GetContext(), &sdkiam.RemoveUserFromGroupInput{
|
||||
UserName: sdkaws.String(username),
|
||||
GroupName: sdkaws.String(groupName),
|
||||
})
|
||||
|
||||
return cli.GetError(err)
|
||||
|
@@ -41,8 +41,6 @@ const (
|
||||
ErrorParamsEmpty
|
||||
)
|
||||
|
||||
var isErrInit = liberr.ExistInMapMessage(ErrorResponse)
|
||||
|
||||
func init() {
|
||||
if liberr.ExistInMapMessage(ErrorResponse) {
|
||||
panic(fmt.Errorf("error code collision with package golib/aws/helpers"))
|
||||
@@ -50,10 +48,6 @@ func init() {
|
||||
liberr.RegisterIdFctMessage(ErrorResponse, getMessage)
|
||||
}
|
||||
|
||||
func IsErrorInit() bool {
|
||||
return isErrInit
|
||||
}
|
||||
|
||||
func getMessage(code liberr.CodeError) string {
|
||||
switch code {
|
||||
case ErrorResponse:
|
||||
|
@@ -31,7 +31,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -53,24 +52,12 @@ func New(ctx context.Context, bucket, region string) Helper {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli Helper) GetError(err ...error) liberr.Error {
|
||||
var er = ErrorAws.Error(nil)
|
||||
|
||||
for _, e := range err {
|
||||
if e == nil {
|
||||
continue
|
||||
}
|
||||
if n, ok := e.(liberr.Error); ok {
|
||||
er.AddParentError(n)
|
||||
} else {
|
||||
er.AddParent(e)
|
||||
}
|
||||
func (cli Helper) GetError(err ...error) error {
|
||||
var e = ErrorAws.Error()
|
||||
e.Add(err...)
|
||||
if e.HasParent() {
|
||||
return e
|
||||
}
|
||||
|
||||
if er.HasParent() {
|
||||
return er
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -42,18 +42,17 @@ import (
|
||||
awspol "github.com/nabbar/golib/aws/policy"
|
||||
awsrol "github.com/nabbar/golib/aws/role"
|
||||
awsusr "github.com/nabbar/golib/aws/user"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type Config interface {
|
||||
Check(ctx context.Context) liberr.Error
|
||||
Validate() liberr.Error
|
||||
Check(ctx context.Context) error
|
||||
Validate() error
|
||||
|
||||
GetAccessKey() string
|
||||
SetCredentials(accessKey, secretKey string)
|
||||
ResetRegionEndpoint()
|
||||
RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error
|
||||
RegisterRegionAws(endpoint *url.URL) liberr.Error
|
||||
RegisterRegionEndpoint(region string, endpoint *url.URL) error
|
||||
RegisterRegionAws(endpoint *url.URL) error
|
||||
SetRegion(region string)
|
||||
GetRegion() string
|
||||
SetEndpoint(endpoint *url.URL)
|
||||
@@ -66,7 +65,7 @@ type Config interface {
|
||||
GetResolvedRegion() string
|
||||
SetRetryer(retryer func() sdkaws.Retryer)
|
||||
|
||||
GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, liberr.Error)
|
||||
GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, error)
|
||||
JSON() ([]byte, error)
|
||||
Clone() Config
|
||||
|
||||
@@ -84,10 +83,10 @@ type AWS interface {
|
||||
|
||||
Config() Config
|
||||
HTTPCli() *http.Client
|
||||
Clone(ctx context.Context) (AWS, liberr.Error)
|
||||
NewForConfig(ctx context.Context, cfg Config) (AWS, liberr.Error)
|
||||
ForcePathStyle(ctx context.Context, enabled bool) liberr.Error
|
||||
ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) liberr.Error
|
||||
Clone(ctx context.Context) (AWS, error)
|
||||
NewForConfig(ctx context.Context, cfg Config) (AWS, error)
|
||||
ForcePathStyle(ctx context.Context, enabled bool) error
|
||||
ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) error
|
||||
|
||||
GetBucketName() string
|
||||
SetBucketName(bucket string)
|
||||
@@ -98,7 +97,7 @@ type AWS interface {
|
||||
SetClientIam(aws *sdkiam.Client)
|
||||
}
|
||||
|
||||
func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, liberr.Error) {
|
||||
func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, error) {
|
||||
if cfg == nil {
|
||||
return nil, awshlp.ErrorConfigEmpty.Error(nil)
|
||||
}
|
||||
|
17
aws/model.go
17
aws/model.go
@@ -40,7 +40,6 @@ import (
|
||||
awspol "github.com/nabbar/golib/aws/policy"
|
||||
awsrol "github.com/nabbar/golib/aws/role"
|
||||
awsusr "github.com/nabbar/golib/aws/user"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
@@ -54,11 +53,11 @@ type client struct {
|
||||
h *http.Client
|
||||
}
|
||||
|
||||
func (c *client) _NewClientIAM(ctx context.Context, httpClient *http.Client) (*sdkiam.Client, liberr.Error) {
|
||||
func (c *client) _NewClientIAM(ctx context.Context, httpClient *http.Client) (*sdkiam.Client, error) {
|
||||
var (
|
||||
cfg *sdkaws.Config
|
||||
iam *sdkiam.Client
|
||||
err liberr.Error
|
||||
err error
|
||||
ret sdkaws.Retryer
|
||||
sig *sdksv4.Signer
|
||||
)
|
||||
@@ -97,10 +96,10 @@ func (c *client) _NewClientIAM(ctx context.Context, httpClient *http.Client) (*s
|
||||
return iam, nil
|
||||
}
|
||||
|
||||
func (c *client) _NewClientS3(ctx context.Context, httpClient *http.Client) (*sdksss.Client, liberr.Error) {
|
||||
func (c *client) _NewClientS3(ctx context.Context, httpClient *http.Client) (*sdksss.Client, error) {
|
||||
var (
|
||||
sss *sdksss.Client
|
||||
err liberr.Error
|
||||
err error
|
||||
ret sdkaws.Retryer
|
||||
cfg *sdkaws.Config
|
||||
sig *sdksv4.Signer
|
||||
@@ -141,7 +140,7 @@ func (c *client) _NewClientS3(ctx context.Context, httpClient *http.Client) (*sd
|
||||
return sss, nil
|
||||
}
|
||||
|
||||
func (c *client) NewForConfig(ctx context.Context, cfg Config) (AWS, liberr.Error) {
|
||||
func (c *client) NewForConfig(ctx context.Context, cfg Config) (AWS, error) {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
|
||||
@@ -171,7 +170,7 @@ func (c *client) NewForConfig(ctx context.Context, cfg Config) (AWS, liberr.Erro
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (c *client) Clone(ctx context.Context) (AWS, liberr.Error) {
|
||||
func (c *client) Clone(ctx context.Context) (AWS, error) {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
|
||||
@@ -205,7 +204,7 @@ func (c *client) Clone(ctx context.Context) (AWS, liberr.Error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (c *client) ForcePathStyle(ctx context.Context, enabled bool) liberr.Error {
|
||||
func (c *client) ForcePathStyle(ctx context.Context, enabled bool) error {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
|
||||
@@ -220,7 +219,7 @@ func (c *client) ForcePathStyle(ctx context.Context, enabled bool) liberr.Error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) liberr.Error {
|
||||
func (c *client) ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) error {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
|
||||
|
@@ -27,11 +27,9 @@ package object
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) Find(regex string) ([]string, liberr.Error) {
|
||||
func (cli *client) Find(regex string) ([]string, error) {
|
||||
var (
|
||||
result = make([]string, 0)
|
||||
token = ""
|
||||
|
@@ -38,7 +38,6 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
@@ -47,52 +46,52 @@ type client struct {
|
||||
s3 *sdksss.Client
|
||||
}
|
||||
|
||||
type WalkFunc func(err liberr.Error, obj sdktps.Object) liberr.Error
|
||||
type VersionWalkFunc func(err liberr.Error, obj sdktps.ObjectVersion) liberr.Error
|
||||
type DelMakWalkFunc func(err liberr.Error, del sdktps.DeleteMarkerEntry) liberr.Error
|
||||
type WalkFunc func(err error, obj sdktps.Object) error
|
||||
type VersionWalkFunc func(err error, obj sdktps.ObjectVersion) error
|
||||
type DelMakWalkFunc func(err error, del sdktps.DeleteMarkerEntry) error
|
||||
|
||||
type Object interface {
|
||||
Find(regex string) ([]string, liberr.Error)
|
||||
Size(object string) (size int64, err liberr.Error)
|
||||
Find(regex string) ([]string, error)
|
||||
Size(object string) (size int64, err error)
|
||||
|
||||
List(continuationToken string) ([]sdktps.Object, string, int64, liberr.Error)
|
||||
Walk(f WalkFunc) liberr.Error
|
||||
List(continuationToken string) ([]sdktps.Object, string, int64, error)
|
||||
Walk(f WalkFunc) error
|
||||
|
||||
ListPrefix(continuationToken string, prefix string) ([]sdktps.Object, string, int64, liberr.Error)
|
||||
WalkPrefix(prefix string, f WalkFunc) liberr.Error
|
||||
ListPrefix(continuationToken string, prefix string) ([]sdktps.Object, string, int64, error)
|
||||
WalkPrefix(prefix string, f WalkFunc) error
|
||||
|
||||
Head(object string) (*sdksss.HeadObjectOutput, liberr.Error)
|
||||
Get(object string) (*sdksss.GetObjectOutput, liberr.Error)
|
||||
Put(object string, body io.Reader) liberr.Error
|
||||
Delete(check bool, object string) liberr.Error
|
||||
DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, liberr.Error)
|
||||
GetAttributes(object, version string) (*sdksss.GetObjectAttributesOutput, liberr.Error)
|
||||
Head(object string) (*sdksss.HeadObjectOutput, error)
|
||||
Get(object string) (*sdksss.GetObjectOutput, error)
|
||||
Put(object string, body io.Reader) error
|
||||
Delete(check bool, object string) error
|
||||
DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, error)
|
||||
GetAttributes(object, version string) (*sdksss.GetObjectAttributesOutput, error)
|
||||
|
||||
MultipartList(keyMarker, markerId string) (uploads []sdktps.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e liberr.Error)
|
||||
MultipartList(keyMarker, markerId string) (uploads []sdktps.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e error)
|
||||
MultipartNew(partSize libsiz.Size, object string) libmpu.MultiPart
|
||||
MultipartPut(object string, body io.Reader) liberr.Error
|
||||
MultipartPutCustom(partSize libsiz.Size, object string, body io.Reader) liberr.Error
|
||||
MultipartCancel(uploadId, key string) liberr.Error
|
||||
MultipartPut(object string, body io.Reader) error
|
||||
MultipartPutCustom(partSize libsiz.Size, object string, body io.Reader) error
|
||||
MultipartCancel(uploadId, key string) error
|
||||
|
||||
UpdateMetadata(meta *sdksss.CopyObjectInput) liberr.Error
|
||||
SetWebsite(object, redirect string) liberr.Error
|
||||
UpdateMetadata(meta *sdksss.CopyObjectInput) error
|
||||
SetWebsite(object, redirect string) error
|
||||
|
||||
VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err liberr.Error)
|
||||
VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) liberr.Error
|
||||
VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) liberr.Error
|
||||
VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err error)
|
||||
VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) error
|
||||
VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) error
|
||||
|
||||
VersionGet(object, version string) (*sdksss.GetObjectOutput, liberr.Error)
|
||||
VersionHead(object, version string) (*sdksss.HeadObjectOutput, liberr.Error)
|
||||
VersionSize(object, version string) (size int64, err liberr.Error)
|
||||
VersionDelete(check bool, object, version string) liberr.Error
|
||||
VersionGet(object, version string) (*sdksss.GetObjectOutput, error)
|
||||
VersionHead(object, version string) (*sdksss.HeadObjectOutput, error)
|
||||
VersionSize(object, version string) (size int64, err error)
|
||||
VersionDelete(check bool, object, version string) error
|
||||
|
||||
GetRetention(object, version string) (until time.Time, mode string, err liberr.Error)
|
||||
SetRetention(object, version string, bypass bool, until time.Time, mode string) liberr.Error
|
||||
GetLegalHold(object, version string) (sdktps.ObjectLockLegalHoldStatus, liberr.Error)
|
||||
SetLegalHold(object, version string, flag sdktps.ObjectLockLegalHoldStatus) liberr.Error
|
||||
GetRetention(object, version string) (until time.Time, mode string, err error)
|
||||
SetRetention(object, version string, bypass bool, until time.Time, mode string) error
|
||||
GetLegalHold(object, version string) (sdktps.ObjectLockLegalHoldStatus, error)
|
||||
SetLegalHold(object, version string, flag sdktps.ObjectLockLegalHoldStatus) error
|
||||
|
||||
GetTags(object, version string) ([]sdktps.Tag, liberr.Error)
|
||||
SetTags(object, version string, tags ...sdktps.Tag) liberr.Error
|
||||
GetTags(object, version string) ([]sdktps.Tag, error)
|
||||
SetTags(object, version string, tags ...sdktps.Tag) error
|
||||
}
|
||||
|
||||
func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Object {
|
||||
|
@@ -32,10 +32,9 @@ import (
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) GetRetention(object, version string) (until time.Time, mode string, err liberr.Error) {
|
||||
func (cli *client) GetRetention(object, version string) (until time.Time, mode string, err error) {
|
||||
until = time.Time{}
|
||||
mode = ""
|
||||
|
||||
@@ -66,7 +65,7 @@ func (cli *client) GetRetention(object, version string) (until time.Time, mode s
|
||||
return until, mode, nil
|
||||
}
|
||||
|
||||
func (cli *client) SetRetention(object, version string, bypass bool, until time.Time, mode string) liberr.Error {
|
||||
func (cli *client) SetRetention(object, version string, bypass bool, until time.Time, mode string) error {
|
||||
in := sdksss.PutObjectRetentionInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Key: sdkaws.String(object),
|
||||
@@ -99,7 +98,7 @@ func (cli *client) SetRetention(object, version string, bypass bool, until time.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) GetLegalHold(object, version string) (sdktps.ObjectLockLegalHoldStatus, liberr.Error) {
|
||||
func (cli *client) GetLegalHold(object, version string) (sdktps.ObjectLockLegalHoldStatus, error) {
|
||||
in := sdksss.GetObjectLegalHoldInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Key: sdkaws.String(object),
|
||||
@@ -118,7 +117,7 @@ func (cli *client) GetLegalHold(object, version string) (sdktps.ObjectLockLegalH
|
||||
return out.LegalHold.Status, nil
|
||||
}
|
||||
|
||||
func (cli *client) SetLegalHold(object, version string, flag sdktps.ObjectLockLegalHoldStatus) liberr.Error {
|
||||
func (cli *client) SetLegalHold(object, version string, flag sdktps.ObjectLockLegalHoldStatus) error {
|
||||
in := sdksss.PutObjectLegalHoldInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Key: sdkaws.String(object),
|
||||
|
@@ -33,13 +33,12 @@ import (
|
||||
sdktyp "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
libmpu "github.com/nabbar/golib/aws/multipart"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libsiz "github.com/nabbar/golib/size"
|
||||
)
|
||||
|
||||
// MultipartList implement the ListMultipartUploads.
|
||||
// See docs for more infos : https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html
|
||||
func (cli *client) MultipartList(keyMarker, markerId string) (uploads []sdktyp.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e liberr.Error) {
|
||||
func (cli *client) MultipartList(keyMarker, markerId string) (uploads []sdktyp.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e error) {
|
||||
in := &sdksss.ListMultipartUploadsInput{
|
||||
Bucket: sdkaws.String(cli.GetBucketName()),
|
||||
MaxUploads: 1000,
|
||||
@@ -71,11 +70,11 @@ func (cli *client) MultipartNew(partSize libsiz.Size, object string) libmpu.Mult
|
||||
return m
|
||||
}
|
||||
|
||||
func (cli *client) MultipartPut(object string, body io.Reader) liberr.Error {
|
||||
func (cli *client) MultipartPut(object string, body io.Reader) error {
|
||||
return cli.MultipartPutCustom(libmpu.DefaultPartSize, object, body)
|
||||
}
|
||||
|
||||
func (cli *client) MultipartPutCustom(partSize libsiz.Size, object string, body io.Reader) liberr.Error {
|
||||
func (cli *client) MultipartPutCustom(partSize libsiz.Size, object string, body io.Reader) error {
|
||||
var (
|
||||
e error
|
||||
m = cli.MultipartNew(partSize, object)
|
||||
@@ -100,7 +99,7 @@ func (cli *client) MultipartPutCustom(partSize libsiz.Size, object string, body
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) MultipartCancel(uploadId, key string) liberr.Error {
|
||||
func (cli *client) MultipartCancel(uploadId, key string) error {
|
||||
res, err := cli.s3.AbortMultipartUpload(cli.GetContext(), &sdksss.AbortMultipartUploadInput{
|
||||
Bucket: sdkaws.String(cli.GetBucketName()),
|
||||
UploadId: sdkaws.String(uploadId),
|
||||
|
@@ -35,14 +35,13 @@ import (
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) List(continuationToken string) ([]sdktps.Object, string, int64, liberr.Error) {
|
||||
func (cli *client) List(continuationToken string) ([]sdktps.Object, string, int64, error) {
|
||||
return cli.ListPrefix(continuationToken, "")
|
||||
}
|
||||
|
||||
func (cli *client) ListPrefix(continuationToken string, prefix string) ([]sdktps.Object, string, int64, liberr.Error) {
|
||||
func (cli *client) ListPrefix(continuationToken string, prefix string) ([]sdktps.Object, string, int64, error) {
|
||||
in := sdksss.ListObjectsV2Input{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
}
|
||||
@@ -66,11 +65,11 @@ func (cli *client) ListPrefix(continuationToken string, prefix string) ([]sdktps
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Walk(f WalkFunc) liberr.Error {
|
||||
func (cli *client) Walk(f WalkFunc) error {
|
||||
return cli.WalkPrefix("", f)
|
||||
}
|
||||
|
||||
func (cli *client) WalkPrefix(prefix string, f WalkFunc) liberr.Error {
|
||||
func (cli *client) WalkPrefix(prefix string, f WalkFunc) error {
|
||||
in := sdksss.ListObjectsV2Input{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
}
|
||||
@@ -80,7 +79,7 @@ func (cli *client) WalkPrefix(prefix string, f WalkFunc) liberr.Error {
|
||||
}
|
||||
|
||||
var (
|
||||
e liberr.Error
|
||||
e error
|
||||
t = sdkaws.String("")
|
||||
)
|
||||
|
||||
@@ -113,23 +112,23 @@ func (cli *client) WalkPrefix(prefix string, f WalkFunc) liberr.Error {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Get(object string) (*sdksss.GetObjectOutput, liberr.Error) {
|
||||
func (cli *client) Get(object string) (*sdksss.GetObjectOutput, error) {
|
||||
return cli.VersionGet(object, "")
|
||||
}
|
||||
|
||||
func (cli *client) Head(object string) (*sdksss.HeadObjectOutput, liberr.Error) {
|
||||
func (cli *client) Head(object string) (*sdksss.HeadObjectOutput, error) {
|
||||
return cli.VersionHead(object, "")
|
||||
}
|
||||
|
||||
func (cli *client) Size(object string) (size int64, err liberr.Error) {
|
||||
func (cli *client) Size(object string) (size int64, err error) {
|
||||
return cli.VersionSize(object, "")
|
||||
}
|
||||
|
||||
func (cli *client) Delete(check bool, object string) liberr.Error {
|
||||
func (cli *client) Delete(check bool, object string) error {
|
||||
return cli.VersionDelete(check, object, "")
|
||||
}
|
||||
|
||||
func (cli *client) Put(object string, body io.Reader) liberr.Error {
|
||||
func (cli *client) Put(object string, body io.Reader) error {
|
||||
var tpe *string
|
||||
|
||||
if t := mime.TypeByExtension(filepath.Ext(object)); t == "" {
|
||||
@@ -154,7 +153,7 @@ func (cli *client) Put(object string, body io.Reader) liberr.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, liberr.Error) {
|
||||
func (cli *client) DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, error) {
|
||||
in := sdksss.DeleteObjectsInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Delete: objects,
|
||||
@@ -171,7 +170,7 @@ func (cli *client) DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, li
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) GetAttributes(object, version string) (*sdksss.GetObjectAttributesOutput, liberr.Error) {
|
||||
func (cli *client) GetAttributes(object, version string) (*sdksss.GetObjectAttributesOutput, error) {
|
||||
in := sdksss.GetObjectAttributesInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Key: sdkaws.String(object),
|
||||
|
@@ -29,10 +29,9 @@ import (
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) GetTags(object, version string) ([]sdktps.Tag, liberr.Error) {
|
||||
func (cli *client) GetTags(object, version string) ([]sdktps.Tag, error) {
|
||||
in := sdksss.GetObjectTaggingInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Key: sdkaws.String(object),
|
||||
@@ -51,7 +50,7 @@ func (cli *client) GetTags(object, version string) ([]sdktps.Tag, liberr.Error)
|
||||
return out.TagSet, nil
|
||||
}
|
||||
|
||||
func (cli *client) SetTags(object, version string, tags ...sdktps.Tag) liberr.Error {
|
||||
func (cli *client) SetTags(object, version string, tags ...sdktps.Tag) error {
|
||||
in := sdksss.PutObjectTaggingInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Key: sdkaws.String(object),
|
||||
|
@@ -32,10 +32,9 @@ import (
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err liberr.Error) {
|
||||
func (cli *client) VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err error) {
|
||||
in := sdksss.ListObjectVersionsInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
MaxKeys: 1000,
|
||||
@@ -61,11 +60,11 @@ func (cli *client) VersionList(prefix, keyMarker, markerId string) (version []sd
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) liberr.Error {
|
||||
func (cli *client) VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) error {
|
||||
return cli.VersionWalkPrefix("", fv, fd)
|
||||
}
|
||||
|
||||
func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) liberr.Error {
|
||||
func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) error {
|
||||
in := sdksss.ListObjectVersionsInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
MaxKeys: 1000,
|
||||
@@ -76,7 +75,7 @@ func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMa
|
||||
}
|
||||
|
||||
var (
|
||||
e liberr.Error
|
||||
e error
|
||||
km = sdkaws.String("")
|
||||
mi = sdkaws.String("")
|
||||
)
|
||||
@@ -126,7 +125,7 @@ func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMa
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) VersionGet(object, version string) (*sdksss.GetObjectOutput, liberr.Error) {
|
||||
func (cli *client) VersionGet(object, version string) (*sdksss.GetObjectOutput, error) {
|
||||
in := sdksss.GetObjectInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Key: sdkaws.String(object),
|
||||
@@ -153,7 +152,7 @@ func (cli *client) VersionGet(object, version string) (*sdksss.GetObjectOutput,
|
||||
|
||||
}
|
||||
|
||||
func (cli *client) VersionHead(object, version string) (*sdksss.HeadObjectOutput, liberr.Error) {
|
||||
func (cli *client) VersionHead(object, version string) (*sdksss.HeadObjectOutput, error) {
|
||||
in := sdksss.HeadObjectInput{
|
||||
Bucket: cli.GetBucketAws(),
|
||||
Key: sdkaws.String(object),
|
||||
@@ -174,7 +173,7 @@ func (cli *client) VersionHead(object, version string) (*sdksss.HeadObjectOutput
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) VersionSize(object, version string) (size int64, err liberr.Error) {
|
||||
func (cli *client) VersionSize(object, version string) (size int64, err error) {
|
||||
var (
|
||||
h *sdksss.HeadObjectOutput
|
||||
)
|
||||
@@ -186,7 +185,7 @@ func (cli *client) VersionSize(object, version string) (size int64, err liberr.E
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) VersionDelete(check bool, object, version string) liberr.Error {
|
||||
func (cli *client) VersionDelete(check bool, object, version string) error {
|
||||
if check {
|
||||
if _, err := cli.VersionHead(object, version); err != nil {
|
||||
return err
|
||||
|
@@ -29,16 +29,15 @@ import (
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) UpdateMetadata(meta *sdksss.CopyObjectInput) liberr.Error {
|
||||
func (cli *client) UpdateMetadata(meta *sdksss.CopyObjectInput) error {
|
||||
_, err := cli.s3.CopyObject(cli.GetContext(), meta)
|
||||
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) SetWebsite(object, redirect string) liberr.Error {
|
||||
func (cli *client) SetWebsite(object, redirect string) error {
|
||||
var err error
|
||||
|
||||
_, err = cli.s3.PutObjectAcl(cli.GetContext(), &sdksss.PutObjectAclInput{
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
@@ -42,19 +41,19 @@ type client struct {
|
||||
}
|
||||
|
||||
type Policy interface {
|
||||
List() (map[string]string, liberr.Error)
|
||||
List() (map[string]string, error)
|
||||
|
||||
Get(arn string) (*types.Policy, liberr.Error)
|
||||
Add(name, desc, policy string) (string, liberr.Error)
|
||||
Update(polArn, polContents string) liberr.Error
|
||||
Delete(polArn string) liberr.Error
|
||||
Get(arn string) (*types.Policy, error)
|
||||
Add(name, desc, policy string) (string, error)
|
||||
Update(polArn, polContents string) error
|
||||
Delete(polArn string) error
|
||||
|
||||
VersionList(arn string, maxItem int32, noDefaultVersion bool) (map[string]string, liberr.Error)
|
||||
VersionGet(arn string, vers string) (*types.PolicyVersion, liberr.Error)
|
||||
VersionAdd(arn string, doc string) liberr.Error
|
||||
VersionDel(arn string, vers string) liberr.Error
|
||||
VersionList(arn string, maxItem int32, noDefaultVersion bool) (map[string]string, error)
|
||||
VersionGet(arn string, vers string) (*types.PolicyVersion, error)
|
||||
VersionAdd(arn string, doc string) error
|
||||
VersionDel(arn string, vers string) error
|
||||
|
||||
CompareUpdate(arn string, doc string) (upd bool, err liberr.Error)
|
||||
CompareUpdate(arn string, doc string) (upd bool, err error)
|
||||
}
|
||||
|
||||
func New(ctx context.Context, bucket, region string, iam *iam.Client, s3 *s3.Client) Policy {
|
||||
|
@@ -30,10 +30,9 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) List() (map[string]string, liberr.Error) {
|
||||
func (cli *client) List() (map[string]string, error) {
|
||||
out, err := cli.iam.ListPolicies(cli.GetContext(), &iam.ListPoliciesInput{})
|
||||
|
||||
if err != nil {
|
||||
@@ -49,7 +48,7 @@ func (cli *client) List() (map[string]string, liberr.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Get(arn string) (*types.Policy, liberr.Error) {
|
||||
func (cli *client) Get(arn string) (*types.Policy, error) {
|
||||
out, err := cli.iam.GetPolicy(cli.GetContext(), &iam.GetPolicyInput{
|
||||
PolicyArn: aws.String(arn),
|
||||
})
|
||||
@@ -63,7 +62,7 @@ func (cli *client) Get(arn string) (*types.Policy, liberr.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Add(name, desc, policy string) (string, liberr.Error) {
|
||||
func (cli *client) Add(name, desc, policy string) (string, error) {
|
||||
out, err := cli.iam.CreatePolicy(cli.GetContext(), &iam.CreatePolicyInput{
|
||||
PolicyName: aws.String(name),
|
||||
Description: aws.String(desc),
|
||||
@@ -77,11 +76,11 @@ func (cli *client) Add(name, desc, policy string) (string, liberr.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Update(polArn, polContents string) liberr.Error {
|
||||
func (cli *client) Update(polArn, polContents string) error {
|
||||
var (
|
||||
pol *types.Policy
|
||||
lst map[string]string
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if pol, err = cli.Get(polArn); err != nil {
|
||||
@@ -105,7 +104,7 @@ func (cli *client) Update(polArn, polContents string) liberr.Error {
|
||||
return cli.VersionAdd(polArn, polContents)
|
||||
}
|
||||
|
||||
func (cli *client) Delete(polArn string) liberr.Error {
|
||||
func (cli *client) Delete(polArn string) error {
|
||||
out, err := cli.iam.ListPolicyVersions(cli.GetContext(), &iam.ListPolicyVersionsInput{
|
||||
PolicyArn: aws.String(polArn),
|
||||
})
|
||||
|
@@ -35,15 +35,14 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
const maxItemList int32 = 1000
|
||||
|
||||
func (cli *client) VersionList(arn string, maxItem int32, noDefaultVersion bool) (map[string]string, liberr.Error) {
|
||||
func (cli *client) VersionList(arn string, maxItem int32, noDefaultVersion bool) (map[string]string, error) {
|
||||
if arn == "" {
|
||||
//nolint #goerr113
|
||||
return nil, libhlp.ErrorParamsEmpty.ErrorParent(fmt.Errorf("arn is empty"))
|
||||
return nil, libhlp.ErrorParamsEmpty.Error(fmt.Errorf("arn is empty"))
|
||||
}
|
||||
|
||||
if maxItem < 1 {
|
||||
@@ -105,7 +104,7 @@ func (cli *client) VersionList(arn string, maxItem int32, noDefaultVersion bool)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (cli *client) VersionAdd(arn string, doc string) liberr.Error {
|
||||
func (cli *client) VersionAdd(arn string, doc string) error {
|
||||
out, err := cli.iam.CreatePolicyVersion(cli.GetContext(), &iam.CreatePolicyVersionInput{
|
||||
PolicyArn: aws.String(arn),
|
||||
PolicyDocument: aws.String(doc),
|
||||
@@ -121,7 +120,7 @@ func (cli *client) VersionAdd(arn string, doc string) liberr.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) VersionGet(arn string, vers string) (*types.PolicyVersion, liberr.Error) {
|
||||
func (cli *client) VersionGet(arn string, vers string) (*types.PolicyVersion, error) {
|
||||
out, err := cli.iam.GetPolicyVersion(cli.GetContext(), &iam.GetPolicyVersionInput{
|
||||
PolicyArn: aws.String(arn),
|
||||
VersionId: aws.String(vers),
|
||||
@@ -136,7 +135,7 @@ func (cli *client) VersionGet(arn string, vers string) (*types.PolicyVersion, li
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) VersionDel(arn string, vers string) liberr.Error {
|
||||
func (cli *client) VersionDel(arn string, vers string) error {
|
||||
out, err := cli.iam.DeletePolicyVersion(cli.GetContext(), &iam.DeletePolicyVersionInput{
|
||||
PolicyArn: aws.String(arn),
|
||||
VersionId: aws.String(vers),
|
||||
@@ -151,7 +150,7 @@ func (cli *client) VersionDel(arn string, vers string) liberr.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) CompareUpdate(arn string, doc string) (upd bool, err liberr.Error) {
|
||||
func (cli *client) CompareUpdate(arn string, doc string) (upd bool, err error) {
|
||||
var (
|
||||
e error
|
||||
pol *types.Policy
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
@@ -41,19 +40,19 @@ type client struct {
|
||||
s3 *sdksss.Client
|
||||
}
|
||||
|
||||
type PoliciesWalkFunc func(err liberr.Error, pol sdktps.AttachedPolicy) liberr.Error
|
||||
type PoliciesWalkFunc func(err error, pol sdktps.AttachedPolicy) error
|
||||
|
||||
type Role interface {
|
||||
List() ([]sdktps.Role, liberr.Error)
|
||||
Check(name string) (string, liberr.Error)
|
||||
Add(name, role string) (string, liberr.Error)
|
||||
Delete(roleName string) liberr.Error
|
||||
List() ([]sdktps.Role, error)
|
||||
Check(name string) (string, error)
|
||||
Add(name, role string) (string, error)
|
||||
Delete(roleName string) error
|
||||
|
||||
PolicyAttach(policyARN, roleName string) liberr.Error
|
||||
PolicyDetach(policyARN, roleName string) liberr.Error
|
||||
PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, liberr.Error)
|
||||
PolicyAttachedList(roleName, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error)
|
||||
PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) liberr.Error
|
||||
PolicyAttach(policyARN, roleName string) error
|
||||
PolicyDetach(policyARN, roleName string) error
|
||||
PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, error)
|
||||
PolicyAttachedList(roleName, marker string) ([]sdktps.AttachedPolicy, string, error)
|
||||
PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) error
|
||||
}
|
||||
|
||||
func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Role {
|
||||
|
@@ -29,13 +29,12 @@ import (
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
/*
|
||||
@DEPRECATED: PolicyAttachedList
|
||||
*/
|
||||
func (cli *client) PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, liberr.Error) {
|
||||
func (cli *client) PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, error) {
|
||||
out, _, err := cli.PolicyAttachedList(roleName, "")
|
||||
|
||||
if err != nil {
|
||||
@@ -45,7 +44,7 @@ func (cli *client) PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy,
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttach(policyARN, roleName string) liberr.Error {
|
||||
func (cli *client) PolicyAttach(policyARN, roleName string) error {
|
||||
_, err := cli.iam.AttachRolePolicy(cli.GetContext(), &sdkiam.AttachRolePolicyInput{
|
||||
PolicyArn: sdkaws.String(policyARN),
|
||||
RoleName: sdkaws.String(roleName),
|
||||
@@ -54,7 +53,7 @@ func (cli *client) PolicyAttach(policyARN, roleName string) liberr.Error {
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) PolicyDetach(policyARN, roleName string) liberr.Error {
|
||||
func (cli *client) PolicyDetach(policyARN, roleName string) error {
|
||||
_, err := cli.iam.DetachRolePolicy(cli.GetContext(), &sdkiam.DetachRolePolicyInput{
|
||||
PolicyArn: sdkaws.String(policyARN),
|
||||
RoleName: sdkaws.String(roleName),
|
||||
@@ -63,7 +62,7 @@ func (cli *client) PolicyDetach(policyARN, roleName string) liberr.Error {
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttachedList(roleName, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) {
|
||||
func (cli *client) PolicyAttachedList(roleName, marker string) ([]sdktps.AttachedPolicy, string, error) {
|
||||
in := &sdkiam.ListAttachedRolePoliciesInput{
|
||||
RoleName: sdkaws.String(roleName),
|
||||
MaxItems: sdkaws.Int32(1000),
|
||||
@@ -86,7 +85,7 @@ func (cli *client) PolicyAttachedList(roleName, marker string) ([]sdktps.Attache
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) liberr.Error {
|
||||
func (cli *client) PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) error {
|
||||
var m *string
|
||||
|
||||
in := &sdkiam.ListAttachedRolePoliciesInput{
|
||||
@@ -109,7 +108,7 @@ func (cli *client) PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) lib
|
||||
return nil
|
||||
}
|
||||
|
||||
var e liberr.Error
|
||||
var e error
|
||||
for _, p := range lst.AttachedPolicies {
|
||||
e = fct(e, p)
|
||||
}
|
||||
|
@@ -26,14 +26,13 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
"github.com/nabbar/golib/errors"
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
iamtps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
)
|
||||
|
||||
func (cli *client) List() ([]types.Role, errors.Error) {
|
||||
out, err := cli.iam.ListRoles(cli.GetContext(), &iam.ListRolesInput{})
|
||||
func (cli *client) List() ([]iamtps.Role, error) {
|
||||
out, err := cli.iam.ListRoles(cli.GetContext(), &sdkiam.ListRolesInput{})
|
||||
|
||||
if err != nil {
|
||||
return nil, cli.GetError(err)
|
||||
@@ -42,9 +41,9 @@ func (cli *client) List() ([]types.Role, errors.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Check(name string) (string, errors.Error) {
|
||||
out, err := cli.iam.GetRole(cli.GetContext(), &iam.GetRoleInput{
|
||||
RoleName: aws.String(name),
|
||||
func (cli *client) Check(name string) (string, error) {
|
||||
out, err := cli.iam.GetRole(cli.GetContext(), &sdkiam.GetRoleInput{
|
||||
RoleName: sdkaws.String(name),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -54,10 +53,10 @@ func (cli *client) Check(name string) (string, errors.Error) {
|
||||
return *out.Role.Arn, nil
|
||||
}
|
||||
|
||||
func (cli *client) Add(name, role string) (string, errors.Error) {
|
||||
out, err := cli.iam.CreateRole(cli.GetContext(), &iam.CreateRoleInput{
|
||||
AssumeRolePolicyDocument: aws.String(role),
|
||||
RoleName: aws.String(name),
|
||||
func (cli *client) Add(name, role string) (string, error) {
|
||||
out, err := cli.iam.CreateRole(cli.GetContext(), &sdkiam.CreateRoleInput{
|
||||
AssumeRolePolicyDocument: sdkaws.String(role),
|
||||
RoleName: sdkaws.String(name),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -67,9 +66,9 @@ func (cli *client) Add(name, role string) (string, errors.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Delete(roleName string) errors.Error {
|
||||
_, err := cli.iam.DeleteRole(cli.GetContext(), &iam.DeleteRoleInput{
|
||||
RoleName: aws.String(roleName),
|
||||
func (cli *client) Delete(roleName string) error {
|
||||
_, err := cli.iam.DeleteRole(cli.GetContext(), &sdkiam.DeleteRoleInput{
|
||||
RoleName: sdkaws.String(roleName),
|
||||
})
|
||||
|
||||
return cli.GetError(err)
|
||||
|
@@ -30,10 +30,9 @@ import (
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
awshlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) AccessListAll(username string) ([]sdktps.AccessKeyMetadata, liberr.Error) {
|
||||
func (cli *client) AccessListAll(username string) ([]sdktps.AccessKeyMetadata, error) {
|
||||
var req = &sdkiam.ListAccessKeysInput{}
|
||||
|
||||
if username != "" {
|
||||
@@ -53,7 +52,7 @@ func (cli *client) AccessListAll(username string) ([]sdktps.AccessKeyMetadata, l
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) AccessList(username string) (map[string]bool, liberr.Error) {
|
||||
func (cli *client) AccessList(username string) (map[string]bool, error) {
|
||||
var req = &sdkiam.ListAccessKeysInput{}
|
||||
|
||||
if username != "" {
|
||||
@@ -84,7 +83,7 @@ func (cli *client) AccessList(username string) (map[string]bool, liberr.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) AccessCreate(username string) (string, string, liberr.Error) {
|
||||
func (cli *client) AccessCreate(username string) (string, string, error) {
|
||||
var req = &sdkiam.CreateAccessKeyInput{}
|
||||
|
||||
if username != "" {
|
||||
@@ -104,7 +103,7 @@ func (cli *client) AccessCreate(username string) (string, string, liberr.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) AccessDelete(username, accessKey string) liberr.Error {
|
||||
func (cli *client) AccessDelete(username, accessKey string) error {
|
||||
var req = &sdkiam.DeleteAccessKeyInput{
|
||||
AccessKeyId: sdkaws.String(accessKey),
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
libhlp "github.com/nabbar/golib/aws/helper"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
@@ -41,28 +40,28 @@ type client struct {
|
||||
s3 *sdksss.Client
|
||||
}
|
||||
|
||||
type PoliciesWalkFunc func(err liberr.Error, pol sdktps.AttachedPolicy) liberr.Error
|
||||
type PoliciesWalkFunc func(err error, pol sdktps.AttachedPolicy) error
|
||||
|
||||
type User interface {
|
||||
List() (map[string]string, liberr.Error)
|
||||
Get(username string) (*sdktps.User, liberr.Error)
|
||||
Create(username string) liberr.Error
|
||||
Delete(username string) liberr.Error
|
||||
List() (map[string]string, error)
|
||||
Get(username string) (*sdktps.User, error)
|
||||
Create(username string) error
|
||||
Delete(username string) error
|
||||
|
||||
PolicyPut(policyDocument, policyName, username string) liberr.Error
|
||||
PolicyAttach(policyARN, username string) liberr.Error
|
||||
PolicyDetach(policyARN, username string) liberr.Error
|
||||
PolicyAttachedList(username, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error)
|
||||
PolicyAttachedWalk(username string, fct PoliciesWalkFunc) liberr.Error
|
||||
PolicyPut(policyDocument, policyName, username string) error
|
||||
PolicyAttach(policyARN, username string) error
|
||||
PolicyDetach(policyARN, username string) error
|
||||
PolicyAttachedList(username, marker string) ([]sdktps.AttachedPolicy, string, error)
|
||||
PolicyAttachedWalk(username string, fct PoliciesWalkFunc) error
|
||||
|
||||
LoginCheck(username string) liberr.Error
|
||||
LoginCreate(username, password string) liberr.Error
|
||||
LoginDelete(username string) liberr.Error
|
||||
LoginCheck(username string) error
|
||||
LoginCreate(username, password string) error
|
||||
LoginDelete(username string) error
|
||||
|
||||
AccessListAll(username string) ([]sdktps.AccessKeyMetadata, liberr.Error)
|
||||
AccessList(username string) (map[string]bool, liberr.Error)
|
||||
AccessCreate(username string) (string, string, liberr.Error)
|
||||
AccessDelete(username, accessKey string) liberr.Error
|
||||
AccessListAll(username string) ([]sdktps.AccessKeyMetadata, error)
|
||||
AccessList(username string) (map[string]bool, error)
|
||||
AccessCreate(username string) (string, string, error)
|
||||
AccessDelete(username, accessKey string) error
|
||||
}
|
||||
|
||||
func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) User {
|
||||
|
@@ -26,39 +26,38 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
"github.com/nabbar/golib/aws/helper"
|
||||
"github.com/nabbar/golib/errors"
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
awshlp "github.com/nabbar/golib/aws/helper"
|
||||
)
|
||||
|
||||
func (cli *client) LoginCheck(username string) errors.Error {
|
||||
_, err := cli.iam.GetLoginProfile(cli.GetContext(), &iam.GetLoginProfileInput{
|
||||
UserName: aws.String(username),
|
||||
func (cli *client) LoginCheck(username string) error {
|
||||
_, err := cli.iam.GetLoginProfile(cli.GetContext(), &sdkiam.GetLoginProfileInput{
|
||||
UserName: sdkaws.String(username),
|
||||
})
|
||||
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) LoginCreate(username, password string) errors.Error {
|
||||
out, err := cli.iam.CreateLoginProfile(cli.GetContext(), &iam.CreateLoginProfileInput{
|
||||
UserName: aws.String(username),
|
||||
Password: aws.String(password),
|
||||
func (cli *client) LoginCreate(username, password string) error {
|
||||
out, err := cli.iam.CreateLoginProfile(cli.GetContext(), &sdkiam.CreateLoginProfileInput{
|
||||
UserName: sdkaws.String(username),
|
||||
Password: sdkaws.String(password),
|
||||
PasswordResetRequired: false,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return cli.GetError(err)
|
||||
} else if out.LoginProfile == nil {
|
||||
return helper.ErrorResponse.Error(nil)
|
||||
return awshlp.ErrorResponse.Error(nil)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) LoginDelete(username string) errors.Error {
|
||||
_, err := cli.iam.DeleteLoginProfile(cli.GetContext(), &iam.DeleteLoginProfileInput{
|
||||
UserName: aws.String(username),
|
||||
func (cli *client) LoginDelete(username string) error {
|
||||
_, err := cli.iam.DeleteLoginProfile(cli.GetContext(), &sdkiam.DeleteLoginProfileInput{
|
||||
UserName: sdkaws.String(username),
|
||||
})
|
||||
|
||||
return cli.GetError(err)
|
||||
|
@@ -29,10 +29,9 @@ import (
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
func (cli *client) PolicyPut(policyDocument, policyName, username string) liberr.Error {
|
||||
func (cli *client) PolicyPut(policyDocument, policyName, username string) error {
|
||||
_, err := cli.iam.PutUserPolicy(cli.GetContext(), &sdkiam.PutUserPolicyInput{
|
||||
PolicyDocument: sdkaws.String(policyDocument),
|
||||
PolicyName: sdkaws.String(policyName),
|
||||
@@ -42,7 +41,7 @@ func (cli *client) PolicyPut(policyDocument, policyName, username string) liberr
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttachedList(username, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) {
|
||||
func (cli *client) PolicyAttachedList(username, marker string) ([]sdktps.AttachedPolicy, string, error) {
|
||||
in := &sdkiam.ListAttachedUserPoliciesInput{
|
||||
UserName: sdkaws.String(username),
|
||||
MaxItems: sdkaws.Int32(1000),
|
||||
@@ -65,7 +64,7 @@ func (cli *client) PolicyAttachedList(username, marker string) ([]sdktps.Attache
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttachedWalk(username string, fct PoliciesWalkFunc) liberr.Error {
|
||||
func (cli *client) PolicyAttachedWalk(username string, fct PoliciesWalkFunc) error {
|
||||
var m *string
|
||||
|
||||
in := &sdkiam.ListAttachedUserPoliciesInput{
|
||||
@@ -88,7 +87,7 @@ func (cli *client) PolicyAttachedWalk(username string, fct PoliciesWalkFunc) lib
|
||||
return nil
|
||||
}
|
||||
|
||||
var e liberr.Error
|
||||
var e error
|
||||
for _, p := range lst.AttachedPolicies {
|
||||
e = fct(e, p)
|
||||
}
|
||||
@@ -105,7 +104,7 @@ func (cli *client) PolicyAttachedWalk(username string, fct PoliciesWalkFunc) lib
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) PolicyAttach(policyARN, username string) liberr.Error {
|
||||
func (cli *client) PolicyAttach(policyARN, username string) error {
|
||||
_, err := cli.iam.AttachUserPolicy(cli.GetContext(), &sdkiam.AttachUserPolicyInput{
|
||||
PolicyArn: sdkaws.String(policyARN),
|
||||
UserName: sdkaws.String(username),
|
||||
@@ -114,7 +113,7 @@ func (cli *client) PolicyAttach(policyARN, username string) liberr.Error {
|
||||
return cli.GetError(err)
|
||||
}
|
||||
|
||||
func (cli *client) PolicyDetach(policyARN, username string) liberr.Error {
|
||||
func (cli *client) PolicyDetach(policyARN, username string) error {
|
||||
_, err := cli.iam.DetachUserPolicy(cli.GetContext(), &sdkiam.DetachUserPolicyInput{
|
||||
PolicyArn: sdkaws.String(policyARN),
|
||||
UserName: sdkaws.String(username),
|
||||
|
@@ -26,20 +26,19 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
"github.com/nabbar/golib/aws/helper"
|
||||
"github.com/nabbar/golib/errors"
|
||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
iamtps "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
awshlp "github.com/nabbar/golib/aws/helper"
|
||||
)
|
||||
|
||||
func (cli *client) List() (map[string]string, errors.Error) {
|
||||
out, err := cli.iam.ListUsers(cli.GetContext(), &iam.ListUsersInput{})
|
||||
func (cli *client) List() (map[string]string, error) {
|
||||
out, err := cli.iam.ListUsers(cli.GetContext(), &sdkiam.ListUsersInput{})
|
||||
|
||||
if err != nil {
|
||||
return nil, cli.GetError(err)
|
||||
} else if out.Users == nil {
|
||||
return nil, helper.ErrorResponse.Error(nil)
|
||||
return nil, awshlp.ErrorResponse.Error(nil)
|
||||
} else {
|
||||
var res = make(map[string]string)
|
||||
|
||||
@@ -51,9 +50,9 @@ func (cli *client) List() (map[string]string, errors.Error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *client) Get(username string) (*types.User, errors.Error) {
|
||||
out, err := cli.iam.GetUser(cli.GetContext(), &iam.GetUserInput{
|
||||
UserName: aws.String(username),
|
||||
func (cli *client) Get(username string) (*iamtps.User, error) {
|
||||
out, err := cli.iam.GetUser(cli.GetContext(), &sdkiam.GetUserInput{
|
||||
UserName: sdkaws.String(username),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -63,23 +62,23 @@ func (cli *client) Get(username string) (*types.User, errors.Error) {
|
||||
return out.User, nil
|
||||
}
|
||||
|
||||
func (cli *client) Create(username string) errors.Error {
|
||||
out, err := cli.iam.CreateUser(cli.GetContext(), &iam.CreateUserInput{
|
||||
UserName: aws.String(username),
|
||||
func (cli *client) Create(username string) error {
|
||||
out, err := cli.iam.CreateUser(cli.GetContext(), &sdkiam.CreateUserInput{
|
||||
UserName: sdkaws.String(username),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return cli.GetError(err)
|
||||
} else if out.User == nil {
|
||||
return helper.ErrorResponse.Error(nil)
|
||||
return awshlp.ErrorResponse.Error(nil)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *client) Delete(username string) errors.Error {
|
||||
_, err := cli.iam.DeleteUser(cli.GetContext(), &iam.DeleteUserInput{
|
||||
UserName: aws.String(username),
|
||||
func (cli *client) Delete(username string) error {
|
||||
_, err := cli.iam.DeleteUser(cli.GetContext(), &sdkiam.DeleteUserInput{
|
||||
UserName: sdkaws.String(username),
|
||||
})
|
||||
|
||||
return cli.GetError(err)
|
||||
|
@@ -60,12 +60,12 @@ func (c *Config) Validate() liberr.Error {
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -57,13 +57,13 @@ func (c *config) checkFile(pemFiles ...string) liberr.Error {
|
||||
}
|
||||
|
||||
if _, e := os.Stat(f); e != nil {
|
||||
return ErrorFileStat.ErrorParent(e)
|
||||
return ErrorFileStat.Error(e)
|
||||
}
|
||||
|
||||
/* #nosec */
|
||||
b, e := ioutil.ReadFile(f)
|
||||
if e != nil {
|
||||
return ErrorFileRead.ErrorParent(e)
|
||||
return ErrorFileRead.Error(e)
|
||||
}
|
||||
|
||||
b = bytes.Trim(b, "\n")
|
||||
@@ -162,7 +162,7 @@ func (c *config) AddCertificatePairString(key, crt string) liberr.Error {
|
||||
|
||||
p, err := tls.X509KeyPair([]byte(crt), []byte(key))
|
||||
if err != nil {
|
||||
return ErrorCertKeyPairParse.ErrorParent(err)
|
||||
return ErrorCertKeyPairParse.Error(err)
|
||||
}
|
||||
|
||||
c.cert = append(c.cert, p)
|
||||
@@ -179,7 +179,7 @@ func (c *config) AddCertificatePairFile(keyFile, crtFile string) liberr.Error {
|
||||
}
|
||||
|
||||
if p, e := tls.LoadX509KeyPair(crtFile, keyFile); e != nil {
|
||||
return ErrorCertKeyPairLoad.ErrorParent(e)
|
||||
return ErrorCertKeyPairLoad.Error(e)
|
||||
} else {
|
||||
c.cert = append(c.cert, p)
|
||||
return nil
|
||||
|
@@ -40,7 +40,7 @@ func (c *cRaft) AsyncPropose(session *dgbcli.Session, cmd []byte) (*dgbclt.Reque
|
||||
r, e := c.nodeHost.Propose(session, cmd, c.timeoutCmdASync)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandASync.ErrorParent(c.getErrorCommand("Propose"), e)
|
||||
return r, ErrorCommandASync.Error(c.getErrorCommand("Propose"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -50,7 +50,7 @@ func (c *cRaft) AsyncProposeSession(session *dgbcli.Session) (*dgbclt.RequestSta
|
||||
r, e := c.nodeHost.ProposeSession(session, c.timeoutCmdASync)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandASync.ErrorParent(c.getErrorCommand("ProposeSession"), e)
|
||||
return r, ErrorCommandASync.Error(c.getErrorCommand("ProposeSession"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -60,7 +60,7 @@ func (c *cRaft) AsyncReadIndex() (*dgbclt.RequestState, liberr.Error) {
|
||||
r, e := c.nodeHost.ReadIndex(c.config.ClusterID, c.timeoutCmdASync)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandASync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("ReadIndex"), e)
|
||||
return r, ErrorCommandASync.Error(c.getErrorCluster(), c.getErrorCommand("ReadIndex"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -78,7 +78,7 @@ func (c *cRaft) AsyncRequestCompaction(nodeID uint64) (*dgbclt.SysOpState, liber
|
||||
r, e := c.nodeHost.RequestCompaction(c.config.ClusterID, nodeID)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandASync.ErrorParent(c.getErrorCluster(), er, c.getErrorCommand("RequestCompaction"), e)
|
||||
return r, ErrorCommandASync.Error(c.getErrorCluster(), er, c.getErrorCommand("RequestCompaction"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
|
@@ -152,14 +152,14 @@ func (c *cRaft) ClusterStart(join bool) liberr.Error {
|
||||
}
|
||||
|
||||
if f, ok := c.fctCreate.(dgbstm.CreateStateMachineFunc); ok {
|
||||
err.AddParent(c.nodeHost.StartCluster(c.memberInit, join, f, c.config))
|
||||
err.Add(c.nodeHost.StartCluster(c.memberInit, join, f, c.config))
|
||||
} else if f, ok := c.fctCreate.(dgbstm.CreateConcurrentStateMachineFunc); ok {
|
||||
err.AddParent(c.nodeHost.StartConcurrentCluster(c.memberInit, join, f, c.config))
|
||||
err.Add(c.nodeHost.StartConcurrentCluster(c.memberInit, join, f, c.config))
|
||||
} else if f, ok := c.fctCreate.(dgbstm.CreateOnDiskStateMachineFunc); ok {
|
||||
err.AddParent(c.nodeHost.StartOnDiskCluster(c.memberInit, join, f, c.config))
|
||||
err.Add(c.nodeHost.StartOnDiskCluster(c.memberInit, join, f, c.config))
|
||||
} else {
|
||||
//nolint #goerr113
|
||||
return ErrorParamsMismatching.ErrorParent(fmt.Errorf("create function is not one of type of CreateStateMachineFunc, CreateConcurrentStateMachineFunc, CreateOnDiskStateMachineFunc"))
|
||||
return ErrorParamsMismatching.Error(fmt.Errorf("create function is not one of type of CreateStateMachineFunc, CreateConcurrentStateMachineFunc, CreateOnDiskStateMachineFunc"))
|
||||
}
|
||||
|
||||
if err.HasParent() {
|
||||
@@ -173,7 +173,7 @@ func (c *cRaft) ClusterStop(force bool) liberr.Error {
|
||||
e := c.nodeHost.StopCluster(c.config.ClusterID)
|
||||
|
||||
if e != nil && !force {
|
||||
return ErrorNodeHostStop.ErrorParent(c.getErrorCluster(), e)
|
||||
return ErrorNodeHostStop.Error(c.getErrorCluster(), e)
|
||||
}
|
||||
|
||||
c.nodeHost.Stop()
|
||||
@@ -200,7 +200,7 @@ func (c *cRaft) NodeStop(target uint64) liberr.Error {
|
||||
e := c.nodeHost.StopNode(c.config.ClusterID, target)
|
||||
|
||||
if e != nil {
|
||||
return ErrorNodeHostStop.ErrorParent(c.getErrorCluster(), en, e)
|
||||
return ErrorNodeHostStop.Error(c.getErrorCluster(), en, e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -211,7 +211,7 @@ func (c *cRaft) NodeRestart(force bool) liberr.Error {
|
||||
|
||||
if l, ok, err := c.GetLeaderID(); err == nil && ok && l == c.config.NodeID {
|
||||
join = true
|
||||
var sErr = ErrorNodeHostRestart.ErrorParent(c.getErrorCluster(), c.getErrorNode())
|
||||
var sErr = ErrorNodeHostRestart.Error(c.getErrorCluster(), c.getErrorNode())
|
||||
for id, nd := range c.memberInit {
|
||||
if id == c.config.NodeID {
|
||||
continue
|
||||
@@ -220,7 +220,7 @@ func (c *cRaft) NodeRestart(force bool) liberr.Error {
|
||||
continue
|
||||
}
|
||||
if err = c.RequestLeaderTransfer(id); err == nil {
|
||||
sErr.AddParentError(err)
|
||||
sErr.Add(err)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ func (c *cRaft) GetLeaderID() (leader uint64, valid bool, err liberr.Error) {
|
||||
leader, valid, e = c.nodeHost.GetLeaderID(c.config.ClusterID)
|
||||
|
||||
if e != nil {
|
||||
err = ErrorLeader.ErrorParent(c.getErrorCluster(), e)
|
||||
err = ErrorLeader.Error(c.getErrorCluster(), e)
|
||||
}
|
||||
|
||||
return
|
||||
@@ -261,7 +261,7 @@ func (c *cRaft) GetNodeUser() (dgbclt.INodeUser, liberr.Error) {
|
||||
r, e := c.nodeHost.GetNodeUser(c.config.ClusterID)
|
||||
|
||||
if e != nil {
|
||||
return nil, ErrorNodeUser.ErrorParent(c.getErrorCluster())
|
||||
return nil, ErrorNodeUser.Error(c.getErrorCluster())
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -287,7 +287,7 @@ func (c *cRaft) RequestLeaderTransfer(targetNodeID uint64) liberr.Error {
|
||||
e := c.nodeHost.RequestLeaderTransfer(c.config.ClusterID, targetNodeID)
|
||||
|
||||
if e != nil {
|
||||
return ErrorLeaderTransfer.ErrorParent(c.getErrorCluster(), c.getErrorNodeTarget(targetNodeID), e)
|
||||
return ErrorLeaderTransfer.Error(c.getErrorCluster(), c.getErrorNodeTarget(targetNodeID), e)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -68,12 +68,12 @@ func (c Config) Validate() liberr.Error {
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -248,12 +248,12 @@ func (c ConfigCluster) Validate() liberr.Error {
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -92,12 +92,12 @@ func (c ConfigEngine) Validate() liberr.Error {
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -73,12 +73,12 @@ func (c ConfigExpert) Validate() liberr.Error {
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -97,12 +97,12 @@ func (c ConfigGossip) Validate() liberr.Error {
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -322,12 +322,12 @@ func (c ConfigNode) Validate() liberr.Error {
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
if e, ok := er.(*libval.InvalidValidationError); ok {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
}
|
||||
|
||||
for _, e := range er.(libval.ValidationErrors) {
|
||||
//nolint goerr113
|
||||
err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -118,7 +118,7 @@ func NewCluster(cfg Config, fctCreate interface{}) (Cluster, liberr.Error) {
|
||||
}
|
||||
|
||||
if n, e := dgbclt.NewNodeHost(cfg.GetDGBConfigNode()); e != nil {
|
||||
return nil, ErrorNodeHostNew.ErrorParent(e)
|
||||
return nil, ErrorNodeHostNew.Error(e)
|
||||
} else {
|
||||
c.nodeHost = n
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ func (c *cRaft) LocalReadNode(rs *dgbclt.RequestState, query interface{}) (inter
|
||||
i, e := c.nodeHost.ReadLocalNode(rs, query)
|
||||
|
||||
if e != nil {
|
||||
return i, ErrorCommandLocal.ErrorParent(c.getErrorCommand("ReadNode"), e)
|
||||
return i, ErrorCommandLocal.Error(c.getErrorCommand("ReadNode"), e)
|
||||
}
|
||||
|
||||
return i, nil
|
||||
@@ -49,7 +49,7 @@ func (c *cRaft) LocalNAReadNode(rs *dgbclt.RequestState, query []byte) ([]byte,
|
||||
r, e := c.nodeHost.NAReadLocalNode(rs, query)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandLocal.ErrorParent(c.getErrorCommand("ReadNode"), e)
|
||||
return r, ErrorCommandLocal.Error(c.getErrorCommand("ReadNode"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
|
@@ -68,7 +68,7 @@ func (c *cRaft) SyncPropose(parent context.Context, session *dgbcli.Session, cmd
|
||||
r, e := c.nodeHost.SyncPropose(ctx, session, cmd)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandSync.ErrorParent(c.getErrorCommand("Propose"), e)
|
||||
return r, ErrorCommandSync.Error(c.getErrorCommand("Propose"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -81,7 +81,7 @@ func (c *cRaft) SyncRead(parent context.Context, query interface{}) (interface{}
|
||||
r, e := c.nodeHost.SyncRead(ctx, c.config.ClusterID, query)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandSync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("Read"), e)
|
||||
return r, ErrorCommandSync.Error(c.getErrorCluster(), c.getErrorCommand("Read"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -94,7 +94,7 @@ func (c *cRaft) SyncGetClusterMembership(parent context.Context) (*dgbclt.Member
|
||||
r, e := c.nodeHost.SyncGetClusterMembership(ctx, c.config.ClusterID)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandSync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("GetClusterMembership"), e)
|
||||
return r, ErrorCommandSync.Error(c.getErrorCluster(), c.getErrorCommand("GetClusterMembership"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -107,7 +107,7 @@ func (c *cRaft) SyncGetSession(parent context.Context) (*dgbcli.Session, liberr.
|
||||
r, e := c.nodeHost.SyncGetSession(ctx, c.config.ClusterID)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandSync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("GetSession"), e)
|
||||
return r, ErrorCommandSync.Error(c.getErrorCluster(), c.getErrorCommand("GetSession"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -120,7 +120,7 @@ func (c *cRaft) SyncCloseSession(parent context.Context, cs *dgbcli.Session) lib
|
||||
e := c.nodeHost.SyncCloseSession(ctx, cs)
|
||||
|
||||
if e != nil {
|
||||
return ErrorCommandSync.ErrorParent(c.getErrorCommand("CloseSession"), e)
|
||||
return ErrorCommandSync.Error(c.getErrorCommand("CloseSession"), e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -133,7 +133,7 @@ func (c *cRaft) SyncRequestSnapshot(parent context.Context, opt dgbclt.SnapshotO
|
||||
r, e := c.nodeHost.SyncRequestSnapshot(ctx, c.config.ClusterID, opt)
|
||||
|
||||
if e != nil {
|
||||
return r, ErrorCommandSync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("RequestSnapshot"), e)
|
||||
return r, ErrorCommandSync.Error(c.getErrorCluster(), c.getErrorCommand("RequestSnapshot"), e)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -154,7 +154,7 @@ func (c *cRaft) SyncRequestDeleteNode(parent context.Context, nodeID uint64, con
|
||||
e := c.nodeHost.SyncRequestDeleteNode(ctx, c.config.ClusterID, nodeID, configChangeIndex)
|
||||
|
||||
if e != nil {
|
||||
return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RequestDeleteNode"), e)
|
||||
return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RequestDeleteNode"), e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -176,7 +176,7 @@ func (c *cRaft) SyncRequestAddNode(parent context.Context, nodeID uint64, target
|
||||
e := c.nodeHost.SyncRequestAddNode(ctx, c.config.ClusterID, nodeID, target, configChangeIndex)
|
||||
|
||||
if e != nil {
|
||||
return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RequestAddNode"), e)
|
||||
return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RequestAddNode"), e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -198,7 +198,7 @@ func (c *cRaft) SyncRequestAddObserver(parent context.Context, nodeID uint64, ta
|
||||
e := c.nodeHost.SyncRequestAddObserver(ctx, c.config.ClusterID, nodeID, target, configChangeIndex)
|
||||
|
||||
if e != nil {
|
||||
return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RequestAddObserver"), e)
|
||||
return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RequestAddObserver"), e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -220,7 +220,7 @@ func (c *cRaft) SyncRequestAddWitness(parent context.Context, nodeID uint64, tar
|
||||
e := c.nodeHost.SyncRequestAddWitness(ctx, c.config.ClusterID, nodeID, target, configChangeIndex)
|
||||
|
||||
if e != nil {
|
||||
return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RequestAddWitness"), e)
|
||||
return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RequestAddWitness"), e)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -241,7 +241,7 @@ func (c *cRaft) SyncRemoveData(parent context.Context, nodeID uint64) liberr.Err
|
||||
e := c.nodeHost.SyncRemoveData(ctx, c.config.ClusterID, nodeID)
|
||||
|
||||
if e != nil {
|
||||
return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RemoveData"), e)
|
||||
return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RemoveData"), e)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -34,7 +34,6 @@ import (
|
||||
|
||||
cfgcst "github.com/nabbar/golib/config/const"
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
spfcbr "github.com/spf13/cobra"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
@@ -110,7 +109,7 @@ func (c *configModel) ComponentKeys() []string {
|
||||
return res
|
||||
}
|
||||
|
||||
func (c *configModel) ComponentStart() liberr.Error {
|
||||
func (c *configModel) ComponentStart() error {
|
||||
var err = ErrorComponentStart.Error(nil)
|
||||
|
||||
for _, key := range c.ComponentDependencies() {
|
||||
@@ -122,9 +121,9 @@ func (c *configModel) ComponentStart() liberr.Error {
|
||||
e := cpt.Start()
|
||||
c.componentUpdate(key, cpt)
|
||||
if e != nil {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
} else if !cpt.IsStarted() {
|
||||
err.AddParent(fmt.Errorf("component '%s' has been call to start, but is not started", key))
|
||||
err.Add(fmt.Errorf("component '%s' has been call to start, but is not started", key))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,7 +154,7 @@ func (c *configModel) ComponentIsStarted() bool {
|
||||
return isOk
|
||||
}
|
||||
|
||||
func (c *configModel) ComponentReload() liberr.Error {
|
||||
func (c *configModel) ComponentReload() error {
|
||||
var err = ErrorComponentReload.Error(nil)
|
||||
|
||||
for _, key := range c.ComponentDependencies() {
|
||||
@@ -167,9 +166,9 @@ func (c *configModel) ComponentReload() liberr.Error {
|
||||
e := cpt.Reload()
|
||||
c.componentUpdate(key, cpt)
|
||||
if e != nil {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
} else if !cpt.IsStarted() {
|
||||
err.AddParent(fmt.Errorf("component '%s' has been call to reload, but is not started", key))
|
||||
err.Add(fmt.Errorf("component '%s' has been call to reload, but is not started", key))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,7 +335,7 @@ func (c *configModel) RegisterFlag(Command *spfcbr.Command) error {
|
||||
if cpt := c.ComponentGet(k); cpt == nil {
|
||||
continue
|
||||
} else if e := cpt.RegisterFlag(Command); e != nil {
|
||||
err.AddParent(e)
|
||||
err.Add(e)
|
||||
} else {
|
||||
c.ComponentSet(k, cpt)
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
libaws "github.com/nabbar/golib/aws"
|
||||
libtls "github.com/nabbar/golib/certificates"
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libhtc "github.com/nabbar/golib/httpcli"
|
||||
libreq "github.com/nabbar/golib/request"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
@@ -165,7 +164,7 @@ func (o *componentAws) _getFctEvt(key uint8) cfgtps.FuncCptEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentAws) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error {
|
||||
func (o *componentAws) _runFct(fct func(cpt cfgtps.Component) error) error {
|
||||
if fct != nil {
|
||||
return fct(o)
|
||||
}
|
||||
@@ -173,11 +172,9 @@ func (o *componentAws) _runFct(fct func(cpt cfgtps.Component) liberr.Error) libe
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentAws) _runCli() liberr.Error {
|
||||
func (o *componentAws) _runCli() error {
|
||||
var (
|
||||
e error
|
||||
|
||||
err liberr.Error
|
||||
err error
|
||||
cli libaws.AWS
|
||||
cfg libaws.Config
|
||||
mon *libreq.OptionsHealth
|
||||
@@ -226,11 +223,11 @@ func (o *componentAws) _runCli() liberr.Error {
|
||||
o.m.Unlock()
|
||||
|
||||
if req != nil {
|
||||
if req, e = opt.Update(o.x.GetContext, req); e != nil {
|
||||
return prt.ErrorParent(e)
|
||||
if req, err = opt.Update(o.x.GetContext, req); err != nil {
|
||||
return prt.Error(err)
|
||||
}
|
||||
} else if req, e = opt.New(o.x.GetContext); e != nil {
|
||||
return prt.ErrorParent(e)
|
||||
} else if req, err = opt.New(o.x.GetContext); err != nil {
|
||||
return prt.Error(err)
|
||||
}
|
||||
|
||||
o.m.Lock()
|
||||
@@ -239,8 +236,8 @@ func (o *componentAws) _runCli() liberr.Error {
|
||||
}
|
||||
|
||||
if mon != nil {
|
||||
if e = o._registerMonitor(mon, cfg); e != nil {
|
||||
return prt.ErrorParent(e)
|
||||
if err = o._registerMonitor(mon, cfg); err != nil {
|
||||
return prt.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +248,7 @@ func (o *componentAws) _runCli() liberr.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentAws) _run() liberr.Error {
|
||||
func (o *componentAws) _run() error {
|
||||
fb, fa := o._getFct()
|
||||
|
||||
if err := o._runFct(fb); err != nil {
|
||||
|
@@ -29,7 +29,6 @@ package aws
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -95,11 +94,11 @@ func (o *componentAws) IsRunning() bool {
|
||||
return o.IsStarted()
|
||||
}
|
||||
|
||||
func (o *componentAws) Start() liberr.Error {
|
||||
func (o *componentAws) Start() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
func (o *componentAws) Reload() liberr.Error {
|
||||
func (o *componentAws) Reload() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
@@ -132,7 +131,7 @@ func (o *componentAws) Dependencies() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentAws) SetDependencies(d []string) liberr.Error {
|
||||
func (o *componentAws) SetDependencies(d []string) error {
|
||||
o.m.RLock()
|
||||
defer o.m.RUnlock()
|
||||
|
||||
|
@@ -30,7 +30,6 @@ import (
|
||||
libaws "github.com/nabbar/golib/aws"
|
||||
cfgstd "github.com/nabbar/golib/aws/configAws"
|
||||
cfgcus "github.com/nabbar/golib/aws/configCustom"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libhtc "github.com/nabbar/golib/httpcli"
|
||||
libreq "github.com/nabbar/golib/request"
|
||||
spfcbr "github.com/spf13/cobra"
|
||||
@@ -111,7 +110,7 @@ func (o *componentAws) RegisterFlag(Command *spfcbr.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libhtc.Options, liberr.Error) {
|
||||
func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libhtc.Options, error) {
|
||||
var (
|
||||
key string
|
||||
cfg libaws.Config
|
||||
@@ -119,7 +118,7 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh
|
||||
mon *libreq.OptionsHealth
|
||||
htc *libhtc.Options
|
||||
vpr *spfvpr.Viper
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if vpr = o._getSPFViper(); vpr == nil {
|
||||
@@ -131,8 +130,8 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh
|
||||
switch o.d {
|
||||
case ConfigCustomStatus:
|
||||
cnf := cfgcus.ModelStatus{}
|
||||
if e := vpr.UnmarshalKey(key, &cnf); e != nil {
|
||||
return nil, nil, nil, ErrorParamInvalid.ErrorParent(e)
|
||||
if err = vpr.UnmarshalKey(key, &cnf); err != nil {
|
||||
return nil, nil, nil, ErrorParamInvalid.Error(err)
|
||||
} else {
|
||||
flg.updCustom(&cnf.Config)
|
||||
}
|
||||
@@ -146,8 +145,8 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh
|
||||
|
||||
case ConfigCustom:
|
||||
cnf := cfgcus.Model{}
|
||||
if e := vpr.UnmarshalKey(key, &cnf); e != nil {
|
||||
return nil, nil, nil, ErrorParamInvalid.ErrorParent(e)
|
||||
if err = vpr.UnmarshalKey(key, &cnf); err != nil {
|
||||
return nil, nil, nil, ErrorParamInvalid.Error(err)
|
||||
} else {
|
||||
flg.updCustom(&cnf)
|
||||
}
|
||||
@@ -161,8 +160,8 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh
|
||||
|
||||
case ConfigStandardStatus:
|
||||
cnf := cfgstd.ModelStatus{}
|
||||
if e := vpr.UnmarshalKey(key, &cnf); e != nil {
|
||||
return nil, nil, nil, ErrorParamInvalid.ErrorParent(e)
|
||||
if err = vpr.UnmarshalKey(key, &cnf); err != nil {
|
||||
return nil, nil, nil, ErrorParamInvalid.Error(err)
|
||||
} else {
|
||||
flg.updStandard(&cnf.Config)
|
||||
}
|
||||
@@ -176,8 +175,8 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh
|
||||
|
||||
case ConfigStandard:
|
||||
cnf := cfgstd.Model{}
|
||||
if e := vpr.UnmarshalKey(key, &cnf); e != nil {
|
||||
return nil, nil, nil, ErrorParamInvalid.ErrorParent(e)
|
||||
if err = vpr.UnmarshalKey(key, &cnf); err != nil {
|
||||
return nil, nil, nil, ErrorParamInvalid.Error(err)
|
||||
} else {
|
||||
flg.updStandard(&cnf)
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
libaws "github.com/nabbar/golib/aws"
|
||||
cfgstd "github.com/nabbar/golib/aws/configAws"
|
||||
cfgcus "github.com/nabbar/golib/aws/configCustom"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type ConfigDriver uint8
|
||||
@@ -70,7 +69,7 @@ func (a ConfigDriver) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (a ConfigDriver) Unmarshal(p []byte) (libaws.Config, liberr.Error) {
|
||||
func (a ConfigDriver) Unmarshal(p []byte) (libaws.Config, error) {
|
||||
switch a {
|
||||
case ConfigCustom:
|
||||
return cfgcus.NewConfigJsonUnmashal(p)
|
||||
@@ -107,7 +106,7 @@ func (a ConfigDriver) Model() interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
func (a ConfigDriver) NewFromModel(i interface{}) (libaws.Config, liberr.Error) {
|
||||
func (a ConfigDriver) NewFromModel(i interface{}) (libaws.Config, error) {
|
||||
switch a {
|
||||
case ConfigCustomStatus:
|
||||
if o, ok := i.(cfgcus.ModelStatus); !ok {
|
||||
@@ -126,7 +125,7 @@ func (a ConfigDriver) NewFromModel(i interface{}) (libaws.Config, liberr.Error)
|
||||
return nil, ErrorConfigInvalid.Error(nil)
|
||||
} else {
|
||||
if edp, err := url.Parse(o.Endpoint); err != nil {
|
||||
return nil, ErrorConfigInvalid.ErrorParent(err)
|
||||
return nil, ErrorConfigInvalid.Error(err)
|
||||
} else {
|
||||
cfg := cfgcus.NewConfig(o.Bucket, o.AccessKey, o.SecretKey, edp, o.Region)
|
||||
|
||||
|
@@ -34,7 +34,6 @@ import (
|
||||
libtls "github.com/nabbar/golib/certificates"
|
||||
libcfg "github.com/nabbar/golib/config"
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
type ComponentAwsClient interface {
|
||||
@@ -51,7 +50,7 @@ type ComponentAws interface {
|
||||
ComponentAwsClient
|
||||
ComponentAwsAPI
|
||||
|
||||
GetAws() (libaws.AWS, liberr.Error)
|
||||
GetAws() (libaws.AWS, error)
|
||||
SetAws(a libaws.AWS)
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,6 @@ import (
|
||||
libaws "github.com/nabbar/golib/aws"
|
||||
libtls "github.com/nabbar/golib/certificates"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
montps "github.com/nabbar/golib/monitor/types"
|
||||
)
|
||||
|
||||
@@ -64,7 +63,7 @@ func (o *componentAws) RegisterTLS(fct libtls.FctTLSDefault) {
|
||||
o.t = fct
|
||||
}
|
||||
|
||||
func (o *componentAws) GetAws() (libaws.AWS, liberr.Error) {
|
||||
func (o *componentAws) GetAws() (libaws.AWS, error) {
|
||||
o.m.RLock()
|
||||
defer o.m.RUnlock()
|
||||
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
"github.com/nabbar/golib/database/gorm"
|
||||
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
spfvbr "github.com/spf13/viper"
|
||||
@@ -148,7 +147,7 @@ func (o *componentDatabase) _getFctEvt(key uint8) cfgtps.FuncCptEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentDatabase) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error {
|
||||
func (o *componentDatabase) _runFct(fct func(cpt cfgtps.Component) error) error {
|
||||
if fct != nil {
|
||||
return fct(o)
|
||||
}
|
||||
@@ -156,9 +155,9 @@ func (o *componentDatabase) _runFct(fct func(cpt cfgtps.Component) liberr.Error)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentDatabase) _runCli() liberr.Error {
|
||||
func (o *componentDatabase) _runCli() error {
|
||||
var (
|
||||
err liberr.Error
|
||||
err error
|
||||
prt = ErrorComponentReload
|
||||
dbo gorm.Database
|
||||
cfg *gorm.Config
|
||||
@@ -183,13 +182,13 @@ func (o *componentDatabase) _runCli() liberr.Error {
|
||||
o.m.Unlock()
|
||||
|
||||
if e := o._registerMonitor(cfg); e != nil {
|
||||
return prt.ErrorParent(e)
|
||||
return prt.Error(e)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentDatabase) _run() liberr.Error {
|
||||
func (o *componentDatabase) _run() error {
|
||||
fb, fa := o._getFct()
|
||||
|
||||
if err := o._runFct(fb); err != nil {
|
||||
|
@@ -29,7 +29,6 @@ package database
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -103,11 +102,11 @@ func (o *componentDatabase) IsRunning() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (o *componentDatabase) Start() liberr.Error {
|
||||
func (o *componentDatabase) Start() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
func (o *componentDatabase) Reload() liberr.Error {
|
||||
func (o *componentDatabase) Reload() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
@@ -145,7 +144,7 @@ func (o *componentDatabase) Dependencies() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentDatabase) SetDependencies(d []string) liberr.Error {
|
||||
func (o *componentDatabase) SetDependencies(d []string) error {
|
||||
o.m.RLock()
|
||||
defer o.m.RUnlock()
|
||||
|
||||
|
@@ -31,7 +31,6 @@ import (
|
||||
|
||||
"github.com/nabbar/golib/database/gorm"
|
||||
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
spfcbr "github.com/spf13/cobra"
|
||||
spfvpr "github.com/spf13/viper"
|
||||
)
|
||||
@@ -108,12 +107,12 @@ func (o *componentDatabase) RegisterFlag(Command *spfcbr.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentDatabase) _getConfig() (*gorm.Config, liberr.Error) {
|
||||
func (o *componentDatabase) _getConfig() (*gorm.Config, error) {
|
||||
var (
|
||||
key string
|
||||
cfg gorm.Config
|
||||
vpr *spfvpr.Viper
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if vpr = o._getSPFViper(); vpr == nil {
|
||||
@@ -123,7 +122,7 @@ func (o *componentDatabase) _getConfig() (*gorm.Config, liberr.Error) {
|
||||
}
|
||||
|
||||
if e := vpr.UnmarshalKey(key, &cfg); e != nil {
|
||||
return nil, ErrorParamInvalid.ErrorParent(e)
|
||||
return nil, ErrorParamInvalid.Error(e)
|
||||
}
|
||||
|
||||
cfg.RegisterLogger(o.getLogger, o.li, o.ls)
|
||||
|
@@ -28,7 +28,6 @@ package head
|
||||
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
spfvbr "github.com/spf13/viper"
|
||||
@@ -137,7 +136,7 @@ func (o *componentHead) _getFctEvt(key uint8) cfgtps.FuncCptEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentHead) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error {
|
||||
func (o *componentHead) _runFct(fct func(cpt cfgtps.Component) error) error {
|
||||
if fct != nil {
|
||||
return fct(o)
|
||||
}
|
||||
@@ -145,7 +144,7 @@ func (o *componentHead) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentHead) _runCli() liberr.Error {
|
||||
func (o *componentHead) _runCli() error {
|
||||
if cfg, err := o._getConfig(); err != nil {
|
||||
return ErrorParamInvalid.Error(err)
|
||||
} else {
|
||||
@@ -157,7 +156,7 @@ func (o *componentHead) _runCli() liberr.Error {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentHead) _run() liberr.Error {
|
||||
func (o *componentHead) _run() error {
|
||||
fb, fa := o._getFct()
|
||||
|
||||
if err := o._runFct(fb); err != nil {
|
||||
|
@@ -29,7 +29,6 @@ package head
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -95,11 +94,11 @@ func (o *componentHead) IsRunning() bool {
|
||||
return o.IsStarted()
|
||||
}
|
||||
|
||||
func (o *componentHead) Start() liberr.Error {
|
||||
func (o *componentHead) Start() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
func (o *componentHead) Reload() liberr.Error {
|
||||
func (o *componentHead) Reload() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
@@ -132,7 +131,7 @@ func (o *componentHead) Dependencies() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentHead) SetDependencies(d []string) liberr.Error {
|
||||
func (o *componentHead) SetDependencies(d []string) error {
|
||||
o.m.RLock()
|
||||
defer o.m.RUnlock()
|
||||
|
||||
|
@@ -27,7 +27,6 @@
|
||||
package head
|
||||
|
||||
import (
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
librtr "github.com/nabbar/golib/router"
|
||||
spfcbr "github.com/spf13/cobra"
|
||||
spfvpr "github.com/spf13/viper"
|
||||
@@ -37,12 +36,12 @@ func (o *componentHead) RegisterFlag(Command *spfcbr.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentHead) _getConfig() (*librtr.HeadersConfig, liberr.Error) {
|
||||
func (o *componentHead) _getConfig() (*librtr.HeadersConfig, error) {
|
||||
var (
|
||||
key string
|
||||
cfg librtr.HeadersConfig
|
||||
vpr *spfvpr.Viper
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if vpr = o._getSPFViper(); vpr == nil {
|
||||
@@ -52,7 +51,7 @@ func (o *componentHead) _getConfig() (*librtr.HeadersConfig, liberr.Error) {
|
||||
}
|
||||
|
||||
if e := vpr.UnmarshalKey(key, &cfg); e != nil {
|
||||
return nil, ErrorParamInvalid.ErrorParent(e)
|
||||
return nil, ErrorParamInvalid.Error(e)
|
||||
}
|
||||
|
||||
if err = cfg.Validate(); err != nil {
|
||||
|
@@ -33,7 +33,6 @@ import (
|
||||
libtls "github.com/nabbar/golib/certificates"
|
||||
cpttls "github.com/nabbar/golib/config/components/tls"
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
htpool "github.com/nabbar/golib/httpserver/pool"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -178,7 +177,7 @@ func (o *componentHttp) _getFctEvt(key uint8) cfgtps.FuncCptEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentHttp) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error {
|
||||
func (o *componentHttp) _runFct(fct func(cpt cfgtps.Component) error) error {
|
||||
if fct != nil {
|
||||
return fct(o)
|
||||
}
|
||||
@@ -186,10 +185,10 @@ func (o *componentHttp) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentHttp) _runCli() liberr.Error {
|
||||
func (o *componentHttp) _runCli() error {
|
||||
var (
|
||||
e error
|
||||
err liberr.Error
|
||||
err error
|
||||
prt = ErrorComponentReload
|
||||
pol htpool.Pool
|
||||
cfg *htpool.Config
|
||||
@@ -207,12 +206,12 @@ func (o *componentHttp) _runCli() liberr.Error {
|
||||
defer o.m.RUnlock()
|
||||
|
||||
if pol, err = cfg.Pool(o.x.GetContext, o._GetHandler, o.getLogger); err != nil {
|
||||
return prt.ErrorParent(err)
|
||||
return prt.Error(err)
|
||||
}
|
||||
|
||||
if o.s != nil && o.s.Len() > 0 {
|
||||
if e = o.s.Merge(pol, o.getLogger); e != nil {
|
||||
return prt.ErrorParent(e)
|
||||
return prt.Error(e)
|
||||
}
|
||||
} else {
|
||||
o.m.RUnlock()
|
||||
@@ -223,7 +222,7 @@ func (o *componentHttp) _runCli() liberr.Error {
|
||||
}
|
||||
|
||||
if e = o.s.Restart(o.x.GetContext()); e != nil {
|
||||
return prt.ErrorParent(e)
|
||||
return prt.Error(e)
|
||||
}
|
||||
|
||||
// Implement wait notify on main call
|
||||
@@ -233,7 +232,7 @@ func (o *componentHttp) _runCli() liberr.Error {
|
||||
return o._registerMonitor(prt)
|
||||
}
|
||||
|
||||
func (o *componentHttp) _run() liberr.Error {
|
||||
func (o *componentHttp) _run() error {
|
||||
fb, fa := o._getFct()
|
||||
|
||||
if err := o._runFct(fb); err != nil {
|
||||
|
@@ -30,7 +30,6 @@ import (
|
||||
cpttls "github.com/nabbar/golib/config/components/tls"
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -103,11 +102,11 @@ func (o *componentHttp) IsRunning() bool {
|
||||
return o.s.IsRunning()
|
||||
}
|
||||
|
||||
func (o *componentHttp) Start() liberr.Error {
|
||||
func (o *componentHttp) Start() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
func (o *componentHttp) Reload() liberr.Error {
|
||||
func (o *componentHttp) Reload() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
@@ -145,7 +144,7 @@ func (o *componentHttp) Dependencies() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentHttp) SetDependencies(d []string) liberr.Error {
|
||||
func (o *componentHttp) SetDependencies(d []string) error {
|
||||
o.m.RLock()
|
||||
defer o.m.RUnlock()
|
||||
|
||||
|
@@ -29,7 +29,6 @@ package http
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
htpool "github.com/nabbar/golib/httpserver/pool"
|
||||
spfcbr "github.com/spf13/cobra"
|
||||
spfvpr "github.com/spf13/viper"
|
||||
@@ -39,12 +38,12 @@ func (o *componentHttp) RegisterFlag(Command *spfcbr.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentHttp) _getConfig() (*htpool.Config, liberr.Error) {
|
||||
func (o *componentHttp) _getConfig() (*htpool.Config, error) {
|
||||
var (
|
||||
key string
|
||||
cfg htpool.Config
|
||||
vpr *spfvpr.Viper
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if vpr = o._getSPFViper(); vpr == nil {
|
||||
@@ -54,7 +53,7 @@ func (o *componentHttp) _getConfig() (*htpool.Config, liberr.Error) {
|
||||
}
|
||||
|
||||
if e := vpr.UnmarshalKey(key, &cfg); e != nil {
|
||||
return nil, ErrorParamInvalid.ErrorParent(e)
|
||||
return nil, ErrorParamInvalid.Error(e)
|
||||
}
|
||||
|
||||
cfg.SetDefaultTLS(o._GetTLS)
|
||||
@@ -64,9 +63,9 @@ func (o *componentHttp) _getConfig() (*htpool.Config, liberr.Error) {
|
||||
if err = cfg.Validate(); err != nil {
|
||||
return nil, ErrorConfigInvalid.Error(err)
|
||||
} else if o.h == nil {
|
||||
return nil, ErrorComponentNotInitialized.ErrorParent(fmt.Errorf("missing handler"))
|
||||
return nil, ErrorComponentNotInitialized.Error(fmt.Errorf("missing handler"))
|
||||
} else if len(o.h()) < 1 {
|
||||
return nil, ErrorComponentNotInitialized.ErrorParent(fmt.Errorf("missing handler"))
|
||||
return nil, ErrorComponentNotInitialized.Error(fmt.Errorf("missing handler"))
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
|
@@ -52,7 +52,7 @@ func (o *componentHttp) _getMonitorPool() montps.Pool {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentHttp) _registerMonitor(err liberr.CodeError) liberr.Error {
|
||||
func (o *componentHttp) _registerMonitor(err liberr.CodeError) error {
|
||||
var (
|
||||
e error
|
||||
key = o._getKey()
|
||||
@@ -70,7 +70,7 @@ func (o *componentHttp) _registerMonitor(err liberr.CodeError) liberr.Error {
|
||||
}
|
||||
|
||||
if mon, e = o._newMonitor(vrs); e != nil {
|
||||
return err.ErrorParent(e)
|
||||
return err.Error(e)
|
||||
} else if mon == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -84,9 +84,9 @@ func (o *componentHttp) _registerMonitor(err liberr.CodeError) liberr.Error {
|
||||
}
|
||||
|
||||
if e = m.Restart(ctx()); e != nil {
|
||||
return err.ErrorParent(e)
|
||||
return err.Error(e)
|
||||
} else if e = o._setMonitor(m); e != nil {
|
||||
return err.ErrorParent(e)
|
||||
return err.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,7 +28,6 @@ package ldap
|
||||
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
lbldap "github.com/nabbar/golib/ldap"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -138,7 +137,7 @@ func (o *componentLDAP) _getFctEvt(key uint8) cfgtps.FuncCptEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentLDAP) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error {
|
||||
func (o *componentLDAP) _runFct(fct func(cpt cfgtps.Component) error) error {
|
||||
if fct != nil {
|
||||
return fct(o)
|
||||
}
|
||||
@@ -146,10 +145,10 @@ func (o *componentLDAP) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentLDAP) _runCli() liberr.Error {
|
||||
func (o *componentLDAP) _runCli() error {
|
||||
var (
|
||||
e error
|
||||
err liberr.Error
|
||||
err error
|
||||
cli *lbldap.HelperLDAP
|
||||
cfg *lbldap.Config
|
||||
)
|
||||
@@ -160,7 +159,7 @@ func (o *componentLDAP) _runCli() liberr.Error {
|
||||
if cfg, err = o._getConfig(); err != nil {
|
||||
return ErrorParamInvalid.Error(err)
|
||||
} else if cli, e = lbldap.NewLDAP(o.x.GetContext(), cfg, o.a); e != nil {
|
||||
return ErrorConfigInvalid.ErrorParent(e)
|
||||
return ErrorConfigInvalid.Error(e)
|
||||
} else {
|
||||
cli.SetLogger(o.getLogger)
|
||||
}
|
||||
@@ -179,7 +178,7 @@ func (o *componentLDAP) _runCli() liberr.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentLDAP) _run() liberr.Error {
|
||||
func (o *componentLDAP) _run() error {
|
||||
fb, fa := o._getFct()
|
||||
|
||||
if err := o._runFct(fb); err != nil {
|
||||
|
@@ -29,7 +29,6 @@ package ldap
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -95,11 +94,11 @@ func (o *componentLDAP) IsRunning() bool {
|
||||
return o.IsStarted()
|
||||
}
|
||||
|
||||
func (o *componentLDAP) Start() liberr.Error {
|
||||
func (o *componentLDAP) Start() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
func (o *componentLDAP) Reload() liberr.Error {
|
||||
func (o *componentLDAP) Reload() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
@@ -134,7 +133,7 @@ func (o *componentLDAP) Dependencies() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentLDAP) SetDependencies(d []string) liberr.Error {
|
||||
func (o *componentLDAP) SetDependencies(d []string) error {
|
||||
o.m.RLock()
|
||||
defer o.m.RUnlock()
|
||||
|
||||
|
@@ -27,7 +27,6 @@
|
||||
package ldap
|
||||
|
||||
import (
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
lbldap "github.com/nabbar/golib/ldap"
|
||||
spfcbr "github.com/spf13/cobra"
|
||||
spfvpr "github.com/spf13/viper"
|
||||
@@ -37,12 +36,12 @@ func (o *componentLDAP) RegisterFlag(Command *spfcbr.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentLDAP) _getConfig() (*lbldap.Config, liberr.Error) {
|
||||
func (o *componentLDAP) _getConfig() (*lbldap.Config, error) {
|
||||
var (
|
||||
key string
|
||||
cfg lbldap.Config
|
||||
vpr *spfvpr.Viper
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if vpr = o._getSPFViper(); vpr == nil {
|
||||
@@ -52,7 +51,7 @@ func (o *componentLDAP) _getConfig() (*lbldap.Config, liberr.Error) {
|
||||
}
|
||||
|
||||
if e := vpr.UnmarshalKey(key, &cfg); e != nil {
|
||||
return nil, ErrorParamInvalid.ErrorParent(e)
|
||||
return nil, ErrorParamInvalid.Error(e)
|
||||
}
|
||||
|
||||
if err = cfg.Validate(); err != nil {
|
||||
|
@@ -28,7 +28,6 @@ package log
|
||||
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
logcfg "github.com/nabbar/golib/logger/config"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
@@ -139,7 +138,7 @@ func (o *componentLog) _getFctEvt(key uint8) cfgtps.FuncCptEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentLog) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error {
|
||||
func (o *componentLog) _runFct(fct func(cpt cfgtps.Component) error) error {
|
||||
if fct != nil {
|
||||
return fct(o)
|
||||
}
|
||||
@@ -147,10 +146,10 @@ func (o *componentLog) _runFct(fct func(cpt cfgtps.Component) liberr.Error) libe
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentLog) _runCli() liberr.Error {
|
||||
func (o *componentLog) _runCli() error {
|
||||
var (
|
||||
e error
|
||||
err liberr.Error
|
||||
err error
|
||||
prt = ErrorReloadLog
|
||||
cfg *logcfg.Options
|
||||
)
|
||||
@@ -174,13 +173,13 @@ func (o *componentLog) _runCli() liberr.Error {
|
||||
defer o.m.RUnlock()
|
||||
|
||||
if e = o.l.SetOptions(cfg); e != nil {
|
||||
return prt.ErrorParent(e)
|
||||
return prt.Error(e)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentLog) _run() liberr.Error {
|
||||
func (o *componentLog) _run() error {
|
||||
fb, fa := o._getFct()
|
||||
|
||||
if err := o._runFct(fb); err != nil {
|
||||
|
@@ -29,7 +29,6 @@ package log
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -95,11 +94,11 @@ func (o *componentLog) IsRunning() bool {
|
||||
return o.IsStarted()
|
||||
}
|
||||
|
||||
func (o *componentLog) Start() liberr.Error {
|
||||
func (o *componentLog) Start() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
func (o *componentLog) Reload() liberr.Error {
|
||||
func (o *componentLog) Reload() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
@@ -133,7 +132,7 @@ func (o *componentLog) Dependencies() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentLog) SetDependencies(d []string) liberr.Error {
|
||||
func (o *componentLog) SetDependencies(d []string) error {
|
||||
o.m.RLock()
|
||||
defer o.m.RUnlock()
|
||||
|
||||
|
@@ -27,7 +27,6 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
logcfg "github.com/nabbar/golib/logger/config"
|
||||
spfcbr "github.com/spf13/cobra"
|
||||
spfvpr "github.com/spf13/viper"
|
||||
@@ -70,12 +69,12 @@ func (o *componentLog) RegisterFlag(Command *spfcbr.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentLog) _getConfig() (*logcfg.Options, liberr.Error) {
|
||||
func (o *componentLog) _getConfig() (*logcfg.Options, error) {
|
||||
var (
|
||||
key string
|
||||
cfg logcfg.Options
|
||||
vpr *spfvpr.Viper
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if vpr = o._getSPFViper(); vpr == nil {
|
||||
@@ -85,7 +84,7 @@ func (o *componentLog) _getConfig() (*logcfg.Options, liberr.Error) {
|
||||
}
|
||||
|
||||
if e := vpr.UnmarshalKey(key, &cfg); e != nil {
|
||||
return nil, ErrorParamInvalid.ErrorParent(e)
|
||||
return nil, ErrorParamInvalid.Error(e)
|
||||
}
|
||||
|
||||
if cfg.Stdout == nil {
|
||||
|
@@ -32,7 +32,6 @@ import (
|
||||
libcfg "github.com/nabbar/golib/config"
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
logcfg "github.com/nabbar/golib/logger/config"
|
||||
logfld "github.com/nabbar/golib/logger/fields"
|
||||
@@ -54,7 +53,7 @@ type ComponentLog interface {
|
||||
SetField(fields logfld.Fields)
|
||||
GetField() logfld.Fields
|
||||
|
||||
SetOptions(opt *logcfg.Options) liberr.Error
|
||||
SetOptions(opt *logcfg.Options) error
|
||||
GetOptions() *logcfg.Options
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,6 @@ import (
|
||||
"sync"
|
||||
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
logcfg "github.com/nabbar/golib/logger/config"
|
||||
logfld "github.com/nabbar/golib/logger/fields"
|
||||
@@ -109,7 +108,7 @@ func (o *componentLog) GetOptions() *logcfg.Options {
|
||||
return o.l.GetOptions()
|
||||
}
|
||||
|
||||
func (o *componentLog) SetOptions(opt *logcfg.Options) liberr.Error {
|
||||
func (o *componentLog) SetOptions(opt *logcfg.Options) error {
|
||||
o.m.Lock()
|
||||
defer o.m.Unlock()
|
||||
|
||||
@@ -118,7 +117,7 @@ func (o *componentLog) SetOptions(opt *logcfg.Options) liberr.Error {
|
||||
}
|
||||
|
||||
if e := o.l.SetOptions(opt); e != nil {
|
||||
return ErrorConfigInvalid.ErrorParent(e)
|
||||
return ErrorConfigInvalid.Error(e)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -30,7 +30,6 @@ import (
|
||||
"context"
|
||||
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libmail "github.com/nabbar/golib/mail"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -147,7 +146,7 @@ func (o *componentMail) _getFctEvt(key uint8) cfgtps.FuncCptEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentMail) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error {
|
||||
func (o *componentMail) _runFct(fct func(cpt cfgtps.Component) error) error {
|
||||
if fct != nil {
|
||||
return fct(o)
|
||||
}
|
||||
@@ -155,9 +154,9 @@ func (o *componentMail) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentMail) _runCli() liberr.Error {
|
||||
func (o *componentMail) _runCli() error {
|
||||
var (
|
||||
err liberr.Error
|
||||
err error
|
||||
prt = ErrorComponentReload
|
||||
obj libmail.Mail
|
||||
cfg *libmail.Config
|
||||
@@ -182,7 +181,7 @@ func (o *componentMail) _runCli() liberr.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentMail) _run() liberr.Error {
|
||||
func (o *componentMail) _run() error {
|
||||
fb, fa := o._getFct()
|
||||
|
||||
if err := o._runFct(fb); err != nil {
|
||||
|
@@ -29,7 +29,6 @@ package mail
|
||||
import (
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
libver "github.com/nabbar/golib/version"
|
||||
libvpr "github.com/nabbar/golib/viper"
|
||||
@@ -95,11 +94,11 @@ func (o *componentMail) IsRunning() bool {
|
||||
return o.IsStarted()
|
||||
}
|
||||
|
||||
func (o *componentMail) Start() liberr.Error {
|
||||
func (o *componentMail) Start() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
func (o *componentMail) Reload() liberr.Error {
|
||||
func (o *componentMail) Reload() error {
|
||||
return o._run()
|
||||
}
|
||||
|
||||
@@ -132,7 +131,7 @@ func (o *componentMail) Dependencies() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *componentMail) SetDependencies(d []string) liberr.Error {
|
||||
func (o *componentMail) SetDependencies(d []string) error {
|
||||
o.m.RLock()
|
||||
defer o.m.RUnlock()
|
||||
|
||||
|
@@ -27,7 +27,6 @@
|
||||
package mail
|
||||
|
||||
import (
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libmail "github.com/nabbar/golib/mail"
|
||||
spfcbr "github.com/spf13/cobra"
|
||||
spfvpr "github.com/spf13/viper"
|
||||
@@ -78,12 +77,12 @@ func (o *componentMail) RegisterFlag(Command *spfcbr.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *componentMail) _getConfig() (*libmail.Config, liberr.Error) {
|
||||
func (o *componentMail) _getConfig() (*libmail.Config, error) {
|
||||
var (
|
||||
key string
|
||||
cfg libmail.Config
|
||||
vpr *spfvpr.Viper
|
||||
err liberr.Error
|
||||
err error
|
||||
)
|
||||
|
||||
if vpr = o._getSPFViper(); vpr == nil {
|
||||
@@ -93,7 +92,7 @@ func (o *componentMail) _getConfig() (*libmail.Config, liberr.Error) {
|
||||
}
|
||||
|
||||
if e := vpr.UnmarshalKey(key, &cfg); e != nil {
|
||||
return nil, ErrorParamInvalid.ErrorParent(e)
|
||||
return nil, ErrorParamInvalid.Error(e)
|
||||
}
|
||||
|
||||
if len(cfg.Headers) < 1 {
|
||||
|
@@ -32,14 +32,13 @@ import (
|
||||
libcfg "github.com/nabbar/golib/config"
|
||||
cfgtps "github.com/nabbar/golib/config/types"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
libmail "github.com/nabbar/golib/mail"
|
||||
)
|
||||
|
||||
type ComponentMail interface {
|
||||
cfgtps.Component
|
||||
|
||||
GetMail() (libmail.Mail, liberr.Error)
|
||||
GetMail() (libmail.Mail, error)
|
||||
}
|
||||
|
||||
func New(ctx libctx.FuncContext) ComponentMail {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user