-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
23 changed files
with
801 additions
and
54 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
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 |
---|---|---|
|
@@ -23,7 +23,8 @@ jobs: | |
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: 1.19.0 | ||
go-version-file: 'go.mod' | ||
cache: false | ||
- name: Check Golang | ||
run: | | ||
./dip image --name=golang --regex=^1\.[0-9]+\.[0-9]+-alpine3\.[0-9]+$ --updateDockerfile | ||
|
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 |
---|---|---|
|
@@ -21,7 +21,8 @@ jobs: | |
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: 1.19.0 | ||
go-version-file: 'go.mod' | ||
cache: false | ||
- name: Unit tests | ||
run: | | ||
go test -short -cover -v -coverprofile=coverage.txt \ | ||
|
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 |
---|---|---|
|
@@ -9,10 +9,10 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Set up Go | ||
uses: actions/[email protected] | ||
- uses: actions/[email protected] | ||
with: | ||
go-version: 1.19.0 | ||
go-version-file: 'go.mod' | ||
cache: false | ||
- name: Install bats | ||
run: | | ||
set -x | ||
|
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 |
---|---|---|
|
@@ -21,7 +21,8 @@ jobs: | |
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: 1.19.0 | ||
go-version-file: 'go.mod' | ||
cache: false | ||
- name: Set N3DR deliverable environment variable | ||
run: echo "n3dr-deliverable=n3dr-${{ matrix.os }}" >> $GITHUB_ENV | ||
if: | | ||
|
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 |
---|---|---|
|
@@ -10,4 +10,6 @@ dip | |
test/gpg/my_rsa_key | ||
test/rproxy-nginx-nexus3.conf.tmp | ||
|
||
.vagrant | ||
.vagrant | ||
|
||
coverage* |
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
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,50 @@ | ||
--- | ||
version: '3' | ||
|
||
env: | ||
GIT_CHGLOG_URL: https://github.com/git-chglog/git-chglog/releases/download | ||
GIT_CHGLOG_VERSION: v0.15.1/git-chglog_0.15.1_linux_amd64.tar.gz | ||
CHANGELOG_NEXT_TAG: 7.4.0 | ||
|
||
tasks: | ||
changelog: | ||
cmds: | ||
- | | ||
git fetch -p -P | ||
curl \ | ||
-L ${GIT_CHGLOG_URL}/${GIT_CHGLOG_VERSION} \ | ||
-o /tmp/git-chglog.tar.gz | ||
tar -xvf /tmp/git-chglog.tar.gz -C /tmp | ||
chmod +x /tmp/git-chglog | ||
/tmp/git-chglog \ | ||
-o docs/CHANGELOG.md \ | ||
--config configs/chglog/config.yml \ | ||
--next-tag ${CHANGELOG_NEXT_TAG} | ||
sed -i "s|\/\([0-9]\+\.\)\{2\}[0-9]\+|/${CHANGELOG_NEXT_TAG}|g" \ | ||
./docs/quickstarts/snippets/n3dr/DOWNLOAD.md | ||
sed -i "s|version:.*|version: ${CHANGELOG_NEXT_TAG}|" \ | ||
./build/package/snap/snapcraft.yaml | ||
integration-tests: | ||
cmds: | ||
- | | ||
go test \ | ||
-coverprofile=coverage.cov \ | ||
--tags=integration \ | ||
-v \ | ||
-count=1 \ | ||
--cover \ | ||
-race \ | ||
-p=4 \ | ||
./... | ||
go tool cover -func=coverage.cov > coverage-functions.out | ||
go tool cover -html=coverage.cov -o coverage.html | ||
open ./coverage.html | ||
lint: | ||
cmds: | ||
- | | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
~/go/bin/golangci-lint --version | ||
~/go/bin/golangci-lint run \ | ||
-v \ | ||
--timeout 2m30s \ | ||
--config .golangci.yml |
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
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,85 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/030/n3dr/internal/app/n3dr/config/user" | ||
"github.com/030/n3dr/internal/app/n3dr/connection" | ||
"github.com/030/n3dr/internal/app/n3dr/goswagger/models" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var downloadRole, uploadRole bool | ||
|
||
// configUserCmd represents the configUser command. | ||
var configRoleCmd = &cobra.Command{ | ||
Use: "configRole", | ||
Short: "Configure roles.", | ||
Long: `Create roles. | ||
Examples: | ||
# Create a download role: | ||
n3dr configRole --downloadRole | ||
# Create an upload role: | ||
n3dr configRole --uploadRole --https=false --n3drPass X --n3drUser admin --n3drURL localhost:9999 | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if !downloadRole && !uploadRole { | ||
log.Fatal("either the downloadRole or uploadRole is required") | ||
} | ||
|
||
acu := models.APICreateUser{ | ||
EmailAddress: email, | ||
FirstName: firstName, | ||
LastName: lastName, | ||
Password: pass, | ||
UserID: id, | ||
} | ||
n := connection.Nexus3{ | ||
FQDN: n3drURL, | ||
HTTPS: &https, | ||
Pass: n3drPass, | ||
User: n3drUser, | ||
} | ||
u := user.User{APICreateUser: acu, Nexus3: n} | ||
|
||
if downloadRole { | ||
u.Roles = []string{"nx-download"} | ||
rr := models.RoleXORequest{ | ||
ID: "nx-download", | ||
Name: "nx-download", | ||
Privileges: []string{ | ||
"nx-repository-view-*-*-browse", | ||
"nx-repository-view-*-*-read", | ||
}, | ||
} | ||
r := user.Role{RoleXORequest: rr, Nexus3: n} | ||
if err := r.CreateRole(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
if uploadRole { | ||
u.Roles = []string{"nx-upload"} | ||
rr := models.RoleXORequest{ | ||
ID: "nx-upload", | ||
Name: "nx-upload", | ||
Privileges: []string{ | ||
"nx-repository-view-*-*-add", | ||
"nx-repository-view-*-*-edit", | ||
}, | ||
} | ||
r := user.Role{RoleXORequest: rr, Nexus3: n} | ||
if err := r.CreateRole(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(configRoleCmd) | ||
|
||
configRoleCmd.Flags().BoolVar(&downloadRole, "downloadRole", false, "Whether a download role should be created") | ||
configRoleCmd.Flags().BoolVar(&uploadRole, "uploadRole", false, "Whether an upload role should be created") | ||
} |
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 |
---|---|---|
|
@@ -9,8 +9,9 @@ import ( | |
) | ||
|
||
var ( | ||
admin, changePass, downloadUser, uploadUser bool | ||
email, firstName, id, lastName, pass string | ||
admin, changePass, custom, downloadUser, uploadUser bool | ||
email, firstName, id, lastName, pass string | ||
roles []string | ||
) | ||
|
||
// configUserCmd represents the configUser command. | ||
|
@@ -20,19 +21,32 @@ var configUserCmd = &cobra.Command{ | |
Long: `Create users or change their passwords. | ||
Examples: | ||
# Create an admin user: | ||
n3dr configUser --pass some-pass --email [email protected] --firstName build --id build --lastName build --admin | ||
# Create a download user: | ||
n3dr configUser --pass some-pass --email [email protected] --firstName build --id build --lastName build --downloadUser | ||
# Create an upload user: | ||
n3dr configUser --pass some-pass --email [email protected] --firstName build --id build --lastName build --uploadUser | ||
# Create a custom user and assign certain roles: | ||
n3dr configUser --pass some-pass --email [email protected] --firstName build --id build --lastName build --roles nx-download,nx-upload --custom | ||
# Change the admin password: | ||
n3dr configUser --changePass --https=false --n3drUser admin --n3drURL nexus3:8081 --n3drPass initial-pass --pass some-pass --email [email protected] --firstName admin --id admin --lastName admin | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if !admin && !downloadUser && !uploadUser && !changePass { | ||
log.Fatal("either the admin, changePass, downloadUser or uploadUser is required") | ||
if !admin && !custom && !downloadUser && !uploadUser && !changePass { | ||
log.Fatal("either the admin, custom, changePass, create, downloadUser or uploadUser is required") | ||
} | ||
|
||
acu := models.APICreateUser{ | ||
EmailAddress: email, | ||
FirstName: firstName, | ||
LastName: lastName, | ||
Password: pass, | ||
Roles: roles, | ||
UserID: id, | ||
} | ||
n := connection.Nexus3{ | ||
|
@@ -50,6 +64,15 @@ Examples: | |
} | ||
} | ||
|
||
if custom { | ||
u.Roles = roles | ||
log.Info("roles:", u) | ||
|
||
if err := u.Create(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
if downloadUser { | ||
u.Roles = []string{"nx-download"} | ||
rr := models.RoleXORequest{ | ||
|
@@ -125,7 +148,10 @@ func init() { | |
} | ||
|
||
configUserCmd.Flags().BoolVar(&admin, "admin", false, "Whether a user should be admin") | ||
configUserCmd.Flags().BoolVar(&custom, "custom", false, "Create a user and assign certain roles") | ||
configUserCmd.Flags().BoolVar(&downloadUser, "downloadUser", false, "Whether a user should be able to download") | ||
configUserCmd.Flags().BoolVar(&uploadUser, "uploadUser", false, "Whether a user should be able to upload") | ||
configUserCmd.Flags().BoolVar(&changePass, "changePass", false, "Whether a pass should be changed") | ||
|
||
configUserCmd.Flags().StringSliceVar(&roles, "roles", nil, "Which roles have to be assigned to the custom user") | ||
} |
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
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,6 @@ | ||
# task | ||
|
||
```bash | ||
go install github.com/go-task/task/v3/cmd/[email protected] | ||
~/go/bin/task integration-tests | ||
``` |
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
Oops, something went wrong.