Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into add_diff_validate
Browse files Browse the repository at this point in the history
  • Loading branch information
oanatmaria committed Oct 26, 2023
2 parents 2093ac0 + 2ef8edd commit 507336c
Show file tree
Hide file tree
Showing 31 changed files with 1,470 additions and 136 deletions.
50 changes: 32 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,50 @@ on:
- release-*
env:
PRE_RELEASE: ${{ github.ref == 'refs/heads/main' && 'development' || '' }}
GO_VERSION: "1.19"
GO_VERSION: "1.20"
GO_RELEASER_VERSION: "v1.20.0"
GO_LANGCI_LINT_VERSION: "v1.53.3"
GO_TESTSUM_VERSION: "1.10.1"

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
-
name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup caching
uses: actions/cache@v3
-
name: Build
uses: goreleaser/goreleaser-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Tools
run: |
go run mage.go deps
- name: Lint
run: |
go run mage.go lint
- name: Test
distribution: goreleaser
version: ${{ env.GO_RELEASER_VERSION }}
args: build --clean --snapshot --single-target
-
name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GO_LANGCI_LINT_VERSION }}
-
name: Test Setup
uses: autero1/[email protected]
with:
gotestsum_version: ${{ env.GO_TESTSUM_VERSION }}
-
name: Test
run: |
go run mage.go test
- name: Upload code coverage
gotestsum --format short-verbose -- -count=1 -v -timeout=240s -coverprofile=cover.out -coverpkg=./... ./...
-
name: Upload code coverage
uses: shogo82148/actions-goveralls@v1
continue-on-error: true
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

.dev/
.ext/
.vscode/launch.json

bin/
dist/

cover.out

Expand Down
91 changes: 91 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
project_name: azm

env:
- REGISTRY=ghcr.io
- ORG=aserto-dev
- REPO=azm

before:
# https://goreleaser.com/customization/hooks/
hooks:

builds:
# https://goreleaser.com/customization/build/
- id: azmcmd
main: ./cmd/azmcmd
binary: azmcmd
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/{{ .Env.ORG }}/{{ .Env.REPO }}/pkg/azmcmd/cmds/ver={{.Version}}
- -X github.com/{{ .Env.ORG }}/{{ .Env.REPO }}/pkg/azmcmd/cmds/commit={{.ShortCommit}}
- -X github.com/{{ .Env.ORG }}/{{ .Env.REPO }}/pkg/azmcmd/cmds/date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"

archives:
# https://goreleaser.com/customization/archive/
- format: zip
builds:
- azmcmd
files:
- LICENSE
- README.md
name_template: >-
azmcmd_{{ .Os }}_{{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end }}
checksum:
# https://goreleaser.com/customization/checksum/
name_template: "checksums.txt"

snapshot:
# https://goreleaser.com/customization/snapshots/
name_template: "{{ .Tag }}"

source:
# https://goreleaser.com/customization/source/
enabled: false

changelog:
# https://goreleaser.com/customization/changelog/
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
# https://goreleaser.com/customization/release/
github:
owner: "{{ .Env.ORG }}"
name: "{{ .Env.REPO }}"

draft: false
prerelease: false
name_template: "{{.ProjectName}} {{.Tag}}"

blobs:
# https://goreleaser.com/customization/blob/
-
provider: gs
bucket: azm-cli
folder: "azmcmd/{{ .Version }}"
extra_files:
- glob: VERSION.txt
-
provider: gs
bucket: azm0-cli
folder: "azmcmd/latest"
extra_files:
- glob: VERSION.txt
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"cSpell.words": [
"aserto",
"etag",
"golangci",
"goreleaser",
"gotestsum",
"jsondiff",
"protobuf",
"samber",
"stretchr",
"testsum",
"timestamppb"
]
}
5 changes: 4 additions & 1 deletion Depfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
go:
goreleaser:
importPath: github.com/goreleaser/goreleaser
version: "v1.20.0"
gotestsum:
importPath: "gotest.tools/gotestsum"
version: "v1.10.1"
Expand All @@ -8,4 +11,4 @@ go:
version: "v1.54.1"
mockgen:
importPath: github.com/golang/mock/mockgen
version: "v1.6.0"
version: "v1.6.0"
4 changes: 2 additions & 2 deletions cache/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func testPagination[T Named, S PagingSlice[T]](t *testing.T, slice S) {
current++
}

