candidate.go 853 B

1234567891011121314151617181920212223242526272829
  1. package forms
  2. import (
  3. "github.com/porter-dev/porter/internal/kubernetes"
  4. "github.com/porter-dev/porter/internal/models"
  5. )
  6. // CreateServiceAccountCandidatesForm represents the accepted values for
  7. // creating a list of ServiceAccountCandidates from a kubeconfig
  8. type CreateServiceAccountCandidatesForm struct {
  9. ProjectID uint `json:"project_id"`
  10. Kubeconfig string `json:"kubeconfig"`
  11. }
  12. // ToServiceAccountCandidates creates a ServiceAccountCandidate from the kubeconfig and
  13. // project id
  14. func (csa *CreateServiceAccountCandidatesForm) ToServiceAccountCandidates() ([]*models.ServiceAccountCandidate, error) {
  15. candidates, err := kubernetes.GetServiceAccountCandidates([]byte(csa.Kubeconfig))
  16. if err != nil {
  17. return nil, err
  18. }
  19. for _, saCandidate := range candidates {
  20. saCandidate.ProjectID = csa.ProjectID
  21. }
  22. return candidates, nil
  23. }