Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ tasks:
cmds:
- go test -race -coverprofile=coverage.txt -covermode=atomic -v ./cmd/... {{ .CLI_ARGS }}

test-e2e:
desc: Run end to end Integration tests
dir: "{{.SRC_DIR}}"
cmds:
- go test -v ./e2e/... {{ .CLI_ARGS }}

update-opslevel-go:
desc: Update opslevel-go version to latest release
dir: "{{.SRC_DIR}}"
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"

"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"

"github.com/opslevel/cli/common"

Expand Down
17 changes: 13 additions & 4 deletions src/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"

"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"

"github.com/opslevel/cli/common"
"github.com/spf13/cobra"
Expand All @@ -17,7 +17,16 @@ var exampleActionCmd = &cobra.Command{
Short: "Example action",
Long: `Example action`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.CustomActionsWebhookActionCreateInput]())
fmt.Println(getExample(opslevel.CustomActionsWebhookActionCreateInput{
Name: "example_name",
Description: opslevel.RefOf("example_description"),
WebhookUrl: "example_webhook_url",
HttpMethod: opslevel.CustomActionsHttpMethodEnumPost,
Headers: &opslevel.JSON{
"example_header": "example_value",
},
LiquidTemplate: opslevel.RefOf("example_liquid_template"),
}))
},
}

Expand Down Expand Up @@ -58,7 +67,7 @@ EOF`,
cobra.CheckErr(err)
result, err := getClientGQL().CreateWebhookAction(*input)
cobra.CheckErr(err)
fmt.Printf("created webhook action: %s\n", result.Id)
fmt.Printf("created webhook action: %s\n", string(result.CustomActionsId.Id))
default:
err := fmt.Errorf("unknown action type: '%s'", actionType)
cobra.CheckErr(err)
Expand Down Expand Up @@ -94,7 +103,7 @@ var listActionCmd = &cobra.Command{
} else {
w := common.NewTabWriter("ID", "NAME", "HTTP_METHOD", "WEBHOOK_URL")
for _, item := range list {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", item.Id, item.Name, item.HTTPMethod, item.WebhookURL)
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", string(item.CustomActionsId.Id), item.Name, item.HttpMethod, item.WebhookUrl)
}
w.Flush()
}
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"slices"
"strings"

"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -16,7 +16,10 @@ var exampleAliasCmd = &cobra.Command{
Short: "Example alias",
Long: `Example alias`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.AliasCreateInput]())
fmt.Println(getExample(opslevel.AliasCreateInput{
OwnerId: opslevel.ID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"),
Alias: "example_alias",
}))
},
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"slices"

"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"

"github.com/opslevel/cli/common"
"github.com/rs/zerolog/log"
Expand Down
10 changes: 8 additions & 2 deletions src/cmd/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"fmt"

"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +20,13 @@ var exampleServiceDependencyCmd = &cobra.Command{
Short: "Example service dependency",
Long: `Example service dependency`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.ServiceDependencyCreateInput]())
fmt.Println(getExample(opslevel.ServiceDependencyCreateInput{
DependencyKey: opslevel.ServiceDependencyKey{
SourceIdentifier: opslevel.NewIdentifier("example_source"),
DestinationIdentifier: opslevel.NewIdentifier("example_destination"),
},
Notes: opslevel.RefOf("example_notes"),
}))
},
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"

"github.com/creasty/defaults"
"github.com/go-git/go-git/v5"
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"

"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down
9 changes: 7 additions & 2 deletions src/cmd/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/opslevel/cli/common"
"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"
"github.com/spf13/cobra"
)

Expand All @@ -17,7 +17,12 @@ var exampleDomainCmd = &cobra.Command{
Short: "Example Domain",
Long: `Example Domain`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.DomainInput]())
fmt.Println(getExample(opslevel.DomainInput{
Name: opslevel.RefOf("example_name"),
Description: opslevel.RefOf("example_description"),
OwnerId: opslevel.RefOf(opslevel.ID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk")),
Note: opslevel.RefOf("example_note"),
}))
},
}

Expand Down
34 changes: 7 additions & 27 deletions src/cmd/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"encoding/json"

"github.com/opslevel/opslevel-go/v2024"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
Expand All @@ -17,35 +16,16 @@ var exampleCmd = &cobra.Command{
Long: "Examples of OpsLevel resources in different formats",
}

func getExample[T any]() string {
func getExample[T any](v T) string {
var out []byte
var err error
if exampleIsJson {
return getJson[T]()
out, err = json.Marshal(v)
} else {
out, err = yaml.Marshal(v)
}
return getYaml[T]()
}

func getJson[T any]() string {
var (
out []byte
err error
)
t := opslevel.NewExampleOf[T]()
out, err = json.Marshal(t)
if err != nil {
panic("unexpected error getting example json")
}
return string(out)
}

func getYaml[T any]() string {
var (
out []byte
err error
)
t := opslevel.NewExampleOf[T]()
out, err = yaml.Marshal(t)
if err != nil {
panic("unexpected error getting example yaml")
panic("unexpected error getting example")
}
return string(out)
}
Expand Down
28 changes: 15 additions & 13 deletions src/cmd/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"

"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"

"github.com/opslevel/cli/common"
"github.com/spf13/cobra"
Expand All @@ -15,7 +15,17 @@ var exampleFilterCmd = &cobra.Command{
Short: "Example filter",
Long: `Example filter`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.FilterCreateInput]())
fmt.Println(getExample(opslevel.FilterCreateInput{
Name: "example_name",
Predicates: &[]opslevel.FilterPredicateInput{
{
Key: opslevel.PredicateKeyEnumAliases,
Type: opslevel.PredicateTypeEnumEquals,
Value: opslevel.RefOf("example_value"),
CaseSensitive: opslevel.RefOf(false),
},
},
}))
},
}

Expand Down Expand Up @@ -100,19 +110,11 @@ EOF`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID"},
Run: func(cmd *cobra.Command, args []string) {
input, err := readResourceInput[opslevel.FilterCreateInput]()
input, err := readResourceInput[opslevel.FilterUpdateInput]()
cobra.CheckErr(err)
input.Id = *opslevel.NewID(args[0])

// hack: in the future all ObjectUpdateInput and ObjectCreateInput
// will be merged into ObjectInput. for now, create an update input
// by adding in the first argument.
updateInput := &opslevel.FilterUpdateInput{
Id: *opslevel.NewID(args[0]),
Name: &input.Name,
Predicates: input.Predicates,
Connective: input.Connective,
}
filter, err := getClientGQL().UpdateFilter(*updateInput)
filter, err := getClientGQL().UpdateFilter(*input)
cobra.CheckErr(err)
common.JsonPrint(json.MarshalIndent(filter, "", " "))
},
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/itchyny/gojq"
"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"
"github.com/spf13/cobra"
)

