From e6efbc195bc253da5b213d2ea21cb1c1da5f72bd Mon Sep 17 00:00:00 2001 From: Boris Manojlovic Date: Fri, 23 Mar 2018 00:10:11 +0100 Subject: [PATCH 1/6] ported code to go language --- .gitmodules | 4 +- .../GitSvnAuthManager.csproj | 0 .../GitSvnAuthManager.sln | 0 git-svn-auth-manager-mono/Makefile | 79 +++++++ .../README.rst | 0 .../config-full | 0 .../config-just-enough | 0 .../mail-sample.txt | 0 .../sqlcipher | 0 .../src/AssemblyInfo.cs | 0 .../src/Config.cs | 0 .../src/EmailSender.cs | 0 .../src/EncryptedSQLiteDb.cs | 0 .../src/EncryptedUserRepository.cs | 0 .../src/GitSvnAuthManager.cs | 0 .../src/Main.cs | 0 .../src/Options.cs | 0 .../src/SQLiteNativeMethods.cs | 0 .../src/SQLiteTypeAffinity.cs | 0 .../src/User.cs | 0 git-svn-auth-manager/LICENSE | 202 +++++++++++++++++ git-svn-auth-manager/Makefile | 81 +------ git-svn-auth-manager/README.md | 136 ++++++++++++ git-svn-auth-manager/cmd/config.go | 40 ++++ git-svn-auth-manager/cmd/root.go | 206 ++++++++++++++++++ git-svn-auth-manager/config_full.yml | 13 ++ git-svn-auth-manager/db/db.go | 118 ++++++++++ git-svn-auth-manager/encryption/encryption.go | 47 ++++ git-svn-auth-manager/golang.mk | 84 +++++++ git-svn-auth-manager/main.go | 21 ++ git-svn-auth-manager/utils/utils.go | 58 +++++ 31 files changed, 1009 insertions(+), 80 deletions(-) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/GitSvnAuthManager.csproj (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/GitSvnAuthManager.sln (100%) create mode 100644 git-svn-auth-manager-mono/Makefile rename {git-svn-auth-manager => git-svn-auth-manager-mono}/README.rst (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/config-full (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/config-just-enough (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/mail-sample.txt (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/sqlcipher (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/AssemblyInfo.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/Config.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/EmailSender.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/EncryptedSQLiteDb.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/EncryptedUserRepository.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/GitSvnAuthManager.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/Main.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/Options.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/SQLiteNativeMethods.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/SQLiteTypeAffinity.cs (100%) rename {git-svn-auth-manager => git-svn-auth-manager-mono}/src/User.cs (100%) create mode 100644 git-svn-auth-manager/LICENSE create mode 100644 git-svn-auth-manager/README.md create mode 100644 git-svn-auth-manager/cmd/config.go create mode 100644 git-svn-auth-manager/cmd/root.go create mode 100644 git-svn-auth-manager/config_full.yml create mode 100644 git-svn-auth-manager/db/db.go create mode 100644 git-svn-auth-manager/encryption/encryption.go create mode 100644 git-svn-auth-manager/golang.mk create mode 100644 git-svn-auth-manager/main.go create mode 100644 git-svn-auth-manager/utils/utils.go diff --git a/.gitmodules b/.gitmodules index 01362ad..ffbfd20 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "git-svn-auth-manager/sqlcipher"] - path = git-svn-auth-manager/sqlcipher +[submodule "git-svn-auth-manager-mono/sqlcipher"] + path = git-svn-auth-manager-mono/sqlcipher url = git://github.com/sqlcipher/sqlcipher.git diff --git a/git-svn-auth-manager/GitSvnAuthManager.csproj b/git-svn-auth-manager-mono/GitSvnAuthManager.csproj similarity index 100% rename from git-svn-auth-manager/GitSvnAuthManager.csproj rename to git-svn-auth-manager-mono/GitSvnAuthManager.csproj diff --git a/git-svn-auth-manager/GitSvnAuthManager.sln b/git-svn-auth-manager-mono/GitSvnAuthManager.sln similarity index 100% rename from git-svn-auth-manager/GitSvnAuthManager.sln rename to git-svn-auth-manager-mono/GitSvnAuthManager.sln diff --git a/git-svn-auth-manager-mono/Makefile b/git-svn-auth-manager-mono/Makefile new file mode 100644 index 0000000..801ac40 --- /dev/null +++ b/git-svn-auth-manager-mono/Makefile @@ -0,0 +1,79 @@ +BINDIR = bin +OBJDIR = obj +TARGETNAME = git-svn-auth-manager + +TARGET = $(BINDIR)/$(TARGETNAME) + +# Creates a bundled binary and links SQLCipher statically into it +# +# See http://github.com/mrts/mono-static-linking for explanations +# and Mac build instructions. + +# C# application +CSHARPC = dmcs +CSHARPEXECUTABLE = $(OBJDIR)/GitSvnAuthManager.exe +CSHARPREFERENCES = /r:System.dll /r:System.Data.dll /r:System.Configuration.dll +CSHARPFLAGS = /nologo /warn:4 /optimize+ /codepage:utf8 /t:exe \ + /define:WITH_STATICALLY_LINKED_SQLCIPHER_SQLITE +CHARPSRC = $(wildcard src/*.cs) + +# mkbundle +CC = cc +CFLAGS = -Wall -s -O2 -Wl,-O1 +GENERATEDSRC = $(OBJDIR)/hello-gen.c +BUNDLEOBJS = $(OBJDIR)/hello-bundles.o + +# SQLCipher C library +SQLCIPHERDIR = sqlcipher +SQLCIPHERLIB = $(SQLCIPHERDIR)/.libs/libsqlite3.a +SQLCIPHERCONFIGFLAGS = --enable-tempstore=yes \ + CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_ENABLE_COLUMN_METADATA" \ + LDFLAGS="-lcrypto" + +# targets + +all: $(TARGET) + +$(TARGET): $(GENERATEDSRC) $(SQLCIPHERLIB) | $(BINDIR) + $(CC) -o $(TARGET) $(CFLAGS) $(GENERATEDSRC) \ + -rdynamic \ + -Wl,-whole-archive \ + $(SQLCIPHERLIB) \ + -Wl,-no-whole-archive \ + $(BUNDLEOBJS) \ + `pkg-config --cflags --libs mono-2` \ + `pkg-config --libs openssl` + +$(GENERATEDSRC): $(CSHARPEXECUTABLE) + mkbundle -c -o $(GENERATEDSRC) -oo $(BUNDLEOBJS) $(CSHARPEXECUTABLE) + +$(SQLCIPHERLIB): $(SQLCIPHERDIR)/Makefile + cd $(SQLCIPHERDIR); \ + make -j 4 + +$(SQLCIPHERDIR)/Makefile: $(SQLCIPHERDIR)/configure + cd $(SQLCIPHERDIR); \ + ./configure $(SQLCIPHERCONFIGFLAGS) + +$(CSHARPEXECUTABLE): $(CHARPSRC) | $(OBJDIR) + $(CSHARPC) "/out:$(CSHARPEXECUTABLE)" \ + $(CSHARPREFERENCES) $(CSHARPFLAGS) $(CHARPSRC) + +install: $(TARGET) + install -m 711 -D $(TARGET) ~/bin/$(TARGETNAME) + +install_config: install + install -m 600 -D config-just-enough ~/.config/$(TARGETNAME)/config + +$(OBJDIR): + mkdir -p $(OBJDIR) + +$(BINDIR): + mkdir -p $(BINDIR) + +clean: + rm -rf $(OBJDIR) $(BINDIR) + +mrproper: clean + rm -f ~/.config/$(TARGETNAME)/userinfo.db + cd $(SQLCIPHERDIR); git clean -fdx diff --git a/git-svn-auth-manager/README.rst b/git-svn-auth-manager-mono/README.rst similarity index 100% rename from git-svn-auth-manager/README.rst rename to git-svn-auth-manager-mono/README.rst diff --git a/git-svn-auth-manager/config-full b/git-svn-auth-manager-mono/config-full similarity index 100% rename from git-svn-auth-manager/config-full rename to git-svn-auth-manager-mono/config-full diff --git a/git-svn-auth-manager/config-just-enough b/git-svn-auth-manager-mono/config-just-enough similarity index 100% rename from git-svn-auth-manager/config-just-enough rename to git-svn-auth-manager-mono/config-just-enough diff --git a/git-svn-auth-manager/mail-sample.txt b/git-svn-auth-manager-mono/mail-sample.txt similarity index 100% rename from git-svn-auth-manager/mail-sample.txt rename to git-svn-auth-manager-mono/mail-sample.txt diff --git a/git-svn-auth-manager/sqlcipher b/git-svn-auth-manager-mono/sqlcipher similarity index 100% rename from git-svn-auth-manager/sqlcipher rename to git-svn-auth-manager-mono/sqlcipher diff --git a/git-svn-auth-manager/src/AssemblyInfo.cs b/git-svn-auth-manager-mono/src/AssemblyInfo.cs similarity index 100% rename from git-svn-auth-manager/src/AssemblyInfo.cs rename to git-svn-auth-manager-mono/src/AssemblyInfo.cs diff --git a/git-svn-auth-manager/src/Config.cs b/git-svn-auth-manager-mono/src/Config.cs similarity index 100% rename from git-svn-auth-manager/src/Config.cs rename to git-svn-auth-manager-mono/src/Config.cs diff --git a/git-svn-auth-manager/src/EmailSender.cs b/git-svn-auth-manager-mono/src/EmailSender.cs similarity index 100% rename from git-svn-auth-manager/src/EmailSender.cs rename to git-svn-auth-manager-mono/src/EmailSender.cs diff --git a/git-svn-auth-manager/src/EncryptedSQLiteDb.cs b/git-svn-auth-manager-mono/src/EncryptedSQLiteDb.cs similarity index 100% rename from git-svn-auth-manager/src/EncryptedSQLiteDb.cs rename to git-svn-auth-manager-mono/src/EncryptedSQLiteDb.cs diff --git a/git-svn-auth-manager/src/EncryptedUserRepository.cs b/git-svn-auth-manager-mono/src/EncryptedUserRepository.cs similarity index 100% rename from git-svn-auth-manager/src/EncryptedUserRepository.cs rename to git-svn-auth-manager-mono/src/EncryptedUserRepository.cs diff --git a/git-svn-auth-manager/src/GitSvnAuthManager.cs b/git-svn-auth-manager-mono/src/GitSvnAuthManager.cs similarity index 100% rename from git-svn-auth-manager/src/GitSvnAuthManager.cs rename to git-svn-auth-manager-mono/src/GitSvnAuthManager.cs diff --git a/git-svn-auth-manager/src/Main.cs b/git-svn-auth-manager-mono/src/Main.cs similarity index 100% rename from git-svn-auth-manager/src/Main.cs rename to git-svn-auth-manager-mono/src/Main.cs diff --git a/git-svn-auth-manager/src/Options.cs b/git-svn-auth-manager-mono/src/Options.cs similarity index 100% rename from git-svn-auth-manager/src/Options.cs rename to git-svn-auth-manager-mono/src/Options.cs diff --git a/git-svn-auth-manager/src/SQLiteNativeMethods.cs b/git-svn-auth-manager-mono/src/SQLiteNativeMethods.cs similarity index 100% rename from git-svn-auth-manager/src/SQLiteNativeMethods.cs rename to git-svn-auth-manager-mono/src/SQLiteNativeMethods.cs diff --git a/git-svn-auth-manager/src/SQLiteTypeAffinity.cs b/git-svn-auth-manager-mono/src/SQLiteTypeAffinity.cs similarity index 100% rename from git-svn-auth-manager/src/SQLiteTypeAffinity.cs rename to git-svn-auth-manager-mono/src/SQLiteTypeAffinity.cs diff --git a/git-svn-auth-manager/src/User.cs b/git-svn-auth-manager-mono/src/User.cs similarity index 100% rename from git-svn-auth-manager/src/User.cs rename to git-svn-auth-manager-mono/src/User.cs diff --git a/git-svn-auth-manager/LICENSE b/git-svn-auth-manager/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/git-svn-auth-manager/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/git-svn-auth-manager/Makefile b/git-svn-auth-manager/Makefile index 801ac40..388559d 100644 --- a/git-svn-auth-manager/Makefile +++ b/git-svn-auth-manager/Makefile @@ -1,79 +1,4 @@ -BINDIR = bin -OBJDIR = obj -TARGETNAME = git-svn-auth-manager +PACKAGE=github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager -TARGET = $(BINDIR)/$(TARGETNAME) - -# Creates a bundled binary and links SQLCipher statically into it -# -# See http://github.com/mrts/mono-static-linking for explanations -# and Mac build instructions. - -# C# application -CSHARPC = dmcs -CSHARPEXECUTABLE = $(OBJDIR)/GitSvnAuthManager.exe -CSHARPREFERENCES = /r:System.dll /r:System.Data.dll /r:System.Configuration.dll -CSHARPFLAGS = /nologo /warn:4 /optimize+ /codepage:utf8 /t:exe \ - /define:WITH_STATICALLY_LINKED_SQLCIPHER_SQLITE -CHARPSRC = $(wildcard src/*.cs) - -# mkbundle -CC = cc -CFLAGS = -Wall -s -O2 -Wl,-O1 -GENERATEDSRC = $(OBJDIR)/hello-gen.c -BUNDLEOBJS = $(OBJDIR)/hello-bundles.o - -# SQLCipher C library -SQLCIPHERDIR = sqlcipher -SQLCIPHERLIB = $(SQLCIPHERDIR)/.libs/libsqlite3.a -SQLCIPHERCONFIGFLAGS = --enable-tempstore=yes \ - CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_ENABLE_COLUMN_METADATA" \ - LDFLAGS="-lcrypto" - -# targets - -all: $(TARGET) - -$(TARGET): $(GENERATEDSRC) $(SQLCIPHERLIB) | $(BINDIR) - $(CC) -o $(TARGET) $(CFLAGS) $(GENERATEDSRC) \ - -rdynamic \ - -Wl,-whole-archive \ - $(SQLCIPHERLIB) \ - -Wl,-no-whole-archive \ - $(BUNDLEOBJS) \ - `pkg-config --cflags --libs mono-2` \ - `pkg-config --libs openssl` - -$(GENERATEDSRC): $(CSHARPEXECUTABLE) - mkbundle -c -o $(GENERATEDSRC) -oo $(BUNDLEOBJS) $(CSHARPEXECUTABLE) - -$(SQLCIPHERLIB): $(SQLCIPHERDIR)/Makefile - cd $(SQLCIPHERDIR); \ - make -j 4 - -$(SQLCIPHERDIR)/Makefile: $(SQLCIPHERDIR)/configure - cd $(SQLCIPHERDIR); \ - ./configure $(SQLCIPHERCONFIGFLAGS) - -$(CSHARPEXECUTABLE): $(CHARPSRC) | $(OBJDIR) - $(CSHARPC) "/out:$(CSHARPEXECUTABLE)" \ - $(CSHARPREFERENCES) $(CSHARPFLAGS) $(CHARPSRC) - -install: $(TARGET) - install -m 711 -D $(TARGET) ~/bin/$(TARGETNAME) - -install_config: install - install -m 600 -D config-just-enough ~/.config/$(TARGETNAME)/config - -$(OBJDIR): - mkdir -p $(OBJDIR) - -$(BINDIR): - mkdir -p $(BINDIR) - -clean: - rm -rf $(OBJDIR) $(BINDIR) - -mrproper: clean - rm -f ~/.config/$(TARGETNAME)/userinfo.db - cd $(SQLCIPHERDIR); git clean -fdx +ADDITIONAL_LDFLAGS=-s -w +include golang.mk diff --git a/git-svn-auth-manager/README.md b/git-svn-auth-manager/README.md new file mode 100644 index 0000000..8525178 --- /dev/null +++ b/git-svn-auth-manager/README.md @@ -0,0 +1,136 @@ +git/Subversion authentication and user information manager +========================================================== + +Helper utility for running a git-SVN bridge. + +- Manages SVN authentication for git +- User mapping between git and SVN +- Keeps data in an encrypted database +- Sends email notifications when SVN authentication fails + +Database is in: + + ~/.config/git-svn-auth-manager/userinfo.db + +Usage +----- + +Run either with a single non-option argument to output user +name and email suitable for `git --authors-prog` + + git-svn-auth-manager USERNAME + +or with a single option to invoke option-specific behaviour: +``` +git-svn-auth-manager +Provides mapping between git and svn repository users + +Usage: + git-svn-auth-manager [flags] + git-svn-auth-manager [command] + +Available Commands: + config set parameters + help Help about any command + +Flags: + -a, --add-user string Add user information to the database + -p, --change-passwd-for string Change user's password in the database + -c, --config-file string Config file location + -h, --help help for git-svn-auth-manager + -r, --reset-auth-for string Reset SVN auth cache with user's credentials; SVN URL required as non-option argument + +Use "git-svn-auth-manager [command] --help" for more information about a command. +``` + +Building +-------- + +As this software is written in golang you can run: +``` +go get github.com/bmanojlovic/git-svn-bridge/tree/master/git-svn-auth-manager +``` + +**Change key**, build: + +``` + $ cd git-svn-bridge/git-svn-auth-manager/GitSvnAuthManager + $ ENCRYPTION_KEY=`tr -dc '[:alnum:]' < /dev/urandom | head -c 32` + $ sed -i "s/@KEY000000000000000000000000KEY@/$ENCRYPTION_KEY/" encryption/encryption.go + $ make + $ cp git-svn-auth-manager ~/bin/git-svn-auth-manager + ``` + + +Security +-------- + +Database is encrypted. + +As encryption key is embedded in `git-svn-auth-manager`, it needs to be owned +by root and be made execute-only: + +``` + $ sudo chown root: git-svn-auth-manager + $ chmod 711 git-svn-auth-manager +``` + +Configuration +------------- + +Config is in: + + ~/.config/git-svn-auth-manager/config.yml + +Configuration settings (from `git-svn-auth-manager -h`): + + svn_auth_dir: SVN authentication cache folder + (default: ${HOME}/.subversion/auth) + + db_filename: encrypted user info database location + (default: ${ApplicationData}/git-svn-auth-manager/userinfo.db, + ${ApplicationData} is ${HOME}/.config in Linux) + + mail_sending_enabled: if "true", send error mails to users + when `svn info` fails (default: false); + if mail_sending_enabled is true, + the following additional settings apply: + + smtp_username: SMTP username (NO DEFAULT) + + smtp_password: SMTP password (NO DEFAULT) + + smtp_server_host: SMTP server host name (default: smtp.gmail.com) + + smtp_server_port: SMTP server port (default: 587) + + mail_from: mail From: header (default: ${smtp_username}) + + mail_subject: mail Subject: header + (default: built-in ${MAIL_SUBJECT_DEFAULT}) + + mail_body: mail message body, must have {}-placeholders for + user name, application name, SVN username and error message + (default: built-in ${MAIL_BODY_DEFAULT}) + + do_not_check_server_certificate: if "true", do not check SMTP + server certificate + (default: true, i.e. certificate is NOT checked) + + +See config_full.yml-full for a full sample or +config_full.yml-sensible for enabling mail sending (other settings +can be left to defaults if GMail is used). + +Mail sending +------------- + +See mail-sample.txt for the mail template that is used by default. + +Enable email notifications to users for *Subversion* authentication failures +(**substitute sed replacment strings with real GMail account data**): + +``` + $ sed -i 's/username@gmail.com/REAL_GMAIL_USER/' config_full.yml + $ sed -i 's/password/REAL_GMAIL_PASSWORD/' config_full.yml +``` \ No newline at end of file diff --git a/git-svn-auth-manager/cmd/config.go b/git-svn-auth-manager/cmd/config.go new file mode 100644 index 0000000..af94fa7 --- /dev/null +++ b/git-svn-auth-manager/cmd/config.go @@ -0,0 +1,40 @@ +// Copyright © 2018 Boris Manojlovc +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var setValue, getValue string + +// configCmd represents the config command +var configCmd = &cobra.Command{ + Use: "config", + Short: "set parameters", + Run: func(cmd *cobra.Command, args []string) { + // TODO... + fmt.Println("config called but not yet implemented!") + }, +} + +func init() { + rootCmd.AddCommand(configCmd) + // Using these flags you will change configuration parameters + configCmd.Flags().StringVarP(&setValue, "setvalue", "s", "", "Set parameter") + configCmd.Flags().StringVarP(&getValue, "getvalue", "g", "", "Set parameter") +} diff --git a/git-svn-auth-manager/cmd/root.go b/git-svn-auth-manager/cmd/root.go new file mode 100644 index 0000000..3ff5862 --- /dev/null +++ b/git-svn-auth-manager/cmd/root.go @@ -0,0 +1,206 @@ +// Copyright © 2018 Boris Manojlovic +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "crypto/tls" + "errors" + "fmt" + "os" + "os/exec" + "strconv" + "strings" + + db "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager/db" + utils "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager/utils" + homedir "github.com/mitchellh/go-homedir" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "gopkg.in/gomail.v2" +) + +var commandToExecute, home, flagConfigFile, flagUserToAdd, flagChangePwFor, flagresetAuthFor string + +var rootCmd = &cobra.Command{ + Use: "git-svn-auth-manager", + Short: "Provides mapping between git and svn repository users", + Args: cmdArgs, + Run: cmdRun, +} + +func cmdArgs(cmd *cobra.Command, args []string) error { + switch { + case flagUserToAdd != "": + return runAddUser() + case flagChangePwFor != "": + return runChangePw() + case flagresetAuthFor != "": + if len(args) != 1 { + return errors.New("subversion URL argument required") + } + return runResetAuthFor(args[0]) + case len(args) == 1: + svnUserToGitAuthor(args[0]) + return nil + default: + // we assume everything is parsed correctly so just show help + // to user by default when there is no flags or commands + return cmd.Help() + } +} + +func init() { + cobra.OnInitialize(initConfig) + rootCmd.PersistentFlags().StringVarP(&flagConfigFile, "config-file", "c", "", "Config file location") + rootCmd.Flags().StringVarP(&flagUserToAdd, "add-user", "a", "", "Add user information to the database") + rootCmd.Flags().StringVarP(&flagChangePwFor, "change-passwd-for", "p", "", "Change user's password in the database") + rootCmd.Flags().StringVarP(&flagresetAuthFor, "reset-auth-for", "r", "", "Reset SVN auth cache with user's credentials;"+ + " SVN URL required as non-option argument") +} + +// initConfig reads in config file and Connect to database +func initConfig() { + if flagConfigFile != "" { + // Use config file from the flag. + viper.SetConfigFile(flagConfigFile) + } else { + // Find home directory. + home, err := homedir.Dir() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + // Search config in home directory with name "config" (without extension). + // viper.AddConfigPath(home) + viper.AddConfigPath(home + "/.config/git-svn-auth-manager/") + viper.SetConfigName("config") + } + viper.SetConfigType("yaml") + viper.AutomaticEnv() // read in environment variables that match + + // If a config file is found, read it in. + err := viper.ReadInConfig() + if err != nil { + fmt.Println("Error Using config file:", viper.ConfigFileUsed()) + fmt.Println(err) + } + // try connecting to database + db.Connect(viper.GetString("configuration.appSettings.db_filename")) +} + +func cmdRun(cmd *cobra.Command, args []string) { +} + +// runAddUser adds or modify user in database +func runAddUser() error { + var err error + var answer string + user := db.GITSVNUser{} + fromDB := db.GetByUserName(flagUserToAdd) + if strings.Compare(fromDB.SVNUsername, flagUserToAdd) == 0 { + if answer, err = utils.ReadDataFromTerminal("User "+flagUserToAdd+" already exist do you want to update it? [y/n]", ""); answer != "y" { + log.Infoln("User data unchanged") + os.Exit(0) + } + } + user.SVNUsername = flagUserToAdd + user.Name, err = utils.ReadDataFromTerminal("Name and Lastname", fromDB.Name) + if err != nil { + log.Fatalln(err) + } + user.Email, err = utils.ReadDataFromTerminal("Email", fromDB.Email) + if err != nil { + log.Fatalln(err) + } + user.SVNPassword, err = utils.ReadPasswordFromTerminal() + if err != nil { + log.Fatalln(err) + } + user.SVNUsername = flagUserToAdd + + db.UpSertUserData(&user) + return nil +} + +// runChangePw change SVN user password +func runChangePw() error { + var err error + fromDB := db.GetByUserName(flagChangePwFor) + log.Debugf("%+v\n", fromDB) + if strings.Compare(flagChangePwFor, fromDB.SVNUsername) == 0 { + fromDB.SVNPassword, err = utils.ReadPasswordFromTerminal() + if err == nil { + db.UpSertUserData(&fromDB) + return nil + } + return err + } + return errors.New("No such user in database") + +} + +// runResetAuthFor is used to update subversion authentication cache +func runResetAuthFor(urlSVN string) error { + var promptUser, promptPass string + u := db.GetByUserName(flagresetAuthFor) + if strings.Compare(u.SVNUsername, flagresetAuthFor) != 0 { + return errors.New("No such user in DB") + } + promptUser = "--username=" + u.SVNUsername + promptPass = "--password=" + u.SVNPassword + svnInfo := exec.Command("svn", "info", promptUser, promptPass, urlSVN) + output, err := svnInfo.CombinedOutput() + if err != nil { + body := strings.Replace(viper.GetString("configuration.appSettings.mail_body"), "{0}", u.Name, -1) + body = strings.Replace(body, "{1}", os.Args[0], -1) + body = strings.Replace(body, "{2}", u.SVNUsername, -1) + body = strings.Replace(body, "{3}", fmt.Sprint(svnInfo.Stderr), -1) + m := gomail.NewMessage() + m.SetHeader("From", viper.GetString("configuration.appSettings.mail_from")) + m.SetHeader("To", u.Email) + m.SetHeader("Subject", viper.GetString("configuration.appSettings.mail_subject")) + m.SetBody("text/plain", body) + portNum, _ := strconv.Atoi(viper.GetString("configuration.appSettings.smtp_server_port")) + tlsVerify, _ := strconv.ParseBool(viper.GetString("configuration.appSettings.do_not_check_server_certificate")) + d := gomail.Dialer{Host: viper.GetString("configuration.appSettings.smtp_server_host"), Port: portNum} + d.TLSConfig = &tls.Config{InsecureSkipVerify: tlsVerify} + if err := d.DialAndSend(m); err != nil { + log.Fatal(err) + } + log.Error(svnInfo.Stderr) + return nil + } + log.Debugln(output) + return nil + +} + +// Execute adds all child commands to the root command and sets flags appropriately. +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func svnUserToGitAuthor(svnuser string) error { + if u := db.GetByUserName(svnuser); len(u.SVNUsername) != 0 { + fmt.Printf("%s <%s>\n", u.Name, u.Email) + return nil + } + log.Fatalln("User " + svnuser + " does not exist in DB") + return nil // not reached but required +} diff --git a/git-svn-auth-manager/config_full.yml b/git-svn-auth-manager/config_full.yml new file mode 100644 index 0000000..0294e83 --- /dev/null +++ b/git-svn-auth-manager/config_full.yml @@ -0,0 +1,13 @@ +configuration: + appSettings: + svn_auth_dir: "/home/git-svn-bridge/.subversion/auth" + db_filename: "/home/git-svn-bridge/.config/git-svn-auth-manager/userinfo.db" + do_not_check_server_certificate: true + mail_sending_enabled: false + smtp_username: "username@gmail.com" + smtp_password: "password" + smtp_server_host: "smtp.gmail.com" + smtp_server_port: 587 + mail_from: "username@gmail.com" + mail_subject: "[git-svn-auth-manager] SVN ACCESS ERROR" + mail_body: "Hi {0}! \nAn error occurred while accessing SVN with your credentials. Either your credentials are wrong or the SVN repository is down. If your password has changed, then please update it with \n{1} --change-passwd-for {2} \nin the git-svn bridge host or ask for help from the person who manages it. \nDetails: \n--- \n{3} \n--- \nBest, {1}" \ No newline at end of file diff --git a/git-svn-auth-manager/db/db.go b/git-svn-auth-manager/db/db.go new file mode 100644 index 0000000..7393697 --- /dev/null +++ b/git-svn-auth-manager/db/db.go @@ -0,0 +1,118 @@ +package db + +import ( + "database/sql" + "strings" + + enc "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager/encryption" + log "github.com/sirupsen/logrus" + + _ "github.com/mattn/go-sqlite3" //sqlite3 importing into main namespace +) + +// GITSVNUser struct represent mapping for SQLite record +type GITSVNUser struct { + SVNUsername string + Email string + Name string + SVNPassword string +} + +// Decrypt data in GITSVNUser struct +func (u *GITSVNUser) Decrypt() { + u.SVNUsername = enc.Decrypt(u.SVNUsername) + u.Email = enc.Decrypt(u.Email) + u.Name = enc.Decrypt(u.Name) + u.SVNPassword = enc.Decrypt(u.SVNPassword) +} + +// DDLGitSvnBridge user schema for git-svn-bridge +var DDLGitSvnBridge = `CREATE TABLE IF NOT EXISTS user ( + svn_username TEXT UNIQUE NOT NULL, + email TEXT UNIQUE NOT NULL, + name TEXT NOT NULL, + svn_password TEXT NOT NULL +)` + +// PSUpSertUserData prepared statement for adding and changing user data +var PSUpSertUserData = `INSERT OR REPLACE INTO user ( + svn_username, + email, + name, + svn_password +) VALUES (?, ?, ?, ?)` + +// PSGetUserData is prepared statement for getting data by email or svn_userename +var PSGetUserData = `SELECT * FROM user WHERE @@BY@@ = ?` + +// DBHandle is database handle +var DBHandle *sql.DB + +// DBError last DB error +var DBError error +var rows *sql.Rows +var res sql.Result + +// Connect should be called first so it will create +// database file and initial schema if missing +func Connect(dbName string) bool { + DBHandle, DBError = sql.Open("sqlite3", dbName) + if DBError != nil { + log.Fatal(DBError) + } + res, DBError = DBHandle.Exec(DDLGitSvnBridge) + if DBError != nil { + log.Printf("%q: %s\n", DBError, DDLGitSvnBridge) + return false + } + log.Debugf("Connect: %+v\n", res) + return true +} + +// UpSertUserData is used to add/replace user data... +func UpSertUserData(u *GITSVNUser) { + stmt, DBError := DBHandle.Prepare(PSUpSertUserData) + if DBError != nil { + log.Fatal(DBError) + } + defer stmt.Close() + res, DBError = stmt.Exec(enc.Encrypt(u.SVNUsername), enc.Encrypt(u.Email), enc.Encrypt(u.Name), enc.Encrypt(u.SVNPassword)) + if DBError != nil { + log.Fatal(DBError) + } + log.Debugf("Data struct %+v\n", u) +} + +// GetByUserName select user details from DB by UserName +func GetByUserName(name string) GITSVNUser { + return getData("svn_username", name) +} + +// GetByEmail select user details from DB by Email +func GetByEmail(name string) GITSVNUser { + return getData("email", name) +} + +func getData(by, item string) GITSVNUser { + var u GITSVNUser + stmt, DBError := DBHandle.Prepare(strings.Replace(PSGetUserData, "@@BY@@", by, 1)) // this string replacement is safe as it is controlled by us + if DBError != nil { + log.Fatal(DBError) + } + defer stmt.Close() + rows, DBError = stmt.Query(enc.Encrypt(item)) + if DBError != nil { + log.Fatal(DBError) + } + for rows.Next() { + DBError = rows.Scan(&u.SVNUsername, &u.Email, &u.Name, &u.SVNPassword) + if DBError != nil { + log.Fatal(DBError) + } + } + if u.SVNUsername == "" { + return GITSVNUser{} + } + u.Decrypt() + return u +} diff --git a/git-svn-auth-manager/encryption/encryption.go b/git-svn-auth-manager/encryption/encryption.go new file mode 100644 index 0000000..3677ab7 --- /dev/null +++ b/git-svn-auth-manager/encryption/encryption.go @@ -0,0 +1,47 @@ +package encryption + +import ( + "crypto/aes" + "crypto/cipher" + "encoding/hex" +) + +var key = []byte("@KEY000000000000000000000000KEY@") +var nonce = []byte("000000000000") // 12 x "0" + +// Encrypt encrypts values based on key defined elsewhere +func Encrypt(data string) string { + plaintext := []byte(data) + + block, err := aes.NewCipher(key) + if err != nil { + panic(err.Error()) + } + + gcm, err := cipher.NewGCM(block) + if err != nil { + panic(err.Error()) + } + return hex.EncodeToString(gcm.Seal(nil, nonce, plaintext, nil)) +} + +// Decrypt decrypts values based on key defined elsewhere +func Decrypt(data string) string { + ciphertext, _ := hex.DecodeString(data) + + block, err := aes.NewCipher(key) + if err != nil { + panic(err.Error()) + } + + gcm, err := cipher.NewGCM(block) + if err != nil { + panic(err.Error()) + } + + plaintext, err := gcm.Open(nil, nonce, ciphertext, nil) + if err != nil { + panic(err.Error()) + } + return string(plaintext) +} diff --git a/git-svn-auth-manager/golang.mk b/git-svn-auth-manager/golang.mk new file mode 100644 index 0000000..39239d0 --- /dev/null +++ b/git-svn-auth-manager/golang.mk @@ -0,0 +1,84 @@ +# Source: https://github.com/rebuy-de/golang-template +# Version: 2.0.2-snapshot +# Dependencies: +# * dep (https://github.com/golang/dep) +# * gocov (https://github.com/axw/gocov) +# * gocov-html (https://github.com/matm/gocov-html) + +NAME=$(notdir $(PACKAGE)) + +BUILD_VERSION=$(shell git describe --always --dirty --tags | tr '-' '.' ) +BUILD_DATE=$(shell date) +BUILD_HASH=$(shell git rev-parse HEAD) +BUILD_MACHINE=$(shell echo $$HOSTNAME) +BUILD_USER=$(shell whoami) +BUILD_ENVIRONMENT=$(BUILD_USER)@$(BUILD_MACHINE) + +BUILD_XDST=$(PACKAGE)/vendor/github.com/rebuy-de/rebuy-go-sdk/cmdutil +BUILD_FLAGS=-ldflags "\ + $(ADDITIONAL_LDFLAGS) \ + -X '$(BUILD_XDST).BuildName=$(NAME)' \ + -X '$(BUILD_XDST).BuildPackage=$(PACKAGE)' \ + -X '$(BUILD_XDST).BuildVersion=$(BUILD_VERSION)' \ + -X '$(BUILD_XDST).BuildDate=$(BUILD_DATE)' \ + -X '$(BUILD_XDST).BuildHash=$(BUILD_HASH)' \ + -X '$(BUILD_XDST).BuildEnvironment=$(BUILD_ENVIRONMENT)' \ +" + +GOFILES=$(shell find . -type f -name '*.go' -not -path "./vendor/*") +GOPKGS=$(shell go list ./...) + +default: build + +Gopkg.lock: Gopkg.toml + dep ensure + touch Gopkg.lock + +vendor: Gopkg.lock Gopkg.toml + dep ensure + touch vendor + +format: + gofmt -s -w $(GOFILES) + +vet: vendor + go vet $(GOPKGS) + +lint: + $(foreach pkg,$(GOPKGS),golint $(pkg);) + +test_gopath: + test $$(go list) = "$(PACKAGE)" + +test_packages: vendor + go test $(GOPKGS) + +test_format: + gofmt -s -l $(GOFILES) + +test: test_gopath test_format vet lint test_packages + +cov: + gocov test -v $(GOPKGS) \ + | gocov-html > coverage.html + +build: + go build \ + $(BUILD_FLAGS) \ + -o $(NAME)-$(BUILD_VERSION)-$(shell go env GOOS)-$(shell go env GOARCH)$(shell go env GOEXE) + ln -sf $(NAME)-$(BUILD_VERSION)-$(shell go env GOOS)-$(shell go env GOARCH)$(shell go env GOEXE) $(NAME)$(shell go env GOEXE) + +xc: + GOOS=linux GOARCH=amd64 make build + GOOS=darwin GOARCH=amd64 make build + GOOS=windows GOARCH=386 make build + GOOS=windows GOARCH=amd64 make build + +install: test + go install \ + $(BUILD_FLAGS) + +clean: + rm -f $(NAME)* + +.PHONY: build install test diff --git a/git-svn-auth-manager/main.go b/git-svn-auth-manager/main.go new file mode 100644 index 0000000..36b6f5e --- /dev/null +++ b/git-svn-auth-manager/main.go @@ -0,0 +1,21 @@ +// Copyright © 2018 NAME HERE +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager/cmd" + +func main() { + cmd.Execute() +} diff --git a/git-svn-auth-manager/utils/utils.go b/git-svn-auth-manager/utils/utils.go new file mode 100644 index 0000000..75629c3 --- /dev/null +++ b/git-svn-auth-manager/utils/utils.go @@ -0,0 +1,58 @@ +package utils + +import ( + "bufio" + "bytes" + "errors" + "fmt" + "log" + "os" + + "golang.org/x/crypto/ssh/terminal" +) + +// ReadPasswordFromTerminal is used to read password and verify its value or return +// error on missmatch +func ReadPasswordFromTerminal() (string, error) { + fmt.Print("Enter Password: ") + password, err := terminal.ReadPassword(0) + if err != nil { + log.Fatal(err) + os.Exit(1) + } + fmt.Println() + fmt.Print("Verify Password: ") + passwordVerify, err := terminal.ReadPassword(0) + if err != nil { + log.Fatal(err) + os.Exit(1) + } + fmt.Println() + if bytes.Equal(password, passwordVerify) { + return string(password), nil + } + return "", errors.New("Passwords do not match") + +} + +// ReadDataFromTerminal is used to read data from terminal +// with provided text as prompt +func ReadDataFromTerminal(input, original string) (string, error) { + var prompt string + if len(original) > 0 { + prompt = fmt.Sprintf("Enter %s [%s]: ", input, original) + } else { + prompt = fmt.Sprintf("Enter %s: ", input) + } + fmt.Print(prompt) + reader := bufio.NewReader(os.Stdin) + text, _, err := reader.ReadLine() + if err != nil { + log.Fatalf("Error on reading %s...", prompt) + return "", err + } + if len(text) == 0 { + return original, nil + } + return string(text), nil +} From dce12f6892f2bf1462e0144fb8012eb8d265abe4 Mon Sep 17 00:00:00 2001 From: Boris Manojlovic Date: Fri, 23 Mar 2018 20:52:15 +0100 Subject: [PATCH 2/6] mv git-svn-auth-manager to git-svn-auth-manager-go --- {git-svn-auth-manager => git-svn-auth-manager-go}/LICENSE | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/Makefile | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/README.md | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/cmd/config.go | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/cmd/root.go | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/config_full.yml | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/db/db.go | 0 .../encryption/encryption.go | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/golang.mk | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/main.go | 0 {git-svn-auth-manager => git-svn-auth-manager-go}/utils/utils.go | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename {git-svn-auth-manager => git-svn-auth-manager-go}/LICENSE (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/Makefile (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/README.md (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/cmd/config.go (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/cmd/root.go (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/config_full.yml (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/db/db.go (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/encryption/encryption.go (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/golang.mk (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/main.go (100%) rename {git-svn-auth-manager => git-svn-auth-manager-go}/utils/utils.go (100%) diff --git a/git-svn-auth-manager/LICENSE b/git-svn-auth-manager-go/LICENSE similarity index 100% rename from git-svn-auth-manager/LICENSE rename to git-svn-auth-manager-go/LICENSE diff --git a/git-svn-auth-manager/Makefile b/git-svn-auth-manager-go/Makefile similarity index 100% rename from git-svn-auth-manager/Makefile rename to git-svn-auth-manager-go/Makefile diff --git a/git-svn-auth-manager/README.md b/git-svn-auth-manager-go/README.md similarity index 100% rename from git-svn-auth-manager/README.md rename to git-svn-auth-manager-go/README.md diff --git a/git-svn-auth-manager/cmd/config.go b/git-svn-auth-manager-go/cmd/config.go similarity index 100% rename from git-svn-auth-manager/cmd/config.go rename to git-svn-auth-manager-go/cmd/config.go diff --git a/git-svn-auth-manager/cmd/root.go b/git-svn-auth-manager-go/cmd/root.go similarity index 100% rename from git-svn-auth-manager/cmd/root.go rename to git-svn-auth-manager-go/cmd/root.go diff --git a/git-svn-auth-manager/config_full.yml b/git-svn-auth-manager-go/config_full.yml similarity index 100% rename from git-svn-auth-manager/config_full.yml rename to git-svn-auth-manager-go/config_full.yml diff --git a/git-svn-auth-manager/db/db.go b/git-svn-auth-manager-go/db/db.go similarity index 100% rename from git-svn-auth-manager/db/db.go rename to git-svn-auth-manager-go/db/db.go diff --git a/git-svn-auth-manager/encryption/encryption.go b/git-svn-auth-manager-go/encryption/encryption.go similarity index 100% rename from git-svn-auth-manager/encryption/encryption.go rename to git-svn-auth-manager-go/encryption/encryption.go diff --git a/git-svn-auth-manager/golang.mk b/git-svn-auth-manager-go/golang.mk similarity index 100% rename from git-svn-auth-manager/golang.mk rename to git-svn-auth-manager-go/golang.mk diff --git a/git-svn-auth-manager/main.go b/git-svn-auth-manager-go/main.go similarity index 100% rename from git-svn-auth-manager/main.go rename to git-svn-auth-manager-go/main.go diff --git a/git-svn-auth-manager/utils/utils.go b/git-svn-auth-manager-go/utils/utils.go similarity index 100% rename from git-svn-auth-manager/utils/utils.go rename to git-svn-auth-manager-go/utils/utils.go From dd34d8147e0381fd62b993e8e2222af0330fb31e Mon Sep 17 00:00:00 2001 From: Boris Manojlovic Date: Fri, 23 Mar 2018 20:56:48 +0100 Subject: [PATCH 3/6] change imports to renamed paths --- git-svn-auth-manager-go/Makefile | 2 +- git-svn-auth-manager-go/cmd/root.go | 4 ++-- git-svn-auth-manager-go/db/db.go | 2 +- git-svn-auth-manager-go/main.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/git-svn-auth-manager-go/Makefile b/git-svn-auth-manager-go/Makefile index 388559d..a1f18d8 100644 --- a/git-svn-auth-manager-go/Makefile +++ b/git-svn-auth-manager-go/Makefile @@ -1,4 +1,4 @@ -PACKAGE=github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager +PACKAGE=github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager-go ADDITIONAL_LDFLAGS=-s -w include golang.mk diff --git a/git-svn-auth-manager-go/cmd/root.go b/git-svn-auth-manager-go/cmd/root.go index 3ff5862..3b4e121 100644 --- a/git-svn-auth-manager-go/cmd/root.go +++ b/git-svn-auth-manager-go/cmd/root.go @@ -23,8 +23,8 @@ import ( "strconv" "strings" - db "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager/db" - utils "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager/utils" + db "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager-go/db" + utils "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager-go/utils" homedir "github.com/mitchellh/go-homedir" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/git-svn-auth-manager-go/db/db.go b/git-svn-auth-manager-go/db/db.go index 7393697..a17f022 100644 --- a/git-svn-auth-manager-go/db/db.go +++ b/git-svn-auth-manager-go/db/db.go @@ -4,7 +4,7 @@ import ( "database/sql" "strings" - enc "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager/encryption" + enc "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager-go/encryption" log "github.com/sirupsen/logrus" _ "github.com/mattn/go-sqlite3" //sqlite3 importing into main namespace diff --git a/git-svn-auth-manager-go/main.go b/git-svn-auth-manager-go/main.go index 36b6f5e..8cc25e6 100644 --- a/git-svn-auth-manager-go/main.go +++ b/git-svn-auth-manager-go/main.go @@ -14,7 +14,7 @@ package main -import "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager/cmd" +import "github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager-go/cmd" func main() { cmd.Execute() From f097c230c89e7e9cc29582630cf7d8d0740b5f3b Mon Sep 17 00:00:00 2001 From: Boris Manojlovic Date: Fri, 23 Mar 2018 21:14:41 +0100 Subject: [PATCH 4/6] update documentation in README.md --- git-svn-auth-manager-go/README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/git-svn-auth-manager-go/README.md b/git-svn-auth-manager-go/README.md index 8525178..ec5f720 100644 --- a/git-svn-auth-manager-go/README.md +++ b/git-svn-auth-manager-go/README.md @@ -48,17 +48,19 @@ Building As this software is written in golang you can run: ``` -go get github.com/bmanojlovic/git-svn-bridge/tree/master/git-svn-auth-manager +go get github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager-go ``` -**Change key**, build: +As step above already build package with default key please do re-build again with steps bellow + +**Change key**, build and install: ``` - $ cd git-svn-bridge/git-svn-auth-manager/GitSvnAuthManager + $ cd ~/go/src/github.com/bmanojlovic/git-svn-bridge/git-svn-auth-manager-go $ ENCRYPTION_KEY=`tr -dc '[:alnum:]' < /dev/urandom | head -c 32` $ sed -i "s/@KEY000000000000000000000000KEY@/$ENCRYPTION_KEY/" encryption/encryption.go - $ make - $ cp git-svn-auth-manager ~/bin/git-svn-auth-manager + $ make # or go build + $ cp git-svn-auth-manager-go ~/bin/git-svn-auth-manager ``` @@ -118,8 +120,8 @@ Configuration settings (from `git-svn-auth-manager -h`): (default: true, i.e. certificate is NOT checked) -See config_full.yml-full for a full sample or -config_full.yml-sensible for enabling mail sending (other settings +See config_full.yml for a full sample or +config_sensible.yml for enabling mail sending (other settings can be left to defaults if GMail is used). Mail sending From ff36d016eb5c2c798eb7711e6545b2bc304456ea Mon Sep 17 00:00:00 2001 From: Boris Manojlovic Date: Thu, 5 Apr 2018 16:01:17 +0200 Subject: [PATCH 5/6] added scripts to add multiple users should be incorporated into command --- git-svn-auth-manager-go/cmd/root.go | 2 ++ scripts/bridge-add-user.expect | 19 +++++++++++++++++++ scripts/bridge-add-user.sh | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100755 scripts/bridge-add-user.expect create mode 100755 scripts/bridge-add-user.sh diff --git a/git-svn-auth-manager-go/cmd/root.go b/git-svn-auth-manager-go/cmd/root.go index 3b4e121..17862ab 100644 --- a/git-svn-auth-manager-go/cmd/root.go +++ b/git-svn-auth-manager-go/cmd/root.go @@ -86,6 +86,8 @@ func initConfig() { // Search config in home directory with name "config" (without extension). // viper.AddConfigPath(home) viper.AddConfigPath(home + "/.config/git-svn-auth-manager/") + // if installed globally on system + viper.AddConfigPath("/etc/git-svn-auth-manager/") viper.SetConfigName("config") } viper.SetConfigType("yaml") diff --git a/scripts/bridge-add-user.expect b/scripts/bridge-add-user.expect new file mode 100755 index 0000000..60afc35 --- /dev/null +++ b/scripts/bridge-add-user.expect @@ -0,0 +1,19 @@ +#!/usr/bin/expect -f +set timeout -1 + +set username [lindex $argv 0]; +set password [lindex $argv 1]; +set name [lindex $argv 2]; +set email [lindex $argv 3]; + +spawn ./bin/git-svn-auth-manager -a $username +match_max 100000 +expect "Enter Name and Lastname: " +send -- "$name\r" +expect "Enter Email: " +send -- "$email\r" +expect "Enter Password: " +send -- "$password\r" +expect "Verify Password: " +send -- "$password\r" +expect eof diff --git a/scripts/bridge-add-user.sh b/scripts/bridge-add-user.sh new file mode 100755 index 0000000..576fa0c --- /dev/null +++ b/scripts/bridge-add-user.sh @@ -0,0 +1,11 @@ +#!/bin/sh +while read line; do + # Simply ignore lines starting with # + if [ $(echo $line |grep -c ^#) -eq 0 ];then + export U="$(echo $line|cut -d: -f1)" + export P="$(echo $line|cut -d: -f2)" + export N="$(echo $line|cut -d: -f3)" + export E="$(echo $line|cut -d: -f4)" + ./bridge-add-user.expect "$U" "$P" "$N" "$E" + fi +done < user-list.txt \ No newline at end of file From 8f4454207d19ee0dd38b8776fd97887cae4a244d Mon Sep 17 00:00:00 2001 From: Boris Manojlovic Date: Thu, 5 Apr 2018 16:05:58 +0200 Subject: [PATCH 6/6] assume scripts are install in path --- scripts/bridge-add-user.expect | 2 +- scripts/bridge-add-user.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/bridge-add-user.expect b/scripts/bridge-add-user.expect index 60afc35..024350d 100755 --- a/scripts/bridge-add-user.expect +++ b/scripts/bridge-add-user.expect @@ -6,7 +6,7 @@ set password [lindex $argv 1]; set name [lindex $argv 2]; set email [lindex $argv 3]; -spawn ./bin/git-svn-auth-manager -a $username +spawn git-svn-auth-manager -a $username match_max 100000 expect "Enter Name and Lastname: " send -- "$name\r" diff --git a/scripts/bridge-add-user.sh b/scripts/bridge-add-user.sh index 576fa0c..e05f159 100755 --- a/scripts/bridge-add-user.sh +++ b/scripts/bridge-add-user.sh @@ -6,6 +6,6 @@ while read line; do export P="$(echo $line|cut -d: -f2)" export N="$(echo $line|cut -d: -f3)" export E="$(echo $line|cut -d: -f4)" - ./bridge-add-user.expect "$U" "$P" "$N" "$E" + bridge-add-user.expect "$U" "$P" "$N" "$E" fi done < user-list.txt \ No newline at end of file