File tree Expand file tree Collapse file tree
internal/core/services/registry Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package cmd
22
33import (
4+ "fmt"
5+
46 "github.com/highcard-dev/daemon/internal/core/domain"
7+ "github.com/highcard-dev/daemon/internal/core/services/registry"
58 "github.com/spf13/cobra"
69 "github.com/spf13/viper"
710)
@@ -21,6 +24,13 @@ Examples:
2124 druid registry login --host artifacts.druid.gg/project1 -u user1 -p pass1
2225 druid registry login --host artifacts.druid.gg/project2 -u user2 -p pass2` ,
2326 RunE : func (cmd * cobra.Command , args []string ) error {
27+
28+ if err := registry .ValidateCredentials (registryHost , registryUser , registryPassword ); err != nil {
29+ return fmt .Errorf ("login failed: %w" , err )
30+ }
31+
32+ cmd .Println ("Login succeeded" )
33+
2434 var registries []domain.RegistryCredential
2535 viper .UnmarshalKey ("registries" , & registries )
2636
Original file line number Diff line number Diff line change @@ -81,6 +81,30 @@ func extractHost(repoUrl string) string {
8181 return repoUrl
8282}
8383
84+ func ValidateCredentials (host , username , password string ) error {
85+ registryHost := extractHost (host )
86+
87+ reg , err := remote .NewRegistry (registryHost )
88+ if err != nil {
89+ return fmt .Errorf ("invalid registry host: %w" , err )
90+ }
91+
92+ reg .Client = & auth.Client {
93+ Client : retry .DefaultClient ,
94+ Cache : auth .DefaultCache ,
95+ Credential : auth .StaticCredential (registryHost , auth.Credential {
96+ Username : username ,
97+ Password : password ,
98+ }),
99+ }
100+
101+ if err := reg .Ping (context .Background ()); err != nil {
102+ return fmt .Errorf ("authentication failed: %w" , err )
103+ }
104+
105+ return nil
106+ }
107+
84108func (c * OciClient ) Pull (dir string , artifact string ) error {
85109 return c .PullSelective (dir , artifact , true , nil )
86110}
You can’t perform that action at this time.
0 commit comments