registry.go 916 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package docker
  2. import (
  3. "context"
  4. "fmt"
  5. fw "git.buran.team/main/fairwind"
  6. moby "github.com/moby/moby/client"
  7. )
  8. type Registry struct {
  9. ctx context.Context
  10. log *fw.Log
  11. client *Docker
  12. address string
  13. login string
  14. password string
  15. }
  16. func NewRegistry(ctx context.Context, log *fw.Log, client *Docker, address string, login string, password string) *Registry {
  17. return &Registry{
  18. ctx: ctx,
  19. log: log,
  20. client: client,
  21. address: address,
  22. login: login,
  23. password: password,
  24. }
  25. }
  26. func (this *Registry) Address() string {
  27. return this.address
  28. }
  29. func (this *Registry) Authorize() error {
  30. _, err := this.client.Docker.RegistryLogin(
  31. this.ctx,
  32. moby.RegistryLoginOptions{
  33. ServerAddress: this.address,
  34. Username: this.login,
  35. Password: this.password,
  36. },
  37. )
  38. if err != nil {
  39. return fmt.Errorf("can't authorize in registry: %w", err)
  40. }
  41. return nil
  42. }