Skip to content

Commit

Permalink
return back Astro login
Browse files Browse the repository at this point in the history
  • Loading branch information
andriisoldatenko committed Jun 17, 2019
1 parent 168c013 commit b27b594
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions docker/docker.go
Expand Up @@ -7,13 +7,15 @@ import (
"os"
"os/exec"

"github.com/docker/docker/registry"

"github.com/docker/docker/pkg/jsonmessage"

clicommand "github.com/docker/cli/cli/command"
cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/docker/api/types"

//registrytypes "github.com/docker/docker/api/types/registry"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -87,36 +89,36 @@ func ExecPush(serverAddress, token, image string) error {

// ExecLogin executes a docker login similar to docker login command
func ExecLogin(serverAddress, username, token string) error {
//var response registrytypes.AuthenticateOKBody
//ctx := context.Background()
//
//cli, err := client.NewClientWithOpts(client.FromEnv)
//if err != nil {
// panic(err)
//}
//
//// Remove http|https from serverAddress
//serverAddress = registry.ConvertToHostname(serverAddress)
//
//authConfig := &types.AuthConfig{
// ServerAddress: serverAddress,
// Username: username,
// RegistryToken: token,
//}

//response, _ = cli.RegistryLogin(ctx, types.AuthConfig(*authConfig))

//configFile := cliconfig.LoadDefaultConfigFile(os.Stderr)

//creds := configFile.GetCredentialsStore(serverAddress)

//if err := creds.Store(*authConfig); err != nil {
// return errors.Errorf("Error saving credentials: %v", err)
//}

//if response.Status != "" {
// return errors.Errorf("Error saving credentials: %v", response.Status)
//}
var response registrytypes.AuthenticateOKBody
ctx := context.Background()

cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
panic(err)
}

// Remove http|https from serverAddress
serverAddress = registry.ConvertToHostname(serverAddress)

authConfig := &types.AuthConfig{
ServerAddress: serverAddress,
Username: username,
RegistryToken: token,
}

response, _ = cli.RegistryLogin(ctx, types.AuthConfig(*authConfig))

configFile := cliconfig.LoadDefaultConfigFile(os.Stderr)

creds := configFile.GetCredentialsStore(serverAddress)

if err := creds.Store(*authConfig); err != nil {
return errors.Errorf("Error saving credentials: %v", err)
}

if response.Status != "" {
return errors.Errorf("Error saving credentials: %v", response.Status)
}

return nil
}
Expand Down

0 comments on commit b27b594

Please sign in to comment.