Explorar o código

added service field to object resp

Alexander Belanger %!s(int64=5) %!d(string=hai) anos
pai
achega
b07c2f9be2

+ 12 - 0
internal/models/cluster.go

@@ -76,15 +76,27 @@ type ClusterExternal struct {
 
 	// Server endpoint for the cluster
 	Server string `json:"server"`
+
+	// The integration service for this cluster
+	Service integrations.IntegrationService `json:"service"`
 }
 
 // Externalize generates an external Cluster to be shared over REST
 func (c *Cluster) Externalize() *ClusterExternal {
+	serv := integrations.Kube
+
+	if c.AWSIntegrationID != 0 {
+		serv = integrations.EKS
+	} else if c.GCPIntegrationID != 0 {
+		serv = integrations.GKE
+	}
+
 	return &ClusterExternal{
 		ID:        c.ID,
 		ProjectID: c.ProjectID,
 		Name:      c.Name,
 		Server:    c.Server,
+		Service:   serv,
 	}
 }
 

+ 5 - 0
internal/models/gitrepo.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"github.com/porter-dev/porter/internal/models/integrations"
 	"gorm.io/gorm"
 )
 
@@ -28,6 +29,9 @@ type GitRepoExternal struct {
 
 	// The username/organization that this repo integration is linked to
 	RepoEntity string `json:"repo_entity"`
+
+	// The integration service for this git repo
+	Service integrations.IntegrationService `json:"service"`
 }
 
 // Externalize generates an external Repo to be shared over REST
@@ -36,5 +40,6 @@ func (r *GitRepo) Externalize() *GitRepoExternal {
 		ID:         r.Model.ID,
 		ProjectID:  r.ProjectID,
 		RepoEntity: r.RepoEntity,
+		Service:    integrations.Github,
 	}
 }

+ 6 - 6
internal/models/integrations/integration.go

@@ -6,12 +6,12 @@ type IntegrationService string
 // The list of supported third-party services
 const (
 	GKE    IntegrationService = "gke"
-	EKS                       = "eks"
-	Kube                      = "kube"
-	GCR                       = "gcr"
-	ECR                       = "ecr"
-	Github                    = "github"
-	Docker                    = "docker"
+	EKS    IntegrationService = "eks"
+	Kube   IntegrationService = "kube"
+	GCR    IntegrationService = "gcr"
+	ECR    IntegrationService = "ecr"
+	Github IntegrationService = "github"
+	Docker IntegrationService = "docker"
 )
 
 // PorterIntegration is a supported integration service, specifying an auth

+ 13 - 0
internal/models/registry.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"github.com/porter-dev/porter/internal/models/integrations"
 	"gorm.io/gorm"
 )
 
@@ -32,13 +33,25 @@ type RegistryExternal struct {
 
 	// Name of the registry
 	Name string `json:"name"`
+
+	// The integration service for this registry
+	Service integrations.IntegrationService `json:"service"`
 }
 
 // Externalize generates an external Registry to be shared over REST
 func (r *Registry) Externalize() *RegistryExternal {
+	var serv integrations.IntegrationService
+
+	if r.AWSIntegrationID != 0 {
+		serv = integrations.ECR
+	} else if r.GCPIntegrationID != 0 {
+		serv = integrations.GCR
+	}
+
 	return &RegistryExternal{
 		ID:        r.ID,
 		ProjectID: r.ProjectID,
 		Name:      r.Name,
+		Service:   serv,
 	}
 }

+ 0 - 21
node_modules/@types/js-base64/LICENSE

@@ -1,21 +0,0 @@
-    MIT License
-
-    Copyright (c) Microsoft Corporation.
-
-    Permission is hereby granted, free of charge, to any person obtaining a copy
-    of this software and associated documentation files (the "Software"), to deal
-    in the Software without restriction, including without limitation the rights
-    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-    copies of the Software, and to permit persons to whom the Software is
-    furnished to do so, subject to the following conditions:
-
-    The above copyright notice and this permission notice shall be included in all
-    copies or substantial portions of the Software.
-
-    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-    SOFTWARE

+ 0 - 16
node_modules/@types/js-base64/README.md

