Skip to content

Commit 6335e39

Browse files
author
Daniel Lloyd
committed
Initial refactor with compartments resource only
1 parent bb994d6 commit 6335e39

27 files changed

+265
-105
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OCI Shiv
2-
A tool for finding OCI instances and OKE Kubernetes clusters and then connecting to them via the OCI bastion service.
2+
A tool for quickly finding OCI resources and connecting to instances and OKE clusters.
33

44
## Quick examples
55

@@ -434,3 +434,8 @@ example
434434
```
435435
sudo xattr -d com.apple.quarantine ~/.local/bin/oshiv
436436
```
437+
438+
## Reference
439+
440+
https://docs.oracle.com/en-us/iaas/tools/go/65.78.0/
441+

bastion/bastion.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

cluster/cluster.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmd/bastion.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
43
*/
54
package cmd
65

@@ -13,13 +12,8 @@ import (
1312
// bastionCmd represents the bastion command
1413
var bastionCmd = &cobra.Command{
1514
Use: "bastion",
16-
Short: "A brief description of your command",
17-
Long: `A longer description that spans multiple lines and likely contains examples
18-
and usage of using your command. For example:
19-
20-
Cobra is a CLI library for Go that empowers applications.
21-
This application is a tool to generate the needed files
22-
to quickly create a Cobra application.`,
15+
Short: "Find, list, and connect via the OCI bastion service",
16+
Long: "TODO",
2317
Run: func(cmd *cobra.Command, args []string) {
2418
fmt.Println("bastion called")
2519
},

cmd/compartment.go

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
1-
/*
2-
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
4-
*/
51
package cmd
62

73
import (
8-
"fmt"
9-
4+
"github.com/cnopslabs/oshiv/resources"
5+
"github.com/cnopslabs/oshiv/utils"
6+
"github.com/oracle/oci-go-sdk/identity"
107
"github.com/spf13/cobra"
118
)
129

13-
// compartmentCmd represents the compartment command
1410
var compartmentCmd = &cobra.Command{
1511
Use: "compartment",
16-
Short: "A brief description of your command",
17-
Long: `A longer description that spans multiple lines and likely contains examples
18-
and usage of using your command. For example:
19-
20-
Cobra is a CLI library for Go that empowers applications.
21-
This application is a tool to generate the needed files
22-
to quickly create a Cobra application.`,
12+
Short: "Find and list compartments",
13+
Long: "TODO",
2314
Run: func(cmd *cobra.Command, args []string) {
24-
fmt.Println("compartment called")
15+
ociConfig := utils.SetupOciConfig()
16+
17+
identityClient, identityErr := identity.NewIdentityClientWithConfigurationProvider(ociConfig)
18+
utils.CheckError(identityErr)
19+
20+
flagTenancyIdOverride, _ := cmd.Flags().GetString("tenancy-id-override")
21+
tenancyId, tenancyName := resources.ValidateTenancyId(flagTenancyIdOverride, identityClient, ociConfig)
22+
23+
compartments := resources.FetchCompartments(tenancyId, identityClient)
24+
25+
flagList, _ := cmd.Flags().GetBool("list")
26+
if flagList {
27+
resources.ListCompartments(compartments, tenancyId, tenancyName)
28+
}
29+
30+
flagFind, _ := cmd.Flags().GetString("find")
31+
if flagFind != "" {
32+
resources.FindCompartments(tenancyId, tenancyName, identityClient, flagFind)
33+
}
2534
},
2635
}
2736

2837
func init() {
2938
rootCmd.AddCommand(compartmentCmd)
30-
3139
// Here you will define your flags and configuration settings.
3240

3341
// Cobra supports Persistent Flags which will work for this command
@@ -36,5 +44,6 @@ func init() {
3644

3745
// Cobra supports local flags which will only run when this command
3846
// is called directly, e.g.:
39-
// compartmentCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
47+
compartmentCmd.Flags().BoolP("list", "l", false, "List all compartments")
48+
compartmentCmd.Flags().StringP("find", "f", "", "Find compartment by name pattern search")
4049
}

cmd/image.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
43
*/
54
package cmd
65

@@ -13,13 +12,8 @@ import (
1312
// imageCmd represents the image command
1413
var imageCmd = &cobra.Command{
1514
Use: "image",
16-
Short: "A brief description of your command",
17-
Long: `A longer description that spans multiple lines and likely contains examples
18-
and usage of using your command. For example:
19-
20-
Cobra is a CLI library for Go that empowers applications.
21-
This application is a tool to generate the needed files
22-
to quickly create a Cobra application.`,
15+
Short: "Find and list OCI compute images",
16+
Long: "TODO",
2317
Run: func(cmd *cobra.Command, args []string) {
2418
fmt.Println("image called")
2519
},

cmd/instance.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
43
*/
54
package cmd
65

@@ -13,13 +12,8 @@ import (
1312
// instanceCmd represents the instance command
1413
var instanceCmd = &cobra.Command{
1514
Use: "instance",
16-
Short: "A brief description of your command",
17-
Long: `A longer description that spans multiple lines and likely contains examples
18-
and usage of using your command. For example:
19-
20-
Cobra is a CLI library for Go that empowers applications.
21-
This application is a tool to generate the needed files
22-
to quickly create a Cobra application.`,
15+
Short: "Find and list OCI instances",
16+
Long: "TODO",
2317
Run: func(cmd *cobra.Command, args []string) {
2418
fmt.Println("instance called")
2519
},

cmd/policy.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
43
*/
54
package cmd
65

@@ -13,13 +12,8 @@ import (
1312
// policyCmd represents the policy command
1413
var policyCmd = &cobra.Command{
1514
Use: "policy",
16-
Short: "A brief description of your command",
17-
Long: `A longer description that spans multiple lines and likely contains examples
18-
and usage of using your command. For example:
19-
20-
Cobra is a CLI library for Go that empowers applications.
21-
This application is a tool to generate the needed files
22-
to quickly create a Cobra application.`,
15+
Short: "Find and list policies by name or statement",
16+
Long: "TODO",
2317
Run: func(cmd *cobra.Command, args []string) {
2418
fmt.Println("policy called")
2519
},

cmd/root.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/*
2-
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
4-
*/
51
package cmd
62

73
import (
@@ -10,18 +6,11 @@ import (
106
"github.com/spf13/cobra"
117
)
128

13-
14-
159
// rootCmd represents the base command when called without any subcommands
1610
var rootCmd = &cobra.Command{
1711
Use: "oshiv",
18-
Short: "A brief description of your application",
19-
Long: `A longer description that spans multiple lines and likely contains
20-
examples and usage of using your application. For example:
21-
22-
Cobra is a CLI library for Go that empowers applications.
23-
This application is a tool to generate the needed files
24-
to quickly create a Cobra application.`,
12+
Short: "A tool for finding and connecting to OCI resources",
13+
Long: "A tool for finding OCI resources and for connecting to instances and OKE clusters via the OCI bastion service.",
2514
// Uncomment the following line if your bare application
2615
// has an action associated with it:
2716
// Run: func(cmd *cobra.Command, args []string) { },
@@ -43,9 +32,13 @@ func init() {
4332

4433
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.oshiv.yaml)")
4534

35+
// We need a way to override the default tenancy that we use to authenticate against
36+
// One way to do that is to provide a flag for Tenancy ID
37+
var FlagTenancyIdOverride string
38+
rootCmd.PersistentFlags().StringVarP(&FlagTenancyIdOverride, "tenancy-id-override", "t", "", "Override's the default tenancy with this tenancy ID")
39+
// rootCmd.MarkFlagRequired("tenancy-id")
40+
4641
// Cobra also supports local flags, which will only run
4742
// when this action is called directly.
48-
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
43+
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
4944
}
50-
51-

cmd/session.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
43
*/
54
package cmd
65

@@ -13,13 +12,8 @@ import (
1312
// sessionCmd represents the session command
1413
var sessionCmd = &cobra.Command{
1514
Use: "session",
16-
Short: "A brief description of your command",
17-
Long: `A longer description that spans multiple lines and likely contains examples
18-
and usage of using your command. For example:
19-
20-
Cobra is a CLI library for Go that empowers applications.
21-
This application is a tool to generate the needed files
22-
to quickly create a Cobra application.`,
15+
Short: "Create, list, and connect to bastion sessions",
16+
Long: "TODO",
2317
Run: func(cmd *cobra.Command, args []string) {
2418
fmt.Println("session called")
2519
},

0 commit comments

Comments
 (0)