if result.PageInfo.NextToken != "" {
page.Token = result.PageInfo.NextToken
if result.NextToken != "" {
page.Token = result.NextToken
} else {
break
}
Expand Down
27 changes: 6 additions & 21 deletions cache/paging.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,21 @@ type RelationTypeSlice []*dsc2.RelationType
type PermissionSlice []*dsc2.Permission

func (s ObjectTypeSlice) Paginate(page *dsc2.PaginationRequest) (*paging.Result[*dsc2.ObjectType], error) {
if paging.IsCountOnly(page) {
return &paging.Result[*dsc2.ObjectType]{
PageInfo: &dsc2.PaginationResponse{ResultSize: int32(len(s))},
}, nil
}

return paging.PaginateSlice(
s,
page,
page.Size,
page.Token,
1,
func(keys []string, ot *dsc2.ObjectType) bool { return keys[0] == ot.Name },
func(ot *dsc2.ObjectType) []string { return []string{ot.Name} },
)
}

func (s RelationTypeSlice) Paginate(page *dsc2.PaginationRequest) (*paging.Result[*dsc2.RelationType], error) {
if paging.IsCountOnly(page) {
return &paging.Result[*dsc2.RelationType]{
PageInfo: &dsc2.PaginationResponse{ResultSize: int32(len(s))},
}, nil
}

return paging.PaginateSlice(
s,
page,
page.Size,
page.Token,
2,
func(keys []string, relType *dsc2.RelationType) bool {
return keys[0] == relType.ObjectType && keys[1] == relType.Name
Expand All @@ -44,15 +34,10 @@ func (s RelationTypeSlice) Paginate(page *dsc2.PaginationRequest) (*paging.Resul
}

func (s PermissionSlice) Paginate(page *dsc2.PaginationRequest) (*paging.Result[*dsc2.Permission], error) {
if paging.IsCountOnly(page) {
return &paging.Result[*dsc2.Permission]{
PageInfo: &dsc2.PaginationResponse{ResultSize: int32(len(s))},
}, nil
}

return paging.PaginateSlice(
s,
page,
page.Size,
page.Token,
1,
func(keys []string, p *dsc2.Permission) bool { return keys[0] == p.Name },
func(p *dsc2.Permission) []string { return []string{p.Name} },
Expand Down
1 change: 1 addition & 0 deletions cmd/azmcmd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# azmcmd
7 changes: 7 additions & 0 deletions cmd/azmcmd/cmds/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cmds

type CLI struct {
Common
Migrate MigrateCmd `cmd:"" help:"migrate directory v2 metadata to an annotated v3 manifest"`
Version VersionCmd `cmd:"" help:"version information"`
}
8 changes: 8 additions & 0 deletions cmd/azmcmd/cmds/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cmds

type Common struct {
Host string `name:"host" env:"ASERTO_DIR_SVC" default:"localhost:9292"`
APIKey string `name:"api-key" env:"ASERTO_DIR_KEY" default:""`
TenantID string `name:"tenant-id" env:"ASERTO_TENANT_ID" default:""`
Insecure bool `name:"insecure" env:"ASERTO_SKIP_TLS_VERIFICATION" default:"false"`
}
44 changes: 44 additions & 0 deletions cmd/azmcmd/cmds/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cmds

import (
"context"
"os"

"github.com/aserto-dev/azm/migrate"
client "github.com/aserto-dev/go-aserto/client"
)

type MigrateCmd struct {
}

func (a *MigrateCmd) Run(c *Common) error {
ctx := context.Background()

opts := []client.ConnectionOption{
client.WithAddr(c.Host),
client.WithAPIKeyAuth(c.APIKey),
client.WithTenantID(c.TenantID),
client.WithInsecure(c.Insecure),
}

clnt, err := client.NewConnection(ctx, opts...)
if err != nil {
return err
}

m := migrate.NewMigrator()

if err := m.Load(clnt.Conn); err != nil {
return err
}

if err := m.Process(); err != nil {
return err
}

if err := m.Write(os.Stdout); err != nil {
return err
}

return nil
}
61 changes: 61 additions & 0 deletions cmd/azmcmd/cmds/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cmds

import (
"fmt"
"os"
"runtime"
"time"
)

var (
ver string //nolint:gochecknoglobals // set by linker
date string //nolint:gochecknoglobals // set by linker
commit string //nolint:gochecknoglobals // set by linker
)

// Info - version info.
type Info struct {
Version string
Date string
Commit string
}

type VersionCmd struct {
}

func (a *VersionCmd) Run(c *Common) error {
fmt.Fprint(os.Stdout, GetInfo().String())
return nil
}

// GetInfo - get version stamp information.
func GetInfo() Info {
if ver == "" {
ver = "0.0.0"
}

if date == "" {
date = time.Now().Format(time.RFC3339)
}

if commit == "" {
commit = "undefined"
}

return Info{
Version: ver,
Date: date,
Commit: commit,
}
}

// String() -- return version info string.
func (vi Info) String() string {
return fmt.Sprintf("%s g%s %s-%s [%s]",
vi.Version,
vi.Commit,
runtime.GOOS,
runtime.GOARCH,
vi.Date,
)
}
Loading

0 comments on commit 507336c

Please sign in to comment.