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
11 changes: 10 additions & 1 deletion src/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion src/cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion src/cmd/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion src/cmd/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/v2025"
"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
12 changes: 11 additions & 1 deletion src/cmd/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion src/cmd/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/cmd/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type IntegrationInputType struct {

type IntegrationInput interface {
opslevel.AWSIntegrationInput |
opslevel.AzureResourcesIntegrationInput |
EventIntegrationInputDTO |
opslevel.GoogleCloudIntegrationInput
opslevel.AzureResourcesIntegrationInput |
EventIntegrationInputDTO |
opslevel.GoogleCloudIntegrationInput
}

func validateIntegrationInput() (*IntegrationInputType, error) {
Expand Down
28 changes: 23 additions & 5 deletions src/cmd/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,31 @@ import (
"github.com/spf13/cobra"
)

func buildExamplePropertyInput() string {
return getExample(opslevel.PropertyInput{
Definition: *opslevel.NewIdentifier("example_definition"),
Owner: *opslevel.NewIdentifier("example_owner"),
Value: opslevel.JsonString("example_value"),
})
}

func buildExamplePropertyDefinitionInput() string {
return getExample(opslevel.PropertyDefinitionInput{
Name: opslevel.RefOf("example_name"),
Description: opslevel.RefOf("example_description"),
Schema: &opslevel.JSONSchema{
"type": "string",
},
})
}

var examplePropertyCmd = &cobra.Command{
Use: "property",
Aliases: []string{"prop"},
Short: "Example Property",
Long: `Example Property`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.PropertyInput]())
fmt.Println(buildExamplePropertyInput())
},
}

Expand Down Expand Up @@ -104,7 +122,7 @@ EOF

cat << EOF | opslevel assign property -f -
%s
EOF`, getYaml[opslevel.PropertyInput]()),
EOF`, buildExamplePropertyInput()),
Run: func(cmd *cobra.Command, args []string) {
input, err := readResourceInput[opslevel.PropertyInput]()
cobra.CheckErr(err)
Expand Down Expand Up @@ -149,7 +167,7 @@ var examplePropertyDefinitionCmd = &cobra.Command{
Short: "Example Property Definition",
Long: `Example Property Definition`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.PropertyDefinitionInput]())
fmt.Println(buildExamplePropertyDefinitionInput())
},
}

Expand All @@ -161,7 +179,7 @@ var createPropertyDefinitionCmd = &cobra.Command{
Example: fmt.Sprintf(`
cat << EOF | opslevel create property-definition -f -
%s
EOF`, getYaml[opslevel.PropertyDefinitionInput]()),
EOF`, buildExamplePropertyDefinitionInput()),
Run: func(cmd *cobra.Command, args []string) {
input, err := readPropertyDefinitionInput()
cobra.CheckErr(err)
Expand All @@ -180,7 +198,7 @@ var updatePropertyDefinitionCmd = &cobra.Command{
Example: fmt.Sprintf(`
cat << EOF | opslevel update property-definition propdef3 -f -
%s
EOF`, getYaml[opslevel.PropertyDefinitionInput]()),
EOF`, buildExamplePropertyDefinitionInput()),
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID", "ALIAS"},
Run: func(cmd *cobra.Command, args []string) {
Expand Down
8 changes: 6 additions & 2 deletions src/cmd/rubric.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var exampleCategoryCmd = &cobra.Command{
Short: "Example rubric category",
Long: `Example rubric category`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.CategoryCreateInput]())
fmt.Println(getExample(opslevel.CategoryCreateInput{
Name: "example_name",
}))
},
}

Expand Down Expand Up @@ -92,7 +94,9 @@ var exampleLevelCmd = &cobra.Command{
Short: "Example rubric level",
Long: `Example rubric level`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.LevelCreateInput]())
fmt.Println(getExample(opslevel.LevelCreateInput{
Name: "example_name",
}))
},
}

Expand Down
7 changes: 6 additions & 1 deletion src/cmd/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ var exampleScorecardCmd = &cobra.Command{
Short: "Example Scorecard",
Long: `Example Scorecard`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.ScorecardInput]())
fmt.Println(getExample(opslevel.ScorecardInput{
Name: "example_name",
Description: opslevel.RefOf("example_description"),
OwnerId: opslevel.ID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"),
AffectsOverallServiceLevels: opslevel.RefOf(false),
}))
},
}

Expand Down
5 changes: 4 additions & 1 deletion src/cmd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ var exampleSecretCmd = &cobra.Command{
Short: "Example Secret",
Long: `Example Secret`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.SecretInput]())
fmt.Println(getExample(opslevel.SecretInput{
Owner: opslevel.NewIdentifier("example_owner"),
Value: opslevel.RefOf("example_value"),
}))
},
}

Expand Down
21 changes: 20 additions & 1 deletion src/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ var exampleServiceCmd = &cobra.Command{
Short: "Example service",
Long: `Example service`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.ServiceCreateInput]())
fmt.Println(getExample(opslevel.ServiceCreateInput{
Name: "example_name",
Description: opslevel.RefOf("example_description"),
Framework: opslevel.RefOf("example_framework"),
Language: opslevel.RefOf("example_language"),
LifecycleAlias: opslevel.RefOf("example_lifecycle"),
OwnerAlias: opslevel.RefOf("example_owner"),
Parent: opslevel.NewIdentifier("example_parent"),
Product: opslevel.RefOf("example_product"),
TierAlias: opslevel.RefOf("example_tier"),
Type: opslevel.NewIdentifier("example_type"),
}))
},
}

Expand Down Expand Up @@ -158,6 +169,14 @@ type:
EOF`,
Run: func(cmd *cobra.Command, args []string) {
input, err := readResourceInput[opslevel.ServiceUpdateInput]()
if len(args) == 1 {
key := args[0]
if opslevel.IsID(key) {
input.Id = opslevel.RefOf(opslevel.ID(key))
} else {
input.Alias = opslevel.RefOf(key)
}
}
cobra.CheckErr(err)
service, err := getClientGQL().UpdateService(*input)
cobra.CheckErr(err)
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ var exampleSystemCmd = &cobra.Command{
Short: "Example system",
Long: `Example system`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.SystemInput]())
fmt.Println(getExample(opslevel.SystemInput{
Name: opslevel.RefOf("example_name"),
Description: opslevel.RefOf("example_description"),
OwnerId: opslevel.RefOf(opslevel.ID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk")),
Parent: opslevel.NewIdentifier("domain-alias"),
Note: opslevel.RefOf("example_note"),
}))
},
}

Expand Down
5 changes: 4 additions & 1 deletion src/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ var exampleTagCmd = &cobra.Command{
Short: "Example tag to assign to a resource",
Long: `Example tag to assign to a resource`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(getExample[opslevel.TagInput]())
fmt.Println(getExample(opslevel.TagInput{
Key: "example_key",
Value: "example_value",
}))
},
}

Expand Down
Loading
Loading