-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
李昌
committed
Dec 15, 2024
1 parent
52dd5d7
commit 8263478
Showing
18 changed files
with
270 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ builds: | |
- amd64 | ||
- arm64 | ||
checksum: | ||
disable: true | ||
disable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
- id: pm | ||
main: . | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,14 @@ jobs: | |
- name: Install cross-compiler for linux/arm64 | ||
run: sudo apt-get install -y gcc-aarch64-linux-gnu | ||
|
||
- name: Set up git tag | ||
uses: devops-actions/[email protected] | ||
with: | ||
strip_v: false | ||
|
||
- name: Replace __VERSION__ in cmds/root.go | ||
run: sed -i "s/__VERSION__/${{ steps.get_tag.outputs.tag }}/" cmds/root.go | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
|
||
|
@@ -28,7 +36,7 @@ jobs: | |
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --config .github/workflows/.goreleaser-for-linux.yml | ||
args: release --skip=validate --config .github/workflows/.goreleaser-for-linux.yml | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GO_BUILD_TOKEN}} | ||
|
||
|
@@ -48,48 +56,25 @@ jobs: | |
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
# either 'goreleaser' (default) or 'goreleaser-pro' | ||
distribution: goreleaser | ||
version: latest | ||
args: release --config .github/workflows/.goreleaser-for-darwin.yml | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GO_BUILD_TOKEN}} | ||
|
||
- name: Upload assets | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: myapp | ||
path: dist/* | ||
|
||
release-windows-binary: | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up MinGW | ||
uses: egor-tensin/setup-mingw@v2 | ||
go-version: 1.23.1 # 指定 Go 版本 | ||
- name: Set up git tag | ||
uses: devops-actions/[email protected] | ||
with: | ||
platform: x64 | ||
version: 12.2.0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
strip_v: false | ||
|
||
- name: Replace __VERSION__ in cmds/root.go | ||
run: sed -i '' "s/__VERSION__/${{ steps.get_tag.outputs.tag }}/" cmds/root.go | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
# either 'goreleaser' (default) or 'goreleaser-pro' | ||
distribution: goreleaser | ||
version: latest | ||
args: release --config .github/workflows/.goreleaser-for-windows.yml | ||
args: release --skip=validate --config .github/workflows/.goreleaser-for-darwin.yml | ||
env: | ||
CGO_ENABLE: 1 | ||
GITHUB_TOKEN: ${{ secrets.GO_BUILD_TOKEN}} | ||
|
||
- name: Upload assets | ||
|
@@ -98,31 +83,3 @@ jobs: | |
name: myapp | ||
path: dist/* | ||
|
||
# goreleaser: | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: Checkout | ||
# uses: actions/checkout@v4 | ||
# with: | ||
# fetch-depth: 0 | ||
|
||
# - name: Set up Go | ||
# uses: actions/setup-go@v4 | ||
|
||
# - name: Run GoReleaser | ||
# uses: goreleaser/goreleaser-action@v5 | ||
# with: | ||
# # either 'goreleaser' (default) or 'goreleaser-pro' | ||
# distribution: goreleaser | ||
# version: latest | ||
# args: release --clean | ||
# env: | ||
# GITHUB_TOKEN: ${{ secrets.GO_BUILD_TOKEN}} | ||
# # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution | ||
# # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} | ||
|
||
# - name: Upload assets | ||
# uses: actions/upload-artifact@v3 | ||
# with: | ||
# name: myapp | ||
# path: myfolder/dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cmds | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/yangchnet/pm/config" | ||
) | ||
|
||
func ListCmd() *cobra.Command { | ||
var ( | ||
filterString string | ||
) | ||
var listCmd = &cobra.Command{ | ||
Use: "list [-f <filter_string>]", | ||
Short: "list passwd name", | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
config.InitConfig() | ||
|
||
service, err := NewService(cmd.Context()) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
if err := service.remote.Pull(cmd.Context()); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
service, err := NewService(cmd.Context()) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
passwds, err := service.store.SearchName(cmd.Context(), filterString) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("%18s| %18s| %18s| %18s|\n", "name", "account", "note", "url") | ||
fmt.Printf("%18s| %18s| %18s| %18s|\n", "-----", "-----", "-----", "-----") | ||
for _, passwd := range passwds { | ||
fmt.Printf("%18s| %18s| %18s| %18s|\n", passwd.Name, passwd.UserName, passwd.Note, passwd.Url) | ||
} | ||
|
||
}, | ||
} | ||
|
||
listCmd.Flags().StringVarP(&filterString, "filter", "f", "", "passwd filter string, default \"\"") | ||
|
||
return listCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package cmds | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/yangchnet/pm/config" | ||
"github.com/yangchnet/pm/store" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func UpdateCmd() *cobra.Command { | ||
var ( | ||
username string | ||
password string | ||
url string | ||
note string | ||
) | ||
var updateCmd = &cobra.Command{ | ||
Use: "update <password> [-u username -p password -l url -n note]", | ||
Short: "update passwd", | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
config.InitConfig() | ||
|
||
service, err := NewService(cmd.Context()) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
if err := service.remote.Pull(cmd.Context()); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
if len(args) < 1 { | ||
fmt.Println("必须执行密码名称!") | ||
os.Exit(1) | ||
} | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
service, err := NewService(cmd.Context()) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
passwd, err := service.store.Get(cmd.Context(), args[0]) | ||
if err != nil { | ||
if errors.Is(err, gorm.ErrRecordNotFound) { | ||
fmt.Printf("不存在的密码 [%s]", args[0]) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
|
||
if password != "" { | ||
primaryKey := GetPrimaryKey() | ||
passwd.CryptedPasswd, err = store.Encrypt(primaryKey, []byte(password)) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
if note != "" { | ||
passwd.Note = note | ||
} | ||
|
||
if url != "" { | ||
passwd.Url = url | ||
} | ||
|
||
if username != "" { | ||
passwd.UserName = username | ||
} | ||
|
||
fmt.Printf("note: %s; url: %s", note, url) | ||
|
||
err = service.store.Update(cmd.Context(), args[0], passwd) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
updateCmd.Flags().StringVarP(&username, "username", "u", "", "passwd username") | ||
updateCmd.Flags().StringVarP(&url, "url", "l", "", "passwd url") | ||
updateCmd.Flags().StringVarP(¬e, "note", "n", "", "passwd note") | ||
updateCmd.Flags().StringVarP(&password, "password", "p", "", "raw passwd") | ||
|
||
return updateCmd | ||
} |
Oops, something went wrong.