integration.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. GCPProjectID string `json:"gcp_project_id"`
  12. }
  13. // ToGCPIntegration converts the project to a gorm project model
  14. func (cgf *CreateGCPIntegrationForm) ToGCPIntegration() (*ints.GCPIntegration, error) {
  15. return &ints.GCPIntegration{
  16. UserID: cgf.UserID,
  17. ProjectID: cgf.ProjectID,
  18. GCPKeyData: []byte(cgf.GCPKeyData),
  19. GCPProjectID: cgf.GCPProjectID,
  20. }, nil
  21. }
  22. // CreateBasicAuthIntegrationForm represents the accepted values for creating a
  23. // basic auth integration
  24. type CreateBasicAuthIntegrationForm struct {
  25. UserID uint `json:"user_id" form:"required"`
  26. ProjectID uint `json:"project_id" form:"required"`
  27. Username string `json:"username"`
  28. Password string `json:"password"`
  29. }
  30. // ToBasicIntegration converts the project to a gorm project model
  31. func (cbf *CreateBasicAuthIntegrationForm) ToBasicIntegration() (*ints.BasicIntegration, error) {
  32. return &ints.BasicIntegration{
  33. UserID: cbf.UserID,
  34. ProjectID: cbf.ProjectID,
  35. Username: []byte(cbf.Username),
  36. Password: []byte(cbf.Password),
  37. }, nil
  38. }
  39. // CreateAWSIntegrationForm represents the accepted values for creating an
  40. // AWS Integration
  41. type CreateAWSIntegrationForm struct {
  42. UserID uint `json:"user_id" form:"required"`
  43. ProjectID uint `json:"project_id" form:"required"`
  44. AWSRegion string `json:"aws_region"`
  45. AWSClusterID string `json:"aws_cluster_id"`
  46. AWSAccessKeyID string `json:"aws_access_key_id"`
  47. AWSSecretAccessKey string `json:"aws_secret_access_key"`
  48. }
  49. // ToAWSIntegration converts the project to a gorm project model
  50. func (caf *CreateAWSIntegrationForm) ToAWSIntegration() (*ints.AWSIntegration, error) {
  51. return &ints.AWSIntegration{
  52. UserID: caf.UserID,
  53. ProjectID: caf.ProjectID,
  54. AWSRegion: caf.AWSRegion,
  55. AWSClusterID: []byte(caf.AWSClusterID),
  56. AWSAccessKeyID: []byte(caf.AWSAccessKeyID),
  57. AWSSecretAccessKey: []byte(caf.AWSSecretAccessKey),
  58. }, nil
  59. }