integration.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package forms
  2. import (
  3. ints "github.com/porter-dev/porter/internal/models/integrations"
  4. )
  5. // CreateGCPIntegrationForm represents the accepted values for creating a
  6. // GCP Integration
  7. type CreateGCPIntegrationForm struct {
  8. UserID uint `json:"user_id" form:"required"`
  9. ProjectID uint `json:"project_id" form:"required"`
  10. GCPKeyData string `json:"gcp_key_data" form:"required"`
  11. }
  12. // ToGCPIntegration converts the project to a gorm project model
  13. func (cgf *CreateGCPIntegrationForm) ToGCPIntegration() (*ints.GCPIntegration, error) {
  14. return &ints.GCPIntegration{
  15. UserID: cgf.UserID,
  16. ProjectID: cgf.ProjectID,
  17. GCPKeyData: []byte(cgf.GCPKeyData),
  18. }, nil
  19. }
  20. // CreateBasicAuthIntegrationForm represents the accepted values for creating a
  21. // basic auth integration
  22. type CreateBasicAuthIntegrationForm struct {
  23. UserID uint `json:"user_id" form:"required"`
  24. ProjectID uint `json:"project_id" form:"required"`
  25. Username string `json:"username"`
  26. Password string `json:"password"`
  27. }
  28. // ToBasicIntegration converts the project to a gorm project model
  29. func (cbf *CreateBasicAuthIntegrationForm) ToBasicIntegration() (*ints.BasicIntegration, error) {
  30. return &ints.BasicIntegration{
  31. UserID: cbf.UserID,
  32. ProjectID: cbf.ProjectID,
  33. Username: []byte(cbf.Username),
  34. Password: []byte(cbf.Password),
  35. }, nil
  36. }
  37. // CreateAWSIntegrationForm represents the accepted values for creating an
  38. // AWS Integration
  39. type CreateAWSIntegrationForm struct {
  40. UserID uint `json:"user_id" form:"required"`
  41. ProjectID uint `json:"project_id" form:"required"`
  42. AWSRegion string `json:"aws_region"`
  43. AWSClusterID string `json:"aws_cluster_id"`
  44. AWSAccessKeyID string `json:"aws_access_key_id"`
  45. AWSSecretAccessKey string `json:"aws_secret_access_key"`
  46. }
  47. // ToAWSIntegration converts the project to a gorm project model
  48. func (caf *CreateAWSIntegrationForm) ToAWSIntegration() (*ints.AWSIntegration, error) {
  49. return &ints.AWSIntegration{
  50. UserID: caf.UserID,
  51. ProjectID: caf.ProjectID,
  52. AWSRegion: caf.AWSRegion,
  53. AWSClusterID: []byte(caf.AWSClusterID),
  54. AWSAccessKeyID: []byte(caf.AWSAccessKeyID),
  55. AWSSecretAccessKey: []byte(caf.AWSSecretAccessKey),
  56. }, nil
  57. }