Skip to content

Commit

Permalink
imported configfile struct instead of redefining, updated test
Browse files Browse the repository at this point in the history
  • Loading branch information
kiryl1 committed Jun 29, 2023
1 parent e6bc698 commit e9a9036
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
32 changes: 3 additions & 29 deletions pkg/dependency/credhelper/cred_helper_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,10 @@ import (
"github.com/runfinch/finch/pkg/dependency"
"github.com/runfinch/finch/pkg/flog"
"github.com/runfinch/finch/pkg/path"

"github.com/docker/cli/cli/config/configfile"
)

// ConfigFile is taken from https://github.com/docker/cli/blob/master/cli/config/configfile/file.go
type ConfigFile struct {
AuthConfigs map[string]interface{} `json:"auths,omitempty"`
HTTPHeaders map[string]string `json:"HttpHeaders,omitempty"`
PsFormat string `json:"psFormat,omitempty"`
ImagesFormat string `json:"imagesFormat,omitempty"`
NetworksFormat string `json:"networksFormat,omitempty"`
PluginsFormat string `json:"pluginsFormat,omitempty"`
VolumesFormat string `json:"volumesFormat,omitempty"`
StatsFormat string `json:"statsFormat,omitempty"`
DetachKeys string `json:"detachKeys,omitempty"`
CredentialsStore string `json:"credsStore,omitempty"`
CredentialHelpers map[string]string `json:"credHelpers,omitempty"`
Filename string `json:"-"` // Note: for internal use only
ServiceInspectFormat string `json:"serviceInspectFormat,omitempty"`
ServicesFormat string `json:"servicesFormat,omitempty"`
TasksFormat string `json:"tasksFormat,omitempty"`
SecretFormat string `json:"secretFormat,omitempty"`
ConfigFormat string `json:"configFormat,omitempty"`
NodesFormat string `json:"nodesFormat,omitempty"`
PruneFilters []string `json:"pruneFilters,omitempty"`
Proxies map[string]interface{} `json:"proxies,omitempty"`
Experimental string `json:"experimental,omitempty"`
CurrentContext string `json:"currentContext,omitempty"`
CLIPluginsExtraDirs []string `json:"cliPluginsExtraDirs,omitempty"`
Plugins map[string]map[string]string `json:"plugins,omitempty"`
Aliases map[string]string `json:"aliases,omitempty"`
}
type binaries struct {
fp path.Finch
fs afero.Fs
Expand Down Expand Up @@ -101,7 +75,7 @@ func updateConfigFile(bin *binaries) error {
if err != nil {
return err
}
var cfg ConfigFile
var cfg configfile.ConfigFile
err = json.Unmarshal(bytes, &cfg)
if err != nil {
return err
Expand Down
4 changes: 1 addition & 3 deletions pkg/dependency/credhelper/cred_helper_binary_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Ensures that the binaries required for networking are installed in a privileged location.
// More information here: https://github.com/lima-vm/socket_vmnet
package credhelper

import (
Expand Down Expand Up @@ -105,7 +103,7 @@ func Test_updateConfigFile(t *testing.T) {
postRunCheck: func(t *testing.T, fs afero.Fs) {
fileBytes, err := afero.ReadFile(fs, "mock_prefix/.finch/config.json")
require.NoError(t, err)
JSONstr := fmt.Sprintf("{\"credsStore\":\"%s\"}", "binary")
JSONstr := fmt.Sprintf("{\"auths\":null,\"credsStore\":\"%s\"}", "binary")
fileData := []byte(JSONstr)
assert.Equal(t, fileData, fileBytes)

Expand Down

0 comments on commit e9a9036

Please sign in to comment.