forked from cyclops-ui/cyclops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔍 implementation of describe command for the custom resources (cyclop…
…s-ui#292) * ft(cyctl): Describe module functionality * ft(cyctl): Describe templateauthrule functionality * ft(cyctl): Describe templatestore functionality * ft(cyctl): added describe command to define resources * ft(cyctl): base64 encoder and decoder * ft(cyctl): describer utility for resources defination * ft(cyctl): updated dependencies * ft(cyctl): removed line spacing * ft(cyctl): return within the error handling * ft(cyctl): removed base64 encoding * ft(cyctl): removed base64 methods * ft(cyctl): added indentation and removed printing on nextline annotation * ft(cyctl): refactored to single describe metadata func * ft(cyctl): typo removed
- Loading branch information
1 parent
8a97d03
commit 0e68c2c
Showing
6 changed files
with
394 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/cyclops-ui/cycops-cyctl/internal/describe" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
describeExample = ` | ||
# Describe one or more modules | ||
cyctl describe modules [module_name] | ||
# Describe one or more templates | ||
cyctl describe templates [template_name] | ||
# Describe one or more templateauthrules. | ||
cyctl describe templateauthrules [templateauthrules_name]` | ||
) | ||
|
||
var describeCMD = &cobra.Command{ | ||
Use: "describe", | ||
Short: "Describe custom resources like modules, templates, and templateauthrules", | ||
Long: "Describe custom resources like modules, templates, and templateauthrules", | ||
Example: describeExample, | ||
Args: cobra.MinimumNArgs(1), | ||
} | ||
|
||
func init() { | ||
describeCMD.AddCommand(describe.DescribeModule) | ||
describeCMD.AddCommand(describe.DescribeTemplateAuthRule) | ||
describeCMD.AddCommand(describe.DescribeTemplate) | ||
|
||
RootCmd.AddCommand(describeCMD) | ||
} |
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,86 @@ | ||
package describe | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1/client" | ||
"github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig" | ||
"github.com/cyclops-ui/cycops-cyctl/utility" | ||
"github.com/spf13/cobra" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var ( | ||
describeModuleExample = ` | ||
# Describe a single module | ||
cyctl describe modules module1 | ||
# Describe multiple modules | ||
cyctl describe modules module1 module2 module3` | ||
) | ||
|
||
// describeModules describe specified module from the Cyclops API. | ||
func describeModules(clientset *client.CyclopsV1Alpha1Client, moduleNames []string) { | ||
if len(moduleNames) == 0 { | ||
modules, err := clientset.Modules("cyclops").List(v1.ListOptions{}) | ||
if err != nil { | ||
fmt.Printf("Error fetching modules: %v\n", err) | ||
return | ||
} | ||
for _, module := range modules { | ||
moduleNames = append(moduleNames, module.Name) | ||
} | ||
} | ||
|
||
for _, moduleName := range moduleNames { | ||
module, err := clientset.Modules("cyclops").Get(moduleName) | ||
if err != nil { | ||
fmt.Printf("Error from server (NotFound): %v\n", err) | ||
return | ||
} | ||
// Describe the module | ||
describe := utility.Describe(func(d *utility.Describer) { | ||
d.DescribeMetaData(module.ObjectMeta) | ||
|
||
d.Printf("Creation:\t%s\n", module.CreationTimestamp) | ||
|
||
d.Printf("Status:\t%s\n", module.Status.ReconciliationStatus.Status) | ||
|
||
d.Println() | ||
d.Printf("Template:\t\n") | ||
d.Printf(" Repository:\t%s\n", module.Spec.TemplateRef.URL) | ||
d.Printf(" Relative Path:\t%s\n", module.Spec.TemplateRef.Path) | ||
d.Printf(" Branch:\t%s\n", module.Spec.TemplateRef.Version) | ||
|
||
d.Println() | ||
if len(module.Spec.Values.Raw) > 0 { | ||
yamlData, err := utility.JsonToYAMLDescriber(module.Spec.Values.Raw) | ||
if err != nil { | ||
d.Printf("Values:\n%s\n", module.Spec.Values.Raw) | ||
} else { | ||
d.Printf("Values:\n%s\n", yamlData) | ||
} | ||
} else { | ||
d.Printf("Values:\n<none>\n") | ||
} | ||
}) | ||
|
||
fmt.Printf("%s", describe) | ||
fmt.Println("-------------------------------") | ||
|
||
} | ||
} | ||
|
||
var ( | ||
DescribeModule = &cobra.Command{ | ||
Use: "modules [module_name]", | ||
Short: "Describe one or more modules", | ||
Long: "The describe modules command allows you to remove one or more modules from the Cyclops API.", | ||
Example: describeModuleExample, | ||
Aliases: []string{"module"}, | ||
Args: cobra.MinimumNArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
describeModules(kubeconfig.Moduleset, args) | ||
}, | ||
} | ||
) |
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,76 @@ | ||
package describe | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1/client" | ||
"github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig" | ||
"github.com/cyclops-ui/cycops-cyctl/utility" | ||
"github.com/spf13/cobra" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var ( | ||
describeTemplateAuthRuleExample = ` | ||
# Describe a single templateauthrule | ||
cyctl describe templateauthrule templateauthrule1 | ||
# Describe multiple templateauthrule | ||
cyctl describe templateauthrule templateauthrule1 templateauthrule2 templateauthrule3` | ||
) | ||
|
||
// describeTemplateAuthRules describe a specified templateauthrules from the Cyclops API. | ||
func describeTemplateAuthRules(clientset *client.CyclopsV1Alpha1Client, templateAuthNames []string) { | ||
if len(templateAuthNames) == 0 { | ||
templateauthrules, err := clientset.TemplateAuthRules("cyclops").List(v1.ListOptions{}) | ||
if err != nil { | ||
fmt.Printf("Error fetching templateauthrules: %v\n", err) | ||
return | ||
} | ||
for _, templateAuth := range templateauthrules { | ||
templateAuthNames = append(templateAuthNames, templateAuth.Name) | ||
} | ||
} | ||
|
||
for _, templateAuthName := range templateAuthNames { | ||
templateAuth, err := clientset.TemplateAuthRules("cyclops").Get(templateAuthName) | ||
if err != nil { | ||
fmt.Printf("Error from server (NotFound): %v\n", err) | ||
return | ||
} | ||
// Describe the templateAuthRule | ||
describe := utility.Describe(func(d *utility.Describer) { | ||
d.DescribeMetaData(templateAuth.ObjectMeta) | ||
|
||
d.Printf("Creation:\t%s\n", templateAuth.CreationTimestamp) | ||
|
||
d.Println() | ||
d.Printf("Repository:\t%s\n", templateAuth.Spec.Repo) | ||
|
||
d.Println() | ||
d.Printf("Credentails:\t\n") | ||
d.Printf("Username:\t%s\n", templateAuth.Spec.Username.Key) | ||
d.Printf("Password:\t%s\n", templateAuth.Spec.Password.Key) | ||
|
||
d.Println() | ||
}) | ||
|
||
fmt.Printf("%s", describe) | ||
fmt.Println("-------------------------------") | ||
|
||
} | ||
} | ||
|
||
var ( | ||
DescribeTemplateAuthRule = &cobra.Command{ | ||
Use: "templateauthrules [template_auth_rule_name]", | ||
Short: "Describe one or more templateauthrule", | ||
Long: "The describe templateauthrule command allows you to remove one or more modules from the Cyclops API.", | ||
Example: describeTemplateAuthRuleExample, | ||
Aliases: []string{"templateauthrule"}, | ||
Args: cobra.MinimumNArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
describeTemplateAuthRules(kubeconfig.Moduleset, args) | ||
}, | ||
} | ||
) |
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,72 @@ | ||
package describe | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1/client" | ||
"github.com/cyclops-ui/cycops-cyctl/internal/kubeconfig" | ||
"github.com/cyclops-ui/cycops-cyctl/utility" | ||
"github.com/spf13/cobra" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var ( | ||
describeTemplateExample = ` | ||
# Describe a single template | ||
cyctl describe templates template1 | ||
# Describe multiple templates | ||
cyctl describe templates template1 template2 template3` | ||
) | ||
|
||
// describeTemplate descrbe a specified templatestore from the Cyclops API. | ||
func describeTemplate(clientset *client.CyclopsV1Alpha1Client, templateNames []string) { | ||
if len(templateNames) == 0 { | ||
templates, err := clientset.TemplateStore("cyclops").List(v1.ListOptions{}) | ||
if err != nil { | ||
fmt.Printf("Error fetching templateauthrules: %v\n", err) | ||
return | ||
} | ||
for _, template := range templates { | ||
templateNames = append(templateNames, template.Name) | ||
} | ||
} | ||
|
||
for _, templateName := range templateNames { | ||
template, err := clientset.TemplateStore("cyclops").Get(templateName) | ||
if err != nil { | ||
fmt.Printf("Error from server (NotFound): %v\n", err) | ||
return | ||
} | ||
// Describe the template | ||
describe := utility.Describe(func(d *utility.Describer) { | ||
d.DescribeMetaData(template.ObjectMeta) | ||
|
||
d.Printf("Creation:\t%s\n", template.CreationTimestamp) | ||
|
||
d.Println() | ||
d.Printf("Repository:\t%s\n", template.Spec.URL) | ||
d.Printf("Branch:\t%s\n", template.Spec.Version) | ||
d.Printf("RelativePath:\t%s\n", template.Spec.Path) | ||
|
||
}) | ||
|
||
fmt.Printf("%s", describe) | ||
fmt.Println("-------------------------------") | ||
|
||
} | ||
} | ||
|
||
var ( | ||
DescribeTemplate = &cobra.Command{ | ||
Use: "template [template_auth_rule_name]", | ||
Short: "Describe one or more templateauthrule", | ||
Long: "The describe template command allows you to remove one or more modules from the Cyclops API.", | ||
Example: describeTemplateExample, | ||
Aliases: []string{"template"}, | ||
Args: cobra.MinimumNArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
describeTemplate(kubeconfig.Moduleset, args) | ||
}, | ||
} | ||
) |
Oops, something went wrong.