basic.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package integrations
  2. import "gorm.io/gorm"
  3. // BasicIntegration represents a basic auth mechanism via username/password
  4. type BasicIntegration struct {
  5. gorm.Model
  6. // The id of the user that linked this auth mechanism
  7. UserID uint `json:"user_id"`
  8. // The project that this integration belongs to
  9. ProjectID uint `json:"project_id"`
  10. // ------------------------------------------------------------------
  11. // All fields encrypted before storage.
  12. // ------------------------------------------------------------------
  13. // Username/Password for basic authentication to a cluster
  14. Username []byte `json:"username,omitempty"`
  15. Password []byte `json:"password,omitempty"`
  16. }
  17. // BasicIntegrationExternal is a BasicIntegration to be shared over REST
  18. type BasicIntegrationExternal struct {
  19. ID uint `json:"id"`
  20. // The id of the user that linked this auth mechanism
  21. UserID uint `json:"user_id"`
  22. // The project that this integration belongs to
  23. ProjectID uint `json:"project_id"`
  24. }
  25. // Externalize generates an external BasicIntegration to be shared over REST
  26. func (b *BasicIntegration) Externalize() *BasicIntegrationExternal {
  27. return &BasicIntegrationExternal{
  28. ID: b.ID,
  29. UserID: b.UserID,
  30. ProjectID: b.ProjectID,
  31. }
  32. }
  33. // ToProjectIntegration converts an oauth integration to a project integration
  34. func (b *BasicIntegration) ToProjectIntegration(
  35. category string,
  36. service IntegrationService,
  37. ) *ProjectIntegration {
  38. return &ProjectIntegration{
  39. ID: b.ID,
  40. ProjectID: b.ProjectID,
  41. AuthMechanism: "basic",
  42. Category: category,
  43. Service: service,
  44. }
  45. }