Skip to content

Commit

Permalink
feat: add ports and tailscale acl to myapps (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
hysyeah authored Jan 14, 2025
1 parent 13e153c commit 6700b89
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 14 deletions.
61 changes: 61 additions & 0 deletions pkg/app_service/v1/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (c *Client) getAppListFromData(apps []map[string]interface{}) ([]*AppInfo,
var res []*AppInfo
for _, data := range apps {
var appEntrances []Entrance
appPorts := make([]ServicePort, 0)
appACLs := make([]ACL, 0)

appSpec, ok := data["spec"].(map[string]interface{})
if !ok {
klog.Error("get app info error: ", data)
Expand Down Expand Up @@ -140,6 +143,62 @@ func (c *Client) getAppListFromData(apps []map[string]interface{}) ([]*AppInfo,
}
}

ports, ok := appSpec["ports"]
if ok {
portsInterface := ports.([]interface{})
for _, p := range portsInterface {
portsMap := p.(map[string]interface{})
var appPort ServicePort
if t, ok := portsMap["exposePort"]; ok {
appPort.ExposePort = int32(t.(float64))
}
if t, ok := portsMap["host"]; ok {
appPort.Host = stringOrEmpty(t)
}
if t, ok := portsMap["name"]; ok {
appPort.Name = stringOrEmpty(t)
}
if t, ok := portsMap["port"]; ok {
appPort.Port = int32(t.(float64))
}
if t, ok := portsMap["protocol"]; ok {
appPort.Protocol = stringOrEmpty(t)
}
appPorts = append(appPorts, appPort)
}
}
acls, ok := appSpec["tailscaleAcls"]
if ok {
aclInterface := acls.([]interface{})
for _, a := range aclInterface {
aclMap := a.(map[string]interface{})
var tailscaleACL ACL
if t, ok := aclMap["action"]; ok {
tailscaleACL.Action = stringOrEmpty(t)
}
if t, ok := aclMap["src"]; ok {
srcInterface := t.([]interface{})
src := make([]string, 0)
for _, s := range srcInterface {
src = append(src, s.(string))
}
tailscaleACL.Src = src
}
if t, ok := aclMap["proto"]; ok {
tailscaleACL.Proto = stringOrEmpty(t)
}
if t, ok := aclMap["dst"]; ok {
dstInterface := t.([]interface{})
dst := make([]string, 0)
for _, d := range dstInterface {
dst = append(dst, d.(string))
}
tailscaleACL.Dst = dst
}
appACLs = append(appACLs, tailscaleACL)
}
}

res = append(res, &AppInfo{
ID: genAppID(appSpec),
Name: stringOrEmpty(appSpec["name"]),
Expand All @@ -150,6 +209,8 @@ func (c *Client) getAppListFromData(apps []map[string]interface{}) ([]*AppInfo,
Title: title,
Target: target,
Entrances: appEntrances,
Ports: appPorts,
TailScaleACLs: appACLs,
State: state,
IsSysApp: isSysApp,
IsClusterScoped: isClusterScoped,
Expand Down
49 changes: 35 additions & 14 deletions pkg/app_service/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ import (
)

type AppInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Namespace string `json:"namespace"`
DeploymentName string `json:"deployment"`
Owner string `json:"owner"`
URL string `json:"url"`
Icon string `json:"icon"`
Title string `json:"title"`
Target string `json:"target"`
Entrances []Entrance `json:"entrances"`
State string `json:"state"`
IsSysApp bool `json:"isSysApp"`
IsClusterScoped bool `json:"isClusterScoped"`
MobileSupported bool `json:"mobileSupported"`
ID string `json:"id"`
Name string `json:"name"`
Namespace string `json:"namespace"`
DeploymentName string `json:"deployment"`
Owner string `json:"owner"`
URL string `json:"url"`
Icon string `json:"icon"`
Title string `json:"title"`
Target string `json:"target"`
Entrances []Entrance `json:"entrances"`
Ports []ServicePort `json:"ports"`
TailScaleACLs []ACL `json:"tailscaleAcls,omitempty"`
State string `json:"state"`
IsSysApp bool `json:"isSysApp"`
IsClusterScoped bool `json:"isClusterScoped"`
MobileSupported bool `json:"mobileSupported"`
}

type Entrance struct {
Expand All @@ -37,6 +39,25 @@ type Entrance struct {
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
}
type ServicePort struct {
Name string `json:"name"`
Host string `json:"host"`
Port int32 `json:"port"`

ExposePort int32 `json:"exposePort,omitempty"`

// The protocol for this entrance. Supports "tcp" and "udp".
// Default is tcp.
// +default="tcp"
// +optional
Protocol string `json:"protocol,omitempty"`
}
type ACL struct {
Action string `json:"action,omitempty"`
Src []string `json:"src,omitempty"`
Proto string `json:"proto"`
Dst []string `json:"dst"`
}

type AppDeploymentInfo struct {
AppInfo *AppInfo
Expand Down

0 comments on commit 6700b89

Please sign in to comment.