Skip to content

Commit

Permalink
Add CLI resource mappings CRUD commands
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
jrschumacher committed Feb 15, 2024
2 parents 370c128 + 0bb961f commit c405fd4
Show file tree
Hide file tree
Showing 17 changed files with 773 additions and 165 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 'CI - Build'
on:
workflow_dispatch:
inputs:
versionBumpType:
description: 'Version Bump Type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
jobs:
build-targets:
name: build-targets
runs-on: ubuntu-22.04
env:
GOPRIVATE: github.com/opentdf/opentdf-v2-poc/*
BIN_NAME: tructl
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
cache: false
- name: Get next version
uses: reecetech/version-increment@2023.9.3
id: version
with:
release_branch: main
scheme: semver
increment: ${{ github.event.inputs.versionBumpType }}
pep440: false
- name: print-version
run: echo Incrementing Version ${{ steps.version.outputs.current-version }} -> ${{ steps.version.outputs.version }}
# special app the virtru eng team created, to grab a token for accessing other org repos, in a secure way
- name: Generate a token
id: generate_token
uses: actions/create-github-app-token@v1.5.0
with:
app-id: '416599'
private-key: '${{ secrets.GH_APP_PRIVATE_KEY }}'
owner: ${{ github.repository_owner }}
repositories: 'opentdf-v2-poc'
- run: git config --global url.https://x-access-token:${{ steps.generate_token.outputs.token }}@github.com/.insteadOf https://github.com/
- name: make-targets
env:
SEM_VER: ${{ steps.version.outputs.version }}
run: make build
- name: smoke-test
run: go test ./... -short -race -cover
- name: Release
uses: softprops/action-gh-release@v1
with:
files: './target/**/*'
body: "This is a test release, and will be removed"
tag_name: ${{ steps.version.outputs.version }}
repository: opentdf/tructl
generate_release_notes: true


2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc
with:
version: v1.55
# Optional: golangci-lint command line arguments.
args: --timeout=10m
unit:
name: unit tests
runs-on: ubuntu-22.04
Expand Down
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# We're going to be using this Makefile as a sort of task runner, for all sorts of operations in this project

# first we'll grab the current version from our ENV VAR (added by our CI) - see here: https://github.com/marketplace/actions/version-increment
CURR_VERSION := ${SEM_VER}

# Default target executed when no arguments are given to make.
# NOTE: .PHONY is used to indicate that the target is not a file (e.g. there is no file called 'build-darwin-amd64', instead the .PHONY directive tells make that the proceeding target is a command to be executed, not a file to be generated)
.PHONY: all
all: run
.DEFAULT_GOAL := run




# Binary name: Change this to your actual binary name
BINARY_NAME=tructl
BINARY_NAME=${BIN_NAME}


# Output directory for compiled binaries
Expand All @@ -20,28 +25,28 @@ build: clean build-darwin-amd64 build-darwin-arm64 build-linux-amd64 build-linux

# Build commands for each platform
build-darwin-amd64:
GOOS=darwin GOARCH=amd64 go build -o $(OUT_DIR)/$(BINARY_NAME)-darwin-amd64 .
GOOS=darwin GOARCH=amd64 go build -o $(OUT_DIR)/$(BINARY_NAME)-${CURR_VERSION}-darwin-amd64 .

build-darwin-arm64:
GOOS=darwin GOARCH=arm64 go build -o $(OUT_DIR)/$(BINARY_NAME)-darwin-arm64 .
GOOS=darwin GOARCH=arm64 go build -o $(OUT_DIR)/$(BINARY_NAME)-${CURR_VERSION}-darwin-arm64 .

build-linux-amd64:
GOOS=linux GOARCH=amd64 go build -o $(OUT_DIR)/$(BINARY_NAME)-linux-amd64 .
GOOS=linux GOARCH=amd64 go build -o $(OUT_DIR)/$(BINARY_NAME)-${CURR_VERSION}-linux-amd64 .

build-linux-arm:
GOOS=linux GOARCH=arm go build -o $(OUT_DIR)/$(BINARY_NAME)-linux-arm .
GOOS=linux GOARCH=arm go build -o $(OUT_DIR)/$(BINARY_NAME)-${CURR_VERSION}-linux-arm .

build-linux-arm64:
GOOS=linux GOARCH=arm64 go build -o $(OUT_DIR)/$(BINARY_NAME)-linux-arm64 .
GOOS=linux GOARCH=arm64 go build -o $(OUT_DIR)/$(BINARY_NAME)-${CURR_VERSION}-linux-arm64 .

build-windows-amd64:
GOOS=windows GOARCH=amd64 go build -o $(OUT_DIR)/$(BINARY_NAME)-windows-amd64.exe .
GOOS=windows GOARCH=amd64 go build -o $(OUT_DIR)/$(BINARY_NAME)-${CURR_VERSION}-windows-amd64.exe .

