@@ -18,7 +18,7 @@ import (
1818 "context"
1919 "errors"
2020 "fmt"
21- "io/ioutil "
21+ "io"
2222 "os"
2323 "time"
2424
@@ -42,10 +42,26 @@ const defaultCommitMessage = "update secrets"
4242func init () {
4343 gitFlagSet = pflag .NewFlagSet ("git" , pflag .ContinueOnError )
4444 gitFlagSet .String ("git-url" , "" , "URL of the git repository (required)" )
45- gitFlagSet .String ("git-path" , "" , "path of the store in the repository (required)" )
46- gitFlagSet .String ("git-branch" , "" , "branch to checkout, commit and push to on updates" )
47- gitFlagSet .String ("git-checkout" , "" , "tree-ish revision to checkout, e.g. commit or tag" )
48- gitFlagSet .String ("git-message" , "" , "commit message when updating the store" )
45+ gitFlagSet .String (
46+ "git-path" ,
47+ "" ,
48+ "path of the store in the repository (required)" ,
49+ )
50+ gitFlagSet .String (
51+ "git-branch" ,
52+ "" ,
53+ "branch to checkout, commit and push to on updates" ,
54+ )
55+ gitFlagSet .String (
56+ "git-checkout" ,
57+ "" ,
58+ "tree-ish revision to checkout, e.g. commit or tag" ,
59+ )
60+ gitFlagSet .String (
61+ "git-message" ,
62+ "" ,
63+ "commit message when updating the store" ,
64+ )
4965}
5066
5167type gitBackend struct {
@@ -61,7 +77,10 @@ func (f gitFactory) New(conf map[string]interface{}) (Backend, error) {
6177 return f .NewContext (context .Background (), conf )
6278}
6379
64- func (f gitFactory ) NewContext (ctx context.Context , conf map [string ]interface {}) (Backend , error ) {
80+ func (f gitFactory ) NewContext (
81+ ctx context.Context ,
82+ conf map [string ]interface {},
83+ ) (Backend , error ) {
6584 return newGit (ctx , conf )
6685}
6786
@@ -90,7 +109,11 @@ func newGit(ctx context.Context, conf map[string]interface{}) (Backend, error) {
90109 }
91110 url , ok := opt .(string )
92111 if ! ok {
93- return nil , fmt .Errorf ("repository URL is not a string: (%T)%s" , opt , opt )
112+ return nil , fmt .Errorf (
113+ "repository URL is not a string: (%T)%s" ,
114+ opt ,
115+ opt ,
116+ )
94117 }
95118 logger = logger .WithField ("url" , url )
96119
@@ -163,6 +186,7 @@ func newGit(ctx context.Context, conf map[string]interface{}) (Backend, error) {
163186func (g gitBackend ) Exists () (bool , error ) {
164187 return g .ExistsContext (context .Background ())
165188}
189+
166190func (g gitBackend ) ExistsContext (ctx context.Context ) (bool , error ) {
167191 logger := getLogger (ctx )
168192
@@ -183,17 +207,18 @@ func (g gitBackend) ExistsContext(ctx context.Context) (bool, error) {
183207func (g gitBackend ) Save (data []byte ) error {
184208 return g .SaveContext (context .Background (), data )
185209}
210+
186211func (g gitBackend ) SaveContext (ctx context.Context , data []byte ) error {
187212 logger := getLogger (ctx )
188213
189214 logger = logger .WithField ("path" , g .path )
190215
191216 logger .Info ("opening file in git repository" )
192- f , err := g .fs .OpenFile (g .path , os .O_CREATE | os .O_TRUNC | os .O_RDWR , 0700 )
217+ f , err := g .fs .OpenFile (g .path , os .O_CREATE | os .O_TRUNC | os .O_RDWR , 0o700 )
193218 if err != nil {
194219 return err
195220 }
196- defer f .Close ()
221+ defer func () { _ = f .Close () } ()
197222
198223 logger .Info ("writing encrypted data to git repository" )
199224 n , err := f .Write (data )
@@ -232,7 +257,10 @@ func (g gitBackend) SaveContext(ctx context.Context, data []byte) error {
232257 }
233258
234259 logger .
235- WithField ("committer" , fmt .Sprintf ("%s <%s>" , authorCommitter .Name , authorCommitter .Email )).
260+ WithField (
261+ "committer" ,
262+ fmt .Sprintf ("%s <%s>" , authorCommitter .Name , authorCommitter .Email ),
263+ ).
236264 Infof ("committing changes to git repository: \" %s\" " , g .message )
237265 _ , err = w .Commit (
238266 g .message ,
@@ -259,6 +287,7 @@ func (g gitBackend) SaveContext(ctx context.Context, data []byte) error {
259287func (g gitBackend ) Load () ([]byte , error ) {
260288 return g .LoadContext (context .Background ())
261289}
290+
262291func (g gitBackend ) LoadContext (ctx context.Context ) ([]byte , error ) {
263292 logger := getLogger (ctx )
264293
@@ -270,9 +299,9 @@ func (g gitBackend) LoadContext(ctx context.Context) ([]byte, error) {
270299 if err != nil {
271300 return nil , err
272301 }
273- defer f .Close ()
302+ defer func () { _ = f .Close () } ()
274303
275- data , err := ioutil .ReadAll (f )
304+ data , err := io .ReadAll (f )
276305 if err != nil {
277306 return nil , err
278307 }
0 commit comments