common.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import aws from 'assets/aws.png';
  2. import digitalOcean from 'assets/do.png';
  3. import gcp from 'assets/gcp.png';
  4. import { InfraType } from 'shared/types';
  5. export const infraNames: any = {
  6. 'ecr': 'Elastic Container Registry (ECR)',
  7. 'eks': 'Elastic Kubernetes Service (EKS)',
  8. 'gcr': 'Google Container Registry (GCR)',
  9. 'gke': 'Google Kubernetes Engine (GKE)',
  10. 'docr': 'Digital Ocean Container Registry',
  11. 'doks': 'Digital Ocean Kubernetes Service'
  12. };
  13. export const integrationList: any = {
  14. 'kubernetes': {
  15. icon: 'https://uxwing.com/wp-content/themes/uxwing/download/10-brands-and-social-media/kubernetes.png',
  16. label: 'Kubernetes',
  17. buttonText: 'Add a Cluster',
  18. },
  19. 'repo': {
  20. icon: 'https://3.bp.blogspot.com/-xhNpNJJyQhk/XIe4GY78RQI/AAAAAAAAItc/ouueFUj2Hqo5dntmnKqEaBJR4KQ4Q2K3ACK4BGAYYCw/s1600/logo%2Bgit%2Bicon.png',
  21. label: 'Git Repository',
  22. buttonText: 'Add a Repository',
  23. },
  24. 'registry': {
  25. icon: 'https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/97_Docker_logo_logos-512.png',
  26. label: 'Docker Registry',
  27. buttonText: 'Add a Registry',
  28. },
  29. 'gke': {
  30. icon: 'https://sysdig.com/wp-content/uploads/2016/08/GKE_color.png',
  31. label: 'Google Kubernetes Engine (GKE)',
  32. },
  33. 'eks': {
  34. icon: 'https://img.stackshare.io/service/7991/amazon-eks.png',
  35. label: 'Amazon Elastic Kubernetes Service (EKS)',
  36. },
  37. 'kube': {
  38. icon: 'https://uxwing.com/wp-content/themes/uxwing/download/10-brands-and-social-media/kubernetes.png',
  39. label: 'Upload Kubeconfig'
  40. },
  41. 'docker': {
  42. icon: 'https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/97_Docker_logo_logos-512.png',
  43. label: 'Docker Hub',
  44. },
  45. 'gcr': {
  46. icon: 'https://carlossanchez.files.wordpress.com/2019/06/21046548.png?w=640',
  47. label: 'Google Container Registry (GCR)',
  48. },
  49. 'ecr': {
  50. icon: 'https://avatars2.githubusercontent.com/u/52505464?s=400&u=da920f994c67665c7ad6c606a5286557d4f8555f&v=4',
  51. label: 'Elastic Container Registry (ECR)',
  52. },
  53. 'aws': {
  54. icon: aws,
  55. label: 'AWS',
  56. },
  57. 'gcp': {
  58. icon: gcp,
  59. label: 'GCP',
  60. },
  61. 'do': {
  62. icon: digitalOcean,
  63. label: 'DigitalOcean',
  64. }
  65. };
  66. export const isAlphanumeric = (x: string | null) => {
  67. let re = /^[a-z0-9-]+$/;
  68. if (!x || x.length == 0 || x.search(re) === -1) {
  69. return false;
  70. }
  71. return true;
  72. }
  73. export const getIgnoreCase = (object: any, key: string) => {
  74. return object[Object.keys(object)
  75. .find(k => k.toLowerCase() === key.toLowerCase())
  76. ];
  77. }
  78. export const includesCompletedInfraSet = (infras: InfraType[]): boolean => {
  79. // TODO: declare globally while avoidiing changes to the array on helper call
  80. let infraSets = [
  81. ['ecr', 'eks'],
  82. ['gcr', 'gke'],
  83. ['docr', 'doks']
  84. ];
  85. if (infras.length === 0) {
  86. return false;
  87. }
  88. let completed = [] as string[];
  89. infras.forEach((infra: InfraType, i: number) => {
  90. if (infra.status === 'created') {
  91. completed.push(infra.kind);
  92. }
  93. });
  94. completed.forEach((kind: string, i: number) => {
  95. infraSets.forEach((infraSet: string[], i: number) => {
  96. infraSet.includes(kind) && infraSet.splice(infraSet.indexOf(kind), 1);
  97. });
  98. });
  99. let anyCompleted = false;
  100. infraSets.forEach((infraSet: string[], i: number) => {
  101. if (infraSet.length === 0) {
  102. anyCompleted = true;
  103. }
  104. })
  105. return anyCompleted;
  106. }
  107. export const filterOldInfras = (infras: InfraType[]): InfraType[] => {
  108. let infraSets = [
  109. ['ecr', 'eks'],
  110. ['gcr', 'gke'],
  111. ['docr', 'doks']
  112. ];
  113. let newestInstances = {} as any;
  114. let newestId = -1;
  115. let whitelistedInfras = [] as string[];
  116. infras.forEach((infra: InfraType, i: number) => {
  117. // Determine the most recent set for which provisioning was attempted
  118. if (infra.id > newestId) {
  119. newestId = infra.id;
  120. infraSets.forEach((infraSet: string[]) => {
  121. infraSet.includes(infra.kind) ? whitelistedInfras = infraSet : null;
  122. });
  123. }
  124. if (!newestInstances[infra.kind]) {
  125. newestInstances[infra.kind] = infra;
  126. } else {
  127. let existingId = newestInstances[infra.kind].id;
  128. if (infra.id > existingId) {
  129. newestInstances[infra.kind] = infra;
  130. }
  131. }
  132. });
  133. let newestInfras = Object.values(newestInstances) as InfraType[];
  134. let result = newestInfras.filter((x: InfraType) => {
  135. return whitelistedInfras.includes(x.kind)
  136. });
  137. return result;
  138. }