build-windows-arm:
GOOS=windows GOARCH=arm go build -o $(OUT_DIR)/$(BINARY_NAME)-windows-arm.exe .
GOOS=windows GOARCH=arm go build -o $(OUT_DIR)/$(BINARY_NAME)-${CURR_VERSION}-windows-arm.exe .

build-windows-arm64:
GOOS=windows GOARCH=arm64 go build -o $(OUT_DIR)/$(BINARY_NAME)-windows-arm64.exe .
GOOS=windows GOARCH=arm64 go build -o $(OUT_DIR)/$(BINARY_NAME)-${CURR_VERSION}-windows-arm64.exe .

# Target for running the project (adjust as necessary for your project)
.PHONY: run
Expand Down
54 changes: 27 additions & 27 deletions cmd/policy-attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
var (
attrValues []string

attributeCommands = []string{
attributesCreateCmd.Use,
attributeGetCmd.Use,
attributesListCmd.Use,
attributeUpdateCmd.Use,
attributesDeleteCmd.Use,
policy_attributeCommands = []string{
policy_attributesCreateCmd.Use,
policy_attributeGetCmd.Use,
policy_attributesListCmd.Use,
policy_attributeUpdateCmd.Use,
policy_attributesDeleteCmd.Use,
}

attributesCmd = &cobra.Command{
policy_attributesCmd = &cobra.Command{
Use: "attributes",
Short: "Manage attributes [" + strings.Join(attributeCommands, ", ") + "]",
Short: "Manage attributes [" + strings.Join(policy_attributeCommands, ", ") + "]",
Long: `
Attributes - commands to manage attributes within the platform.
Expand All @@ -32,7 +32,7 @@ used to define the access controls based on subject encodings and entity entitle
}

// Create an attribute
attributesCreateCmd = &cobra.Command{
policy_attributesCreateCmd = &cobra.Command{
Use: "create",
Short: "Create an attribute",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -89,7 +89,7 @@ used to define the access controls based on subject encodings and entity entitle
}

// Get an attribute
attributeGetCmd = &cobra.Command{
policy_attributeGetCmd = &cobra.Command{
Use: "get",
Short: "Get an attribute",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -122,7 +122,7 @@ used to define the access controls based on subject encodings and entity entitle
}

// List attributes
attributesListCmd = &cobra.Command{
policy_attributesListCmd = &cobra.Command{
Use: "list",
Short: "List attributes",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -150,7 +150,7 @@ used to define the access controls based on subject encodings and entity entitle
},
}

attributesDeleteCmd = &cobra.Command{
policy_attributesDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete an attribute",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -191,7 +191,7 @@ used to define the access controls based on subject encodings and entity entitle
}

// Update one attribute
attributeUpdateCmd = &cobra.Command{
policy_attributeUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update an attribute",
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -211,28 +211,28 @@ used to define the access controls based on subject encodings and entity entitle
)

func init() {
policyCmd.AddCommand(attributesCmd)
policyCmd.AddCommand(policy_attributesCmd)

// Create an attribute
attributesCmd.AddCommand(attributesCreateCmd)
attributesCreateCmd.Flags().StringP("name", "n", "", "Name of the attribute")
attributesCreateCmd.Flags().StringP("rule", "r", "", "Rule of the attribute")
attributesCreateCmd.Flags().StringSliceVarP(&attrValues, "values", "v", []string{}, "Values of the attribute")
attributesCreateCmd.Flags().StringP("namespace", "s", "", "Namespace of the attribute")
attributesCreateCmd.Flags().StringP("description", "d", "", "Description of the attribute")
policy_attributesCmd.AddCommand(policy_attributesCreateCmd)
policy_attributesCreateCmd.Flags().StringP("name", "n", "", "Name of the attribute")
policy_attributesCreateCmd.Flags().StringP("rule", "r", "", "Rule of the attribute")
policy_attributesCreateCmd.Flags().StringSliceVarP(&attrValues, "values", "v", []string{}, "Values of the attribute")
policy_attributesCreateCmd.Flags().StringP("namespace", "s", "", "Namespace of the attribute")
policy_attributesCreateCmd.Flags().StringP("description", "d", "", "Description of the attribute")

// Get an attribute
attributesCmd.AddCommand(attributeGetCmd)
attributeGetCmd.Flags().StringP("id", "i", "", "Id of the attribute")
policy_attributesCmd.AddCommand(policy_attributeGetCmd)
policy_attributeGetCmd.Flags().StringP("id", "i", "", "Id of the attribute")

// List attributes
attributesCmd.AddCommand(attributesListCmd)
policy_attributesCmd.AddCommand(policy_attributesListCmd)

// Update an attribute
attributesCmd.AddCommand(attributeUpdateCmd)
attributeUpdateCmd.Flags().StringP("id", "i", "", "Id of the attribute")
policy_attributesCmd.AddCommand(policy_attributeUpdateCmd)
policy_attributeUpdateCmd.Flags().StringP("id", "i", "", "Id of the attribute")

// Delete an attribute
attributesCmd.AddCommand(attributesDeleteCmd)
attributesDeleteCmd.Flags().StringP("id", "i", "", "Id of the attribute")
policy_attributesCmd.AddCommand(policy_attributesDeleteCmd)
policy_attributesDeleteCmd.Flags().StringP("id", "i", "", "Id of the attribute")
}
48 changes: 24 additions & 24 deletions cmd/policy-namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
)

var (
namespacesCommands = []string{
namespacesCreateCmd.Use,
namespaceGetCmd.Use,
namespacesListCmd.Use,
namespaceUpdateCmd.Use,
namespaceDeleteCmd.Use,
policy_namespacesCommands = []string{
policy_namespacesCreateCmd.Use,
policy_namespaceGetCmd.Use,
policy_namespacesListCmd.Use,
policy_namespaceUpdateCmd.Use,
policy_namespaceDeleteCmd.Use,
}

namespacesCmd = &cobra.Command{
policy_namespacesCmd = &cobra.Command{
Use: "namespaces",
Short: "Manage namespaces [" + strings.Join(namespacesCommands, ", ") + "]",
Short: "Manage namespaces [" + strings.Join(policy_namespacesCommands, ", ") + "]",
Long: `
Namespaces - commands to manage attribute namespaces within the platform.
Expand All @@ -29,7 +29,7 @@ or different attributes tied to each.
`,
}

namespaceGetCmd = &cobra.Command{
policy_namespaceGetCmd = &cobra.Command{
Use: "get",
Short: "Get a namespace by id",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -57,7 +57,7 @@ or different attributes tied to each.
},
}

namespacesListCmd = &cobra.Command{
policy_namespacesListCmd = &cobra.Command{
Use: "list",
Short: "List namespaces",
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -81,7 +81,7 @@ or different attributes tied to each.
},
}

namespacesCreateCmd = &cobra.Command{
policy_namespacesCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a new namespace, i.e. 'https://example.com'",
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -106,7 +106,7 @@ or different attributes tied to each.
},
}

namespaceDeleteCmd = &cobra.Command{
policy_namespaceDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a namespace by id",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -143,7 +143,7 @@ or different attributes tied to each.
}

// Update one namespace
namespaceUpdateCmd = &cobra.Command{
policy_namespaceUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update a namespace",
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -167,20 +167,20 @@ or different attributes tied to each.
)

func init() {
policyCmd.AddCommand(namespacesCmd)
policyCmd.AddCommand(policy_namespacesCmd)

namespacesCmd.AddCommand(namespaceGetCmd)
namespaceGetCmd.Flags().StringP("id", "i", "", "Id of the namespace")
policy_namespacesCmd.AddCommand(policy_namespaceGetCmd)
policy_namespaceGetCmd.Flags().StringP("id", "i", "", "Id of the namespace")

namespacesCmd.AddCommand(namespacesListCmd)
policy_namespacesCmd.AddCommand(policy_namespacesListCmd)

namespacesCmd.AddCommand(namespacesCreateCmd)
namespacesCreateCmd.Flags().StringP("name", "n", "", "Name value of the namespace")
policy_namespacesCmd.AddCommand(policy_namespacesCreateCmd)
policy_namespacesCreateCmd.Flags().StringP("name", "n", "", "Name value of the namespace")

namespacesCmd.AddCommand(namespaceUpdateCmd)
namespaceUpdateCmd.Flags().StringP("id", "i", "", "Id of the namespace")
namespaceUpdateCmd.Flags().StringP("name", "n", "", "Name value of the namespace")
policy_namespacesCmd.AddCommand(policy_namespaceUpdateCmd)
policy_namespaceUpdateCmd.Flags().StringP("id", "i", "", "Id of the namespace")
policy_namespaceUpdateCmd.Flags().StringP("name", "n", "", "Name value of the namespace")

namespacesCmd.AddCommand(namespaceDeleteCmd)
namespaceDeleteCmd.Flags().StringP("id", "i", "", "Id of the namespace")
policy_namespacesCmd.AddCommand(policy_namespaceDeleteCmd)
policy_namespaceDeleteCmd.Flags().StringP("id", "i", "", "Id of the namespace")
}
Loading

0 comments on commit c405fd4

Please sign in to comment.