Expand Down
23 changes: 19 additions & 4 deletions src/cmd/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"github.com/opslevel/cli/common"
"github.com/opslevel/opslevel-go/v2024"
"github.com/opslevel/opslevel-go/v2025"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
Expand All @@ -20,7 +20,22 @@ var exampleInfraCmd = &cobra.Command{
Short: "Example infrastructure resource",
Long: `Example infrastructure resource`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.InfrastructureResourceInput]())
fmt.Println(getExample(opslevel.InfraInput{
Schema: "example_schema",
Owner: opslevel.NewID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"),
Provider: &opslevel.InfraProviderInput{
Account: "example_account",
Name: "example_provider_name",
Type: "example_provider_type",
URL: "example_external_url",
},
Data: &opslevel.JSON{
"name": "my-big-query",
"endpoint": "https://google.com",
"engine": "BigQuery",
"replica": false,
},
}))
},
}

Expand Down Expand Up @@ -173,7 +188,7 @@ opslevel list infra -o json | jq 'map(select(.type == "Database") | .data | from
w := csv.NewWriter(os.Stdout)
w.Write([]string{"NAME", "ID", "ALIASES"})
for _, item := range list {
w.Write([]string{item.Name, item.Id, strings.Join(item.Aliases, "/")})
w.Write([]string{item.Name, string(item.Id), strings.Join(item.Aliases, "/")})
}
w.Flush()
} else {
Expand Down Expand Up @@ -216,7 +231,7 @@ EOF`,
cobra.CheckErr(err)
result, err := getClientGQL().UpdateInfrastructure(key, *input)
cobra.CheckErr(err)
fmt.Println(result.Id)
fmt.Println(string(result.Id))
},
}

Expand Down
Loading
Loading