@@ -1,16 +0,0 @@
-# Installation
-> `npm install --save @types/js-base64`
-
-# Summary
-This package contains type definitions for js-base64 (https://github.com/dankogai/js-base64).
-
-# Details
-Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/js-base64.
-
-### Additional Details
- * Last updated: Sat, 18 Jul 2020 15:47:12 GMT
- * Dependencies: none
- * Global values: `Base64`
-
-# Credits
-These definitions were written by [Denis Carriere](https://github.com/DenisCarriere), [Tommy Lent](https://github.com/tlent), and [JounQin](https://github.com/JounQin).

+ 0 - 82
node_modules/@types/js-base64/index.d.ts

@@ -1,82 +0,0 @@
-// Type definitions for js-base64 3.0
-// Project: https://github.com/dankogai/js-base64
-// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
-//                 Tommy Lent <https://github.com/tlent>
-//                 JounQin <https://github.com/JounQin>
-// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-
-export interface Base64 {
-    VERSION: string;
-    encode(s: string, uriSafe?: boolean): string;
-    encodeURI(s: string): string;
-    encodeURL: Base64['encodeURI'];
-    decode(base64: string): string;
-    atob(base64: string): string;
-    btoa(s: string): string;
-    fromBase64(base64: string): string;
-    toBase64(s: string, uriSafe?: boolean): string;
-    btou(s: string): string;
-    utob(s: string): string;
-    fromUint8Array(uint8Array: Uint8Array, uriSafe?: boolean): string;
-    toUint8Array(s: string): Uint8Array;
-    extendString(): void;
-    extendUint8Array(): void;
-    extendBuiltins(): void;
-}
-
-export const Base64: Base64;
-
-export const VERSION: string;
-
-export const encode: Base64['encode'];
-
-export const encodeURI: Base64['encodeURI'];
-
-export const encodeURL: Base64['encodeURL'];
-
-export const decode: Base64['decode'];
-
-export const atob: Base64['atob'];
-
-export const btoa: Base64['btoa'];
-
-export const fromBase64: Base64['fromBase64'];
-
-export const toBase64: Base64['toBase64'];
-
-export const btou: Base64['btou'];
-
-export const utob: Base64['utob'];
-
-export const fromUint8Array: Base64['fromUint8Array'];
-
-export const toUint8Array: Base64['toUint8Array'];
-
-export const extendString: Base64['extendString'];
-
-export const extendUint8Array: Base64['extendUint8Array'];
-
-export const extendBuiltins: Base64['extendBuiltins'];
-
-/**
- * only for global usage, not available in esm actually
- */
-export function noConflict(): Base64;
-
-export as namespace Base64;
-
-declare global {
-    interface String {
-        fromBase64(): string;
-        toBase64(uriSafe?: boolean): string;
-        toBase64URI(): string;
-        toBase64URL(): string;
-        toUint8Array(): Uint8Array;
-    }
-
-    interface Uint8Array {
-        toBase64(uriSafe?: boolean): string;
-        toBase64URI(): string;
-        toBase64URL(): string;
-    }
-}

+ 0 - 62
node_modules/@types/js-base64/package.json

@@ -1,62 +0,0 @@
-{
-  "_from": "@types/js-base64",
-  "_id": "@types/js-base64@3.0.0",
-  "_inBundle": false,
-  "_integrity": "sha512-BnEyOcDE4H6bkg8m84xhdbkYoAoCg8sYERmAvE4Ff50U8jTfbmOinRdJpauBn1P9XsCCQgCLuSiyz3PM4WHYOA==",
-  "_location": "/@types/js-base64",
-  "_phantomChildren": {},
-  "_requested": {
-    "type": "tag",
-    "registry": true,
-    "raw": "@types/js-base64",
-    "name": "@types/js-base64",
-    "escapedName": "@types%2fjs-base64",
-    "scope": "@types",
-    "rawSpec": "",
-    "saveSpec": null,
-    "fetchSpec": "latest"
-  },
-  "_requiredBy": [
-    "#USER",
-    "/"
-  ],
-  "_resolved": "https://registry.npmjs.org/@types/js-base64/-/js-base64-3.0.0.tgz",
-  "_shasum": "b7b4c130facefefd5c57ba82664c41e2995f91be",
-  "_spec": "@types/js-base64",
-  "_where": "/Users/trevorshim/Development/porter-dev/porter",
-  "bugs": {
-    "url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
-  },
-  "bundleDependencies": false,
-  "contributors": [
-    {
-      "name": "Denis Carriere",
-      "url": "https://github.com/DenisCarriere"
-    },
-    {
-      "name": "Tommy Lent",
-      "url": "https://github.com/tlent"
-    },
-    {
-      "name": "JounQin",
-      "url": "https://github.com/JounQin"
-    }
-  ],
-  "dependencies": {},
-  "deprecated": false,
-  "description": "TypeScript definitions for js-base64",
-  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped#readme",
-  "license": "MIT",
-  "main": "",
-  "name": "@types/js-base64",
-  "repository": {
-    "type": "git",
-    "url": "git+https://github.com/DefinitelyTyped/DefinitelyTyped.git",
-    "directory": "types/js-base64"
-  },
-  "scripts": {},
-  "typeScriptVersion": "3.0",
-  "types": "index.d.ts",
-  "typesPublisherContentHash": "4b5afb34917caed330bdb1d07cae9ec4f28c8f27affcb5551a4412b3f9d082eb",
-  "version": "3.0.0"
-}

+ 3 - 3
server/api/project_handler_test.go

@@ -132,7 +132,7 @@ var readProjectClusterTest = []*projTest{
 		endpoint:  "/api/projects/1/clusters/1",
 		body:      ``,
 		expStatus: http.StatusOK,
-		expBody:   `{"id":1,"project_id":1,"name":"cluster-test","server":"https://10.10.10.10"}`,
+		expBody:   `{"id":1,"project_id":1,"name":"cluster-test","server":"https://10.10.10.10","service":"kube"}`,
 		useCookie: true,
 		validators: []func(c *projTest, tester *tester, t *testing.T){
 			projectClusterBodyValidator,
@@ -156,7 +156,7 @@ var listProjectClustersTest = []*projTest{
 		endpoint:  "/api/projects/1/clusters",
 		body:      ``,
 		expStatus: http.StatusOK,
-		expBody:   `[{"id":1,"project_id":1,"name":"cluster-test","server":"https://10.10.10.10"}]`,
+		expBody:   `[{"id":1,"project_id":1,"name":"cluster-test","server":"https://10.10.10.10","service":"kube"}]`,
 		useCookie: true,
 		validators: []func(c *projTest, tester *tester, t *testing.T){
 			projectClustersBodyValidator,
@@ -273,7 +273,7 @@ var resolveProjectClusterCandidatesTests = []*projTest{
 		endpoint:  "/api/projects/1/clusters/candidates/1/resolve",
 		body:      `{"oidc_idp_issuer_ca_data": "LS0tLS1CRUdJTiBDRVJ="}`,
 		expStatus: http.StatusCreated,
-		expBody:   `{"id":1,"project_id":1,"name":"cluster-test","server":"https://10.10.10.10"}`,
+		expBody:   `{"id":1,"project_id":1,"name":"cluster-test","server":"https://10.10.10.10","service":"kube"}`,
 		useCookie: true,
 		validators: []func(c *projTest, tester *tester, t *testing.T){
 			projectClusterBodyValidator,

+ 13 - 10
server/api/registry_handler_test.go

@@ -134,7 +134,7 @@ var createRegistryTests = []*regTest{
 		endpoint:  "/api/projects/1/registries",
 		body:      `{"name":"registry-test","aws_integration_id":1}`,
 		expStatus: http.StatusCreated,
-		expBody:   `{"id":1,"name":"registry-test","project_id":1}`,
+		expBody:   `{"id":1,"name":"registry-test","project_id":1,"service":"ecr"}`,
 		useCookie: true,
 		validators: []func(c *regTest, tester *tester, t *testing.T){
 			regBodyValidator,
@@ -158,7 +158,7 @@ var listRegistryTests = []*regTest{
 		endpoint:  "/api/projects/1/registries",
 		body:      ``,
 		expStatus: http.StatusOK,
-		expBody:   `[{"id":1,"name":"registry-test","project_id":1}]`,
+		expBody:   `[{"id":1,"name":"registry-test","project_id":1,"service":"ecr"}]`,
 		useCookie: true,
 		validators: []func(c *regTest, tester *tester, t *testing.T){
 			regsBodyValidator,
@@ -166,6 +166,10 @@ var listRegistryTests = []*regTest{
 	},
 }
 
+func TestHandleListRegistries(t *testing.T) {
+	testRegistryRequests(t, listRegistryTests, true)
+}
+
 var listImagesTests = []*imagesTest{
 	&imagesTest{
 		initializers: []func(tester *tester){
@@ -184,10 +188,6 @@ var listImagesTests = []*imagesTest{
 	},
 }
 
-func TestHandleListRegistries(t *testing.T) {
-	testRegistryRequests(t, listRegistryTests, true)
-}
-
 func TestHandleListImages(t *testing.T) {
 	testImagesRequests(t, listImagesTests, true)
 }
@@ -207,8 +207,8 @@ func initRegistry(tester *tester) {
 }
 
 func regBodyValidator(c *regTest, tester *tester, t *testing.T) {
-	gotBody := &models.Registry{}
-	expBody := &models.Registry{}
+	gotBody := &models.RegistryExternal{}
+	expBody := &models.RegistryExternal{}
 
 	json.Unmarshal(tester.rr.Body.Bytes(), &gotBody)
 	json.Unmarshal([]byte(c.expBody), &expBody)
@@ -220,8 +220,11 @@ func regBodyValidator(c *regTest, tester *tester, t *testing.T) {
 }
 
 func regsBodyValidator(c *regTest, tester *tester, t *testing.T) {
-	gotBody := make([]*models.Registry, 0)
-	expBody := make([]*models.Registry, 0)
+	gotBody := make([]*models.RegistryExternal, 0)
+	expBody := make([]*models.RegistryExternal, 0)
+
+	json.Unmarshal(tester.rr.Body.Bytes(), &gotBody)
+	json.Unmarshal([]byte(c.expBody), &expBody)
 
 	if diff := deep.Equal(gotBody, expBody); diff != nil {
 		t.Errorf("handler returned wrong body:\n")