Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
itsCheithanya committed Jun 28, 2023
1 parent 043dae1 commit aa3a1a8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 61 deletions.
1 change: 1 addition & 0 deletions plugins/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func DockerCLI() schema.Executable {
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
needsauth.ForCommand("login", "push", "pull"),
),
Uses: []schema.CredentialUsage{
{
Expand Down
13 changes: 6 additions & 7 deletions plugins/docker/user_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ func UserLogin() schema.CredentialType {
Secret: true,
},
},
DefaultProvisioner: provision.TempFile(dockerConfig, provision.AddArgs("--config={{ .Path }}")),

Importer: importer.TryAll(TryDockerConfigFile()),
DefaultProvisioner: provision.TempFile(dockerConfig, provision.AtFixedPath("~/.docker/config.json")),
Importer: importer.TryAll(TryDockerConfigFile()),
}
}

Expand All @@ -52,10 +51,10 @@ func dockerConfig(in sdk.ProvisionInput) ([]byte, error) {
return []byte(content), nil
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"DOCKER_USERNAME": fieldname.Username,
"DOCKER_PASSWORD": fieldname.Password,
}
// var defaultEnvVarMapping = map[string]sdk.FieldName{
// "DOCKER_USERNAME": fieldname.Username,
// "DOCKER_PASSWORD": fieldname.Password,
// }

func TryDockerConfigFile() sdk.Importer {
return importer.TryFile("~/.docker/config.json", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
Expand Down
108 changes: 54 additions & 54 deletions plugins/docker/user_login_test.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
package docker
// package docker

import (
"testing"
// import (
// "testing"

"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/plugintest"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)
// "github.com/1Password/shell-plugins/sdk"
// "github.com/1Password/shell-plugins/sdk/plugintest"
// "github.com/1Password/shell-plugins/sdk/schema/fieldname"
// )

func TestUserLoginProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, UserLogin().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.Username: "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
fieldname.Password: "12345",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"DOCKER_USERNAME": "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
"DOCKER_PASSWORD": "12345",
},
},
},
})
}
// func TestUserLoginProvisioner(t *testing.T) {
// plugintest.TestProvisioner(t, UserLogin().DefaultProvisioner, map[string]plugintest.ProvisionCase{
// "default": {
// ItemFields: map[sdk.FieldName]string{
// fieldname.Username: "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
// fieldname.Password: "12345",
// },
// ExpectedOutput: sdk.ProvisionOutput{
// Environment: map[string]string{
// "DOCKER_USERNAME": "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
// "DOCKER_PASSWORD": "12345",
// },
// },
// },
// })
// }

func TestUserLoginImporter(t *testing.T) {
plugintest.TestImporter(t, UserLogin().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{
"DOCKER_USERNAME": "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
"DOCKER_PASSWORD": "12345",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Username: "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
fieldname.Password: "12345",
},
},
},
},
// func TestUserLoginImporter(t *testing.T) {
// plugintest.TestImporter(t, UserLogin().Importer, map[string]plugintest.ImportCase{
// "environment": {
// Environment: map[string]string{
// "DOCKER_USERNAME": "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
// "DOCKER_PASSWORD": "12345",
// },
// ExpectedCandidates: []sdk.ImportCandidate{
// {
// Fields: map[sdk.FieldName]string{
// fieldname.Username: "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
// fieldname.Password: "12345",
// },
// },
// },
// },

"config file": {
Files: map[string]string{
"~/.docker/config.json": plugintest.LoadFixture(t, "config.json"),
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Username: "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
fieldname.Password: "12345",
},
},
},
},
})
}
// "config file": {
// Files: map[string]string{
// "~/.docker/config.json": plugintest.LoadFixture(t, "config.json"),
// },
// ExpectedCandidates: []sdk.ImportCandidate{
// {
// Fields: map[sdk.FieldName]string{
// fieldname.Username: "4LjPnJ2u4Yo02KRfP7ffF1Tf2eoDZxnvNEXAMPLE",
// fieldname.Password: "12345",
// },
// },
// },
// },
// })
// }

0 comments on commit aa3a1a8

Please sign in to comment.