Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-crypt-module #101

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: golangci-lint
on:
push:
branches: [ "main" ]
branches:
- main
- master
pull_request:
branches: [ "main" ]

permissions:
contents: read
Expand All @@ -22,4 +23,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
version: v1.60
90 changes: 0 additions & 90 deletions app/crypt/crypt.go

This file was deleted.

50 changes: 0 additions & 50 deletions app/crypt/crypt_key.go

This file was deleted.

14 changes: 0 additions & 14 deletions app/crypt/decrypt.go

This file was deleted.

12 changes: 0 additions & 12 deletions app/crypt/encrypt.go

This file was deleted.

73 changes: 60 additions & 13 deletions app/json/crypt.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,76 @@
package json

import (
"ssh+/app/crypt"
"ssh+/app/output"

"github.com/spf13/viper"
"github.com/ssh-connection-manager/crypt"
)

func SetCryptData(c Connect) Connect {
c.Alias = crypt.Encrypt(c.Alias)
c.Address = crypt.Encrypt(c.Address)
c.Login = crypt.Encrypt(c.Login)
c.Password = crypt.Encrypt(c.Password)
var err error

pathConf := viper.GetString("FullPathConfig")
fileNameKey := viper.GetString("NameFileCryptKey")

c.CreatedAt = crypt.Encrypt(c.CreatedAt)
c.UpdatedAt = crypt.Encrypt(c.UpdatedAt)
c.Alias, err = crypt.Encrypt(c.Alias, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.Address, err = crypt.Encrypt(c.Address, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.Login, err = crypt.Encrypt(c.Login, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.Password, err = crypt.Encrypt(c.Password, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.CreatedAt, err = crypt.Encrypt(c.CreatedAt, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.UpdatedAt, err = crypt.Encrypt(c.UpdatedAt, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}

return c
}

func decryptData(c Connect) Connect {
c.Alias = crypt.Decrypt(c.Alias)
c.Address = crypt.Decrypt(c.Address)
c.Login = crypt.Decrypt(c.Login)
c.Password = crypt.Decrypt(c.Password)
var err error

c.CreatedAt = crypt.Decrypt(c.CreatedAt)
c.UpdatedAt = crypt.Decrypt(c.UpdatedAt)
pathConf := viper.GetString("FullPathConfig")
fileNameKey := viper.GetString("NameFileCryptKey")

c.Alias, err = crypt.Decrypt(c.Alias, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.Address, err = crypt.Decrypt(c.Address, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.Login, err = crypt.Decrypt(c.Login, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.Password, err = crypt.Decrypt(c.Password, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.CreatedAt, err = crypt.Decrypt(c.CreatedAt, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}
c.UpdatedAt, err = crypt.Decrypt(c.UpdatedAt, pathConf, fileNameKey)
if err != nil {
output.GetOutError("err crypt data")
}

return c
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ssh-connection-manager/crypt v1.0.2 // indirect
github.com/ssh-connection-manager/time v1.0.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/ssh-connection-manager/crypt v1.0.1 h1:TKWmqgypv2C2mMyYJ8kSjtK96p1rnnyjzIkrQAp8dzQ=
github.com/ssh-connection-manager/crypt v1.0.1/go.mod h1:q58XdwFONc12YHMN8LjbZK+G3cdes7fvatidwjegq1s=
github.com/ssh-connection-manager/crypt v1.0.2 h1:/caPrJ5X8hwVqqeVtuu2Mj6BnO4csjYnmbiOVQ1Fchc=
github.com/ssh-connection-manager/crypt v1.0.2/go.mod h1:q58XdwFONc12YHMN8LjbZK+G3cdes7fvatidwjegq1s=
github.com/ssh-connection-manager/file v1.0.1 h1:t0bWe/WlYx/00i1zoO7ABL51oyB+7r1GlU4pktdVM0c=
github.com/ssh-connection-manager/file v1.0.1/go.mod h1:v6ohozxsgX7s4ze2Vy4sesNBaJ9pcJG0aOmqgffJenA=
github.com/ssh-connection-manager/time v1.0.0 h1:pGTqenPyDymD489mNcsUbICSBihZpl7yWEnNIICZLfA=
Expand Down
13 changes: 11 additions & 2 deletions inits/inits.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package inits

import (
"ssh+/app/crypt"
"github.com/spf13/viper"
"ssh+/app/json"
"ssh+/app/output"
"ssh+/config"

"github.com/ssh-connection-manager/crypt"
)

func generateConfigFile() {
Expand All @@ -15,7 +18,13 @@ func createFileConnects() {
}

func generateCryptKey() {
crypt.GenerateKey()
pathConf := viper.GetString("FullPathConfig")
fileNameKey := viper.GetString("NameFileCryptKey")

err := crypt.GenerateKey(pathConf, fileNameKey)
if err != nil {
output.GetOutError("err generate key")
}
}

func SetDependencies() {
Expand Down
Loading