action.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package models
  2. import "gorm.io/gorm"
  3. // Action names
  4. const (
  5. ClusterCADataAction string = "upload-cluster-ca-data"
  6. ClusterLocalhostAction = "fix-cluster-localhost"
  7. ClientCertDataAction = "upload-client-cert-data"
  8. ClientKeyDataAction = "upload-client-key-data"
  9. OIDCIssuerDataAction = "upload-oidc-idp-issuer-ca-data"
  10. TokenDataAction = "upload-token-data"
  11. GCPKeyDataAction = "upload-gcp-key-data"
  12. AWSDataAction = "upload-aws-data"
  13. )
  14. // ServiceAccountAction is an action that must be resolved to set up
  15. // a ServiceAccount
  16. type ServiceAccountAction struct {
  17. gorm.Model
  18. ServiceAccountCandidateID uint
  19. // One of the constant action names
  20. Name string `json:"name"`
  21. Resolved bool `json:"resolved"`
  22. // Filename is an optional filename, if the action requires
  23. // data populated from a local file
  24. Filename string `json:"filename,omitempty"`
  25. }
  26. // Externalize generates an external ServiceAccount to be shared over REST
  27. func (u *ServiceAccountAction) Externalize() *ServiceAccountActionExternal {
  28. info := ServiceAccountActionInfos[u.Name]
  29. return &ServiceAccountActionExternal{
  30. Name: u.Name,
  31. Resolved: u.Resolved,
  32. Filename: u.Filename,
  33. Docs: info.Docs,
  34. Fields: info.Fields,
  35. }
  36. }
  37. // ServiceAccountActionExternal is an external ServiceAccountAction to be
  38. // sent over REST
  39. type ServiceAccountActionExternal struct {
  40. Name string `json:"name"`
  41. Docs string `json:"docs"`
  42. Resolved bool `json:"resolved"`
  43. Fields string `json:"fields"`
  44. Filename string `json:"filename,omitempty"`
  45. }
  46. // ServiceAccountAllActions is a helper type that contains the fields for
  47. // all possible actions, so that raw bytes can be unmarshaled in a single
  48. // read
  49. type ServiceAccountAllActions struct {
  50. Name string `json:"name"`
  51. ClusterCAData string `json:"cluster_ca_data,omitempty"`
  52. ClusterHostname string `json:"cluster_hostname,omitempty"`
  53. ClientCertData string `json:"client_cert_data,omitempty"`
  54. ClientKeyData string `json:"client_key_data,omitempty"`
  55. OIDCIssuerCAData string `json:"oidc_idp_issuer_ca_data,omitempty"`
  56. TokenData string `json:"token_data,omitempty"`
  57. GCPKeyData string `json:"gcp_key_data,omitempty"`
  58. AWSAccessKeyID string `json:"aws_access_key_id"`
  59. AWSSecretAccessKey string `json:"aws_secret_access_key"`
  60. AWSClusterID string `json:"aws_cluster_id"`
  61. }
  62. // ServiceAccountActionInfo contains the information for actions to be
  63. // performed in order to initialize a ServiceAccount
  64. type ServiceAccountActionInfo struct {
  65. Name string `json:"name"`
  66. Docs string `json:"docs"`
  67. // a comma-separated list of required fields to send in an action request
  68. Fields string `json:"fields"`
  69. }
  70. // ServiceAccountActionInfos contain the information for actions to be
  71. // performed in order to initialize a ServiceAccount
  72. var ServiceAccountActionInfos = map[string]ServiceAccountActionInfo{
  73. "upload-cluster-ca-data": ServiceAccountActionInfo{
  74. Name: ClusterCADataAction,
  75. Docs: "https://github.com/porter-dev/porter",
  76. Fields: "cluster_ca_data",
  77. },
  78. "fix-cluster-localhost": ServiceAccountActionInfo{
  79. Name: ClusterLocalhostAction,
  80. Docs: "https://github.com/porter-dev/porter",
  81. Fields: "cluster_hostname",
  82. },
  83. "upload-client-cert-data": ServiceAccountActionInfo{
  84. Name: ClientCertDataAction,
  85. Docs: "https://github.com/porter-dev/porter",
  86. Fields: "client_cert_data",
  87. },
  88. "upload-client-key-data": ServiceAccountActionInfo{
  89. Name: ClientKeyDataAction,
  90. Docs: "https://github.com/porter-dev/porter",
  91. Fields: "client_key_data",
  92. },
  93. "upload-oidc-idp-issuer-ca-data": ServiceAccountActionInfo{
  94. Name: OIDCIssuerDataAction,
  95. Docs: "https://github.com/porter-dev/porter",
  96. Fields: "oidc_idp_issuer_ca_data",
  97. },
  98. "upload-token-data": ServiceAccountActionInfo{
  99. Name: TokenDataAction,
  100. Docs: "https://github.com/porter-dev/porter",
  101. Fields: "token_data",
  102. },
  103. "upload-gcp-key-data": ServiceAccountActionInfo{
  104. Name: GCPKeyDataAction,
  105. Docs: "https://github.com/porter-dev/porter",
  106. Fields: "gcp_key_data",
  107. },
  108. "upload-aws-data": ServiceAccountActionInfo{
  109. Name: AWSDataAction,
  110. Docs: "https://github.com/porter-dev/porter",
  111. Fields: "aws_access_key_id,aws_secret_access_key,aws_cluster_id",
  112. },
  113. }