| 442 | } |
| 443 | |
| 444 | func gitAuth(c client.Client, r *v1alpha1.Repository) (githttp.AuthMethod, error) { |
| 445 | switch r.Spec.Type { |
| 446 | case v1alpha1.RepositoryTypeGithub: |
| 447 | // get the secret |
| 448 | secret := &corev1.Secret{} |
| 449 | if err := c.Get(context.TODO(), client.ObjectKey{Name: r.Name, Namespace: r.Namespace}, secret); err != nil { |
| 450 | return nil, err |
| 451 | } |
| 452 | |
| 453 | tokenBytes, ok := secret.Data["token"] |
| 454 | if !ok { |
| 455 | return nil, errors.New("token not found in secret") |
| 456 | } |
| 457 | token := string(tokenBytes) |
| 458 | |
| 459 | return &githttp.BasicAuth{Username: "encoder-run", Password: token}, nil |
| 460 | default: |
| 461 | return nil, fmt.Errorf("unsupported repository type: %s", r.Spec.Type) |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | func postgresStorageStorer(c client.Client, s *v1alpha1.Storage, nsPrefix string) (storage.Storer, *gorm.DB, error) { |
| 466 | // get the password from the postgres secret |