-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from kthcloud/dev
add discovery route, fix many bugs with user and team notifications
- Loading branch information
Showing
31 changed files
with
344 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package body | ||
|
||
type DiscoverRead struct { | ||
Version string `json:"version"` | ||
Roles []Role `json:"roles"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package body | ||
|
||
type Role struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Permissions []string `json:"permissions"` | ||
Quota *Quota `json:"quota,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package discover | ||
|
||
import ( | ||
"go-deploy/models/sys/role" | ||
) | ||
|
||
type Discover struct { | ||
Version string | ||
Roles []role.Role | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package discover | ||
|
||
import "go-deploy/models/dto/body" | ||
|
||
func (d *Discover) ToDTO() *body.DiscoverRead { | ||
roles := make([]body.Role, len(d.Roles)) | ||
for i, r := range d.Roles { | ||
roles[i] = r.ToDTO(true) | ||
} | ||
|
||
return &body.DiscoverRead{ | ||
Version: d.Version, | ||
Roles: roles, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package role | ||
|
||
import ( | ||
"github.com/fatih/structs" | ||
"go-deploy/models/dto/body" | ||
) | ||
|
||
func (r *Role) ToDTO(includeQuota bool) body.Role { | ||
permissionsStructMap := structs.Map(r.Permissions) | ||
permissions := make([]string, 0) | ||
for name, value := range permissionsStructMap { | ||
hasPermission, ok := value.(bool) | ||
if ok && hasPermission { | ||
permissions = append(permissions, name) | ||
} | ||
} | ||
|
||
var quota *body.Quota | ||
if includeQuota { | ||
dto := r.Quotas.ToDTO() | ||
quota = &dto | ||
} | ||
|
||
return body.Role{ | ||
Name: r.Name, | ||
Description: r.Description, | ||
Permissions: permissions, | ||
Quota: quota, | ||
} | ||
} | ||
|
||
func (q *Quotas) ToDTO() body.Quota { | ||
return body.Quota{ | ||
Deployments: q.Deployments, | ||
CpuCores: q.CpuCores, | ||
RAM: q.RAM, | ||
DiskSize: q.DiskSize, | ||
Snapshots: q.Snapshots, | ||
GpuLeaseDuration: q.GpuLeaseDuration, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package role | ||
|
||
type Quotas struct { | ||
Deployments int `yaml:"deployments" structs:"deployments"` | ||
CpuCores int `yaml:"cpuCores" structs:"cpuCores"` | ||
RAM int `yaml:"ram" structs:"ram"` | ||
DiskSize int `yaml:"diskSize" structs:"diskSize"` | ||
Snapshots int `yaml:"snapshots" structs:"snapshots"` | ||
GpuLeaseDuration float64 `yaml:"gpuLeaseDuration" structs:"gpuLeaseDuration"` // in hours | ||
} | ||
|
||
type Permissions struct { | ||
ChooseZone bool `yaml:"chooseZone" structs:"chooseZone"` | ||
ChooseGPU bool `yaml:"chooseGpu" structs:"chooseGpu"` | ||
UseCustomDomains bool `yaml:"useCustomDomains" structs:"useCustomDomains"` | ||
UseGPUs bool `yaml:"useGpus" structs:"useGpus"` | ||
UsePrivilegedGPUs bool `yaml:"usePrivilegedGpus" structs:"usePrivilegedGpus"` | ||
} | ||
|
||
type Role struct { | ||
Name string `yaml:"name"` | ||
Description string `yaml:"description"` | ||
IamGroup string `yaml:"iamGroup"` | ||
Permissions Permissions `yaml:"permissions"` | ||
Quotas Quotas `yaml:"quotas"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.