2
0

action.go 3.9 KB

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