Skip to content

Commit 076f9f1

Browse files
authored
add otterize export clientintents cli command; Bump golang to v1.23.1; bump actions versions (#164)
1 parent 2189e19 commit 076f9f1

28 files changed

Lines changed: 10466 additions & 5873 deletions

File tree

.github/workflows/build-fork.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ jobs:
2424
runs-on: ${{ matrix.os }}
2525
steps:
2626
- name: Check out the code
27-
uses: actions/checkout@v2
27+
uses: actions/checkout@v4
2828
with:
2929
fetch-depth: 1
3030
submodules: recursive
3131

32-
- uses: actions/setup-go@v3
32+
- uses: actions/setup-go@v4
3333
with:
34-
go-version: 1.22
34+
go-version: 1.23.1
3535

3636
- name: Install dependencies
3737
if: matrix.os == 'macos-latest'

.github/workflows/build.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ jobs:
2424
runs-on: ${{ matrix.os }}
2525
steps:
2626
- name: Check out the code
27-
uses: actions/checkout@v2
27+
uses: actions/checkout@v4
2828
with:
2929
fetch-depth: 1
3030
submodules: recursive
3131

32-
- uses: actions/setup-go@v3
32+
- uses: actions/setup-go@v4
3333
with:
34-
go-version: 1.22
34+
go-version: 1.23.1
3535

3636
- name: Install dependencies
3737
if: matrix.os == 'macos-latest'
@@ -66,17 +66,17 @@ jobs:
6666
- shell: bash
6767
run: |
6868
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
69-
- uses: actions/upload-artifact@v3
69+
- uses: actions/upload-artifact@v4
7070
if: matrix.os == 'ubuntu-latest'
7171
with:
7272
path: dist/linux
7373
name: linux-${{ env.sha_short }}
74-
- uses: actions/upload-artifact@v3
74+
- uses: actions/upload-artifact@v4
7575
if: matrix.os == 'macos-latest'
7676
with:
7777
path: dist/darwin
7878
name: darwin-${{ env.sha_short }}
79-
- uses: actions/upload-artifact@v3
79+
- uses: actions/upload-artifact@v4
8080
if: matrix.os == 'windows-latest'
8181
with:
8282
path: dist/windows

.github/workflows/lint.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: golangci-lint
1+
name: lint
22
on:
33
pull_request:
44
types:
@@ -13,32 +13,34 @@ permissions:
1313
# pull-requests: read
1414

1515
jobs:
16-
golangci:
17-
name: golangci
16+
go-lint:
17+
name: go-lint
1818
runs-on: ubuntu-latest
1919
steps:
20-
- name: Checkout repository
21-
uses: actions/checkout@v4
22-
23-
- uses: actions/setup-go@v3
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-go@v4
2422
with:
25-
go-version: 1.22
26-
23+
go-version: 1.23.1
2724
- name: go vet
2825
run: go vet ./...
2926
working-directory: .
30-
27+
- name: staticcheck
28+
uses: dominikh/staticcheck-action@v1.3.1
29+
with:
30+
version: "2024.1.1"
31+
install-go: false
32+
working-directory: .
3133
- name: golangci-lint
32-
uses: golangci/golangci-lint-action@v3
34+
uses: golangci/golangci-lint-action@v6
3335
with:
3436
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
35-
version: v1.55.2
37+
version: v1.61.0
3638

3739
# Optional: working directory, useful for monorepos
3840
working-directory: .
3941

4042
# Optional: golangci-lint command line arguments.
41-
args: --timeout 5m
43+
args: --timeout 2m --out-format=colored-line-number
4244

4345
# Optional: show only new issues if it's a pull request. The default value is `false`.
4446
# only-new-issues: true

.github/workflows/release-tag.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818

1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v2
21+
uses: actions/checkout@v4
2222

23-
- uses: actions/setup-go@v3
23+
- uses: actions/setup-go@v4
2424
with:
25-
go-version: 1.22
25+
go-version: 1.23.1
2626
cache: true
2727

2828

@@ -60,17 +60,17 @@ jobs:
6060
- shell: bash
6161
run: |
6262
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
63-
- uses: actions/upload-artifact@v3
63+
- uses: actions/upload-artifact@v4
6464
if: matrix.os == 'ubuntu-latest'
6565
with:
6666
path: dist/linux
6767
name: linux-${{ env.sha_short }}
68-
- uses: actions/upload-artifact@v3
68+
- uses: actions/upload-artifact@v4
6969
if: matrix.os == 'macos-latest'
7070
with:
7171
path: dist/darwin
7272
name: darwin-${{ env.sha_short }}
73-
- uses: actions/upload-artifact@v3
73+
- uses: actions/upload-artifact@v4
7474
if: matrix.os == 'windows-latest'
7575
with:
7676
path: dist/windows
@@ -80,12 +80,12 @@ jobs:
8080
runs-on: ubuntu-latest
8181
needs: build
8282
steps:
83-
- uses: actions/checkout@v3
83+
- uses: actions/checkout@v4
8484
with:
8585
fetch-depth: 0
86-
- uses: actions/setup-go@v3
86+
- uses: actions/setup-go@v4
8787
with:
88-
go-version: 1.22
88+
go-version: 1.23.1
8989
cache: true
9090

9191
- name: GCP auth
@@ -96,15 +96,15 @@ jobs:
9696
# copy the caches from prepare
9797
- shell: bash
9898
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
99-
- uses: actions/download-artifact@v3
99+
- uses: actions/download-artifact@v4
100100
with:
101101
path: dist/linux
102102
name: linux-${{ env.sha_short }}
103-
- uses: actions/download-artifact@v3
103+
- uses: actions/download-artifact@v4
104104
with:
105105
path: dist/darwin
106106
name: darwin-${{ env.sha_short }}
107-
- uses: actions/download-artifact@v3
107+
- uses: actions/download-artifact@v4
108108
with:
109109
path: dist/windows
110110
name: windows-${{ env.sha_short }}
@@ -137,7 +137,7 @@ jobs:
137137
# For macOS, we need to modify the hashes for the zips ot match
138138
# those of the notarized ZIPs, rather than the build output zips.
139139
- name: Checkout homebrew-otterize
140-
uses: actions/checkout@v2
140+
uses: actions/checkout@v4
141141
with:
142142
token: ${{ secrets.OTTERIZEBOT_GITHUB_TOKEN }}
143143
repository: otterize/homebrew-otterize
@@ -149,7 +149,7 @@ jobs:
149149
steps:
150150

151151
- name: Checkout docs
152-
uses: actions/checkout@v2
152+
uses: actions/checkout@v4
153153
with:
154154
token: ${{ secrets.OTTERIZEBOT_GITHUB_TOKEN }}
155155
repository: otterize/docs
@@ -172,7 +172,7 @@ jobs:
172172
needs: release
173173
steps:
174174
- name: Checkout docs
175-
uses: actions/checkout@v2
175+
uses: actions/checkout@v4
176176
with:
177177
token: ${{ secrets.OTTERIZEBOT_GITHUB_TOKEN }}
178178
repository: otterize/network-mapper
@@ -195,7 +195,7 @@ jobs:
195195
needs: release
196196
steps:
197197
- name: Checkout CLI
198-
uses: actions/checkout@v2
198+
uses: actions/checkout@v4
199199
with:
200200
token: ${{ secrets.OTTERIZEBOT_GITHUB_TOKEN }}
201201
path: ./cli

go.mod

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/accessgraph/get/get-accessgraph.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ const (
2121
servicesIdsKey = "services-ids"
2222
)
2323

24+
func getInputIncludeFilterFromViper(key string) *map[string]any {
25+
if viper.IsSet(key) {
26+
return &map[string]any{
27+
"include": lo.ToPtr(viper.GetStringSlice(key)),
28+
}
29+
}
30+
return nil
31+
}
32+
33+
func getInputTimeFilterValueFromViper(key string) (*map[string]any, error) {
34+
if viper.IsSet(key) {
35+
lastSeenAfterStr := viper.GetString(key)
36+
lastSeenAfter, err := time.Parse(time.RFC3339, lastSeenAfterStr)
37+
if err != nil {
38+
return nil, fmt.Errorf("invalid last seen after format: %s", err)
39+
}
40+
return &map[string]any{
41+
"operator": lo.ToPtr(cloudapi.AFTER),
42+
"value": lo.ToPtr(lastSeenAfter),
43+
}, nil
44+
}
45+
return nil, nil
46+
}
47+
2448
var GetAccessGraph = &cobra.Command{
2549
Use: "get",
2650
Short: "Get access graph",
@@ -35,21 +59,17 @@ var GetAccessGraph = &cobra.Command{
3559
}
3660

3761
filter := cloudapi.InputAccessGraphFilter{
38-
IncludeServicesWithNoEdges: lo.ToPtr(true),
39-
ClusterIds: lo.Ternary(viper.IsSet(clustersIdsKey), lo.ToPtr(viper.GetStringSlice(clustersIdsKey)), nil),
40-
EnvironmentIds: lo.Ternary(viper.IsSet(envIdsKey), lo.ToPtr(viper.GetStringSlice(envIdsKey)), nil),
41-
NamespaceIds: lo.Ternary(viper.IsSet(namespacesIdsKey), lo.ToPtr(viper.GetStringSlice(namespacesIdsKey)), nil),
42-
ServiceIds: lo.Ternary(viper.IsSet(servicesIdsKey), lo.ToPtr(viper.GetStringSlice(servicesIdsKey)), nil),
62+
ClusterIds: getInputIncludeFilterFromViper(clustersIdsKey),
63+
EnvironmentIds: getInputIncludeFilterFromViper(envIdsKey),
64+
NamespaceIds: getInputIncludeFilterFromViper(namespacesIdsKey),
65+
ServiceIds: getInputIncludeFilterFromViper(servicesIdsKey),
4366
}
4467

45-
if viper.IsSet(lastSeenAfterKey) {
46-
lastSeenAfterStr := viper.GetString(lastSeenAfterKey)
47-
lastSeenAfter, err := time.Parse(time.RFC3339, lastSeenAfterStr)
48-
if err != nil {
49-
return fmt.Errorf("invalid last seen after format: %s", err)
50-
}
51-
filter.LastSeenAfter = &lastSeenAfter
68+
lastSeenFilter, err := getInputTimeFilterValueFromViper(lastSeenAfterKey)
69+
if err != nil {
70+
return err
5271
}
72+
filter.LastSeen = lastSeenFilter
5373

5474
r, err := c.AccessGraphQueryWithResponse(ctxTimeout, cloudapi.AccessGraphQueryJSONRequestBody{Filter: &filter})
5575
if err != nil {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package clientintents
2+
3+
import (
4+
"github.com/otterize/otterize-cli/src/cmd/clientintents/export"
5+
"github.com/otterize/otterize-cli/src/cmd/groups"
6+
"github.com/otterize/otterize-cli/src/pkg/cloudclient"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var ClientIntentsCmd = &cobra.Command{
11+
Use: "clientintents",
12+
GroupID: groups.ResourcesGroup.ID,
13+
Short: "Get service client intents information",
14+
}
15+
16+
func init() {
17+
cloudclient.RegisterAPIFlags(ClientIntentsCmd)
18+
ClientIntentsCmd.AddCommand(export.ExportClientIntentsCmd)
19+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package export
2+
3+
import (
4+
"context"
5+
cloudclient "github.com/otterize/otterize-cli/src/pkg/cloudclient/restapi"
6+
"github.com/otterize/otterize-cli/src/pkg/cloudclient/restapi/cloudapi"
7+
"github.com/otterize/otterize-cli/src/pkg/config"
8+
"github.com/otterize/otterize-cli/src/pkg/output"
9+
"github.com/samber/lo"
10+
"github.com/spf13/cobra"
11+
"github.com/spf13/viper"
12+
"os"
13+
)
14+
15+
const (
16+
outputLocationKey = "output"
17+
outputLocationShorthand = "o"
18+
)
19+
20+
var ExportClientIntentsCmd = &cobra.Command{
21+
Use: "export <service-id>",
22+
Short: "Export client intents for a service",
23+
Args: cobra.ExactArgs(1),
24+
SilenceUsage: true,
25+
RunE: func(_ *cobra.Command, args []string) error {
26+
ctxTimeout, cancel := context.WithTimeout(context.Background(), config.DefaultTimeout)
27+
defer cancel()
28+
29+
c, err := cloudclient.NewClient(ctxTimeout)
30+
if err != nil {
31+
return err
32+
}
33+
34+
id := args[0]
35+
r, err := c.ServiceClientIntentsQueryWithResponse(ctxTimeout, id, cloudapi.ServiceClientIntentsQueryJSONRequestBody{
36+
AsServiceId: nil,
37+
ClusterIds: nil,
38+
EnableInternetIntents: lo.ToPtr(true),
39+
FeatureFlags: nil,
40+
LastSeenAfter: nil,
41+
})
42+
if err != nil {
43+
return err
44+
}
45+
46+
serviceClientIntents := r.JSON200.AsClient
47+
s := output.FormatClientIntents(serviceClientIntents)
48+
49+
outputLocation := viper.GetString(outputLocationKey)
50+
if outputLocation == "" {
51+
output.PrintStdout(s)
52+
} else {
53+
err := writeIntentsFile(outputLocation, s)
54+
if err != nil {
55+
return err
56+
}
57+
output.PrintStderr("Successfully wrote intents into %s", outputLocation)
58+
}
59+
return nil
60+
},
61+
}
62+
63+
func writeIntentsFile(filePath string, content string) error {
64+
f, err := os.Create(filePath)
65+
if err != nil {
66+
return err
67+
}
68+
defer f.Close()
69+
70+
_, err = f.WriteString(content)
71+
if err != nil {
72+
return err
73+
}
74+
return nil
75+
}
76+
77+
func init() {
78+
ExportClientIntentsCmd.Flags().StringP(outputLocationKey, outputLocationShorthand, "", "file path to write the output into")
79+
80+
}

0 commit comments

Comments
 (0)