-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 13cb82e
Showing
13 changed files
with
785 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
*.iml | ||
narc | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# IntelliJ | ||
.idea/ | ||
|
||
.config/ | ||
|
||
tool/ | ||
dist/ | ||
|
||
# asdf | ||
.tool-versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 NAV | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.PHONY: build | ||
|
||
build: | ||
go build -o narc ./cmd/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# NAIS Adminstrator CLI Og Scripts | ||
|
||
> One CLI to administrate it all, and one repository for all the other scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package clusterCmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/nais/narcos/pkg/gcp" | ||
"github.com/nais/narcos/pkg/naisdevice" | ||
"github.com/urfave/cli/v2" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
func Command() *cli.Command { | ||
return &cli.Command{ | ||
Name: "cluster", | ||
Aliases: []string{"c"}, | ||
Description: "Operate on NAIS clusters", | ||
HideHelpCommand: true, | ||
Subcommands: subCommands(), | ||
} | ||
} | ||
|
||
func subCommands() []*cli.Command { | ||
return []*cli.Command{ | ||
{ | ||
Name: "list", | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: "includeManagement", | ||
Aliases: []string{"m"}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "includeOnprem", | ||
Aliases: []string{"o"}, | ||
Value: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "tenant", | ||
Aliases: []string{"t"}, | ||
Action: func(context *cli.Context, tenant string) error { | ||
if !slices.Contains(naisdevice.Tenants, tenant) { | ||
return fmt.Errorf("%v is not a valid tenant", tenant) | ||
} | ||
|
||
return nil | ||
}, | ||
}, | ||
}, | ||
Before: func(context *cli.Context) error { | ||
return gcp.ValidateUserLogin(context.Context) | ||
}, | ||
Action: func(context *cli.Context) error { | ||
includeManagement := context.Bool("includeManagement") | ||
includeOnprem := context.Bool("includeOnprem") | ||
tenant := context.String("tenant") | ||
|
||
_, err := gcp.GetClusters(context.Context, includeManagement, includeOnprem, tenant) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package deviceCmd | ||
|
||
import ( | ||
"github.com/nais/narcos/cmd/commands/deviceCmd/tenant" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func Command() *cli.Command { | ||
return &cli.Command{ | ||
Name: "device", | ||
Aliases: []string{"d"}, | ||
Description: "Manage Naisdevice from the terminal.", | ||
HideHelpCommand: true, | ||
Subcommands: subCommands(), | ||
} | ||
} | ||
|
||
func subCommands() []*cli.Command { | ||
return []*cli.Command{ | ||
tenant.Command(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package tenant | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/nais/narcos/pkg/naisdevice" | ||
"github.com/urfave/cli/v2" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
func Command() *cli.Command { | ||
return &cli.Command{ | ||
Name: "tenant", | ||
Aliases: []string{"t"}, | ||
Usage: "Manage tenants.", | ||
HideHelpCommand: true, | ||
Subcommands: subCommands(), | ||
} | ||
} | ||
|
||
func subCommands() []*cli.Command { | ||
return []*cli.Command{ | ||
{ | ||
Name: "list", | ||
Usage: "narc device tenant list", | ||
Action: func(context *cli.Context) error { | ||
for _, tenant := range naisdevice.Tenants { | ||
fmt.Println(tenant) | ||
} | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "set", | ||
Usage: "narc device tenant set [tenant]", | ||
ArgsUsage: "name of the tenant", | ||
Action: func(ctx *cli.Context) error { | ||
if ctx.Args().Len() != 1 { | ||
return fmt.Errorf("missing required arguments: tenant name") | ||
} | ||
|
||
tenant := strings.TrimSpace(ctx.Args().First()) | ||
if !slices.Contains(naisdevice.Tenants, tenant) { | ||
return fmt.Errorf("unknown tenant %v, must be one of: %v", tenant, naisdevice.Tenants) | ||
} | ||
|
||
err := naisdevice.SetTenant(ctx.Context, tenant) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("Tenant has been set to ", tenant) | ||
|
||
return nil | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/nais/narcos/cmd/commands/clusterCmd" | ||
"github.com/nais/narcos/cmd/commands/deviceCmd" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func main() { | ||
app := &cli.App{ | ||
Name: "narc", | ||
Usage: "NAIS Administrator CLI", | ||
Version: "v0.1", | ||
Description: "NAIS Administrator CLI", | ||
Commands: []*cli.Command{ | ||
deviceCmd.Command(), | ||
clusterCmd.Command(), | ||
}, | ||
EnableBashCompletion: true, | ||
HideHelpCommand: true, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module github.com/nais/narcos | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/nais/device v0.0.0-20230606131307-0fe402bccc46 | ||
github.com/urfave/cli/v2 v2.25.5 | ||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 | ||
google.golang.org/api v0.125.0 | ||
google.golang.org/grpc v1.55.0 | ||
) | ||
|
||
require ( | ||
cloud.google.com/go/compute v1.20.0 // indirect | ||
cloud.google.com/go/compute/metadata v0.2.3 // indirect | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/s2a-go v0.1.4 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect | ||
github.com/googleapis/gax-go/v2 v2.10.0 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/stretchr/objx v0.5.0 // indirect | ||
github.com/stretchr/testify v1.8.1 // indirect | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect | ||
go.opencensus.io v0.24.0 // indirect | ||
golang.org/x/crypto v0.9.0 // indirect | ||
golang.org/x/net v0.10.0 // indirect | ||
golang.org/x/oauth2 v0.8.0 // indirect | ||
golang.org/x/sys v0.8.0 // indirect | ||
golang.org/x/text v0.9.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.