Skip to content

Commit d37fdc5

Browse files
authored
feat: [#440] Create user and assign roles. (#447)
1 parent 2aefee5 commit d37fdc5

File tree

23 files changed

+801
-54
lines changed

23 files changed

+801
-54
lines changed

Diff for: .github/dependabot.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ updates:
44
- package-ecosystem: 'docker'
55
directory: '/'
66
schedule:
7-
interval: 'weekly'
7+
interval: 'daily'
88
- package-ecosystem: 'github-actions'
99
directory: '/'
1010
schedule:
11-
interval: 'weekly'
11+
interval: 'daily'
1212
- package-ecosystem: 'gomod'
1313
directory: '/'
1414
schedule:
15-
interval: 'weekly'
15+
interval: 'daily'

Diff for: .github/workflows/dip.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
- name: Set up Go
2424
uses: actions/[email protected]
2525
with:
26-
go-version: 1.19.0
26+
go-version-file: 'go.mod'
27+
cache: false
2728
- name: Check Golang
2829
run: |
2930
./dip image --name=golang --regex=^1\.[0-9]+\.[0-9]+-alpine3\.[0-9]+$ --updateDockerfile

Diff for: .github/workflows/go.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
- name: Set up Go
2222
uses: actions/[email protected]
2323
with:
24-
go-version: 1.19.0
24+
go-version-file: 'go.mod'
25+
cache: false
2526
- name: Unit tests
2627
run: |
2728
go test -short -cover -v -coverprofile=coverage.txt \

Diff for: .github/workflows/integration.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/[email protected]
12-
- name: Set up Go
13-
uses: actions/[email protected]
12+
- uses: actions/[email protected]
1413
with:
15-
go-version: 1.19.0
14+
go-version-file: 'go.mod'
15+
cache: false
1616
- name: Install bats
1717
run: |
1818
set -x

Diff for: .github/workflows/release.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
- name: Set up Go
2222
uses: actions/[email protected]
2323
with:
24-
go-version: 1.19.0
24+
go-version-file: 'go.mod'
25+
cache: false
2526
- name: Set N3DR deliverable environment variable
2627
run: echo "n3dr-deliverable=n3dr-${{ matrix.os }}" >> $GITHUB_ENV
2728
if: |

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ dip
1010
test/gpg/my_rsa_key
1111
test/rproxy-nginx-nexus3.conf.tmp
1212

13-
.vagrant
13+
.vagrant
14+
15+
coverage*

Diff for: .golangci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ issues:
1717
- gochecknoinits
1818
path: cmd/n3dr/configUser.go
1919
text: "don't use `init` function"
20+
- linters:
21+
- gochecknoinits
22+
path: cmd/n3dr/configRole.go
23+
text: "don't use `init` function"
2024
- linters:
2125
- gochecknoinits
2226
path: cmd/n3dr/count.go

Diff for: Taskfile.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
version: '3'
3+
4+
env:
5+
GIT_CHGLOG_URL: https://github.com/git-chglog/git-chglog/releases/download
6+
GIT_CHGLOG_VERSION: v0.15.1/git-chglog_0.15.1_linux_amd64.tar.gz
7+
CHANGELOG_NEXT_TAG: 7.4.0
8+
9+
tasks:
10+
changelog:
11+
cmds:
12+
- |
13+
git fetch -p -P
14+
curl \
15+
-L ${GIT_CHGLOG_URL}/${GIT_CHGLOG_VERSION} \
16+
-o /tmp/git-chglog.tar.gz
17+
tar -xvf /tmp/git-chglog.tar.gz -C /tmp
18+
chmod +x /tmp/git-chglog
19+
/tmp/git-chglog \
20+
-o docs/CHANGELOG.md \
21+
--config configs/chglog/config.yml \
22+
--next-tag ${CHANGELOG_NEXT_TAG}
23+
sed -i "s|\/\([0-9]\+\.\)\{2\}[0-9]\+|/${CHANGELOG_NEXT_TAG}|g" \
24+
./docs/quickstarts/snippets/n3dr/DOWNLOAD.md
25+
sed -i "s|version:.*|version: ${CHANGELOG_NEXT_TAG}|" \
26+
./build/package/snap/snapcraft.yaml
27+
integration-tests:
28+
cmds:
29+
- |
30+
go test \
31+
-coverprofile=coverage.cov \
32+
--tags=integration \
33+
-v \
34+
-count=1 \
35+
--cover \
36+
-race \
37+
-p=4 \
38+
./...
39+
go tool cover -func=coverage.cov > coverage-functions.out
40+
go tool cover -html=coverage.cov -o coverage.html
41+
open ./coverage.html
42+
lint:
43+
cmds:
44+
- |
45+
go install github.com/golangci/golangci-lint/cmd/[email protected]
46+
~/go/bin/golangci-lint --version
47+
~/go/bin/golangci-lint run \
48+
-v \
49+
--timeout 2m30s \
50+
--config .golangci.yml

Diff for: build/package/snap/snapcraft.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: n3dr
33
base: core20
4-
version: 7.3.3
4+
version: 7.4.0
55
summary: Nexus3 Disaster Recovery
66
description: |
77
Download all artifacts at once or migrate automatically from Nexus to Nexus.

Diff for: cmd/n3dr/configRole.go

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package main
2+
3+
import (
4+
"github.com/030/n3dr/internal/app/n3dr/config/user"
5+
"github.com/030/n3dr/internal/app/n3dr/connection"
6+
"github.com/030/n3dr/internal/app/n3dr/goswagger/models"
7+
log "github.com/sirupsen/logrus"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var downloadRole, uploadRole bool
12+
13+
// configUserCmd represents the configUser command.
14+
var configRoleCmd = &cobra.Command{
15+
Use: "configRole",
16+
Short: "Configure roles.",
17+
Long: `Create roles.
18+
19+
Examples:
20+
# Create a download role:
21+
n3dr configRole --downloadRole
22+
23+
# Create an upload role:
24+
n3dr configRole --uploadRole --https=false --n3drPass X --n3drUser admin --n3drURL localhost:9999
25+
`,
26+
Run: func(cmd *cobra.Command, args []string) {
27+
if !downloadRole && !uploadRole {
28+
log.Fatal("either the downloadRole or uploadRole is required")
29+
}
30+
31+
acu := models.APICreateUser{
32+
EmailAddress: email,
33+
FirstName: firstName,
34+
LastName: lastName,
35+
Password: pass,
36+
UserID: id,
37+
}
38+
n := connection.Nexus3{
39+
FQDN: n3drURL,
40+
HTTPS: &https,
41+
Pass: n3drPass,
42+
User: n3drUser,
43+
}
44+
u := user.User{APICreateUser: acu, Nexus3: n}
45+
46+
if downloadRole {
47+
u.Roles = []string{"nx-download"}
48+
rr := models.RoleXORequest{
49+
ID: "nx-download",
50+
Name: "nx-download",
51+
Privileges: []string{
52+
"nx-repository-view-*-*-browse",
53+
"nx-repository-view-*-*-read",
54+
},
55+
}
56+
r := user.Role{RoleXORequest: rr, Nexus3: n}
57+
if err := r.CreateRole(); err != nil {
58+
log.Fatal(err)
59+
}
60+
}
61+
62+
if uploadRole {
63+
u.Roles = []string{"nx-upload"}
64+
rr := models.RoleXORequest{
65+
ID: "nx-upload",
66+
Name: "nx-upload",
67+
Privileges: []string{
68+
"nx-repository-view-*-*-add",
69+
"nx-repository-view-*-*-edit",
70+
},
71+
}
72+
r := user.Role{RoleXORequest: rr, Nexus3: n}
73+
if err := r.CreateRole(); err != nil {
74+
log.Fatal(err)
75+
}
76+
}
77+
},
78+
}
79+
80+
func init() {
81+
rootCmd.AddCommand(configRoleCmd)
82+
83+
configRoleCmd.Flags().BoolVar(&downloadRole, "downloadRole", false, "Whether a download role should be created")
84+
configRoleCmd.Flags().BoolVar(&uploadRole, "uploadRole", false, "Whether an upload role should be created")
85+
}

Diff for: cmd/n3dr/configUser.go

+30-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
)
1010

1111
var (
12-
admin, changePass, downloadUser, uploadUser bool
13-
email, firstName, id, lastName, pass string
12+
admin, changePass, custom, downloadUser, uploadUser bool
13+
email, firstName, id, lastName, pass string
14+
roles []string
1415
)
1516

1617
// configUserCmd represents the configUser command.
@@ -20,19 +21,32 @@ var configUserCmd = &cobra.Command{
2021
Long: `Create users or change their passwords.
2122
2223
Examples:
24+
# Create an admin user:
25+
n3dr configUser --pass some-pass --email [email protected] --firstName build --id build --lastName build --admin
26+
27+
# Create a download user:
28+
n3dr configUser --pass some-pass --email [email protected] --firstName build --id build --lastName build --downloadUser
29+
30+
# Create an upload user:
31+
n3dr configUser --pass some-pass --email [email protected] --firstName build --id build --lastName build --uploadUser
32+
33+
# Create a custom user and assign certain roles:
34+
n3dr configUser --pass some-pass --email [email protected] --firstName build --id build --lastName build --roles nx-download,nx-upload --custom
35+
2336
# Change the admin password:
2437
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
2538
`,
2639
Run: func(cmd *cobra.Command, args []string) {
27-
if !admin && !downloadUser && !uploadUser && !changePass {
28-
log.Fatal("either the admin, changePass, downloadUser or uploadUser is required")
40+
if !admin && !custom && !downloadUser && !uploadUser && !changePass {
41+
log.Fatal("either the admin, custom, changePass, create, downloadUser or uploadUser is required")
2942
}
3043

3144
acu := models.APICreateUser{
3245
EmailAddress: email,
3346
FirstName: firstName,
3447
LastName: lastName,
3548
Password: pass,
49+
Roles: roles,
3650
UserID: id,
3751
}
3852
n := connection.Nexus3{
@@ -50,6 +64,15 @@ Examples:
5064
}
5165
}
5266

67+
if custom {
68+
u.Roles = roles
69+
log.Info("roles:", u)
70+
71+
if err := u.Create(); err != nil {
72+
log.Fatal(err)
73+
}
74+
}
75+
5376
if downloadUser {
5477
u.Roles = []string{"nx-download"}
5578
rr := models.RoleXORequest{
@@ -125,7 +148,10 @@ func init() {
125148
}
126149

127150
configUserCmd.Flags().BoolVar(&admin, "admin", false, "Whether a user should be admin")
151+
configUserCmd.Flags().BoolVar(&custom, "custom", false, "Create a user and assign certain roles")
128152
configUserCmd.Flags().BoolVar(&downloadUser, "downloadUser", false, "Whether a user should be able to download")
129153
configUserCmd.Flags().BoolVar(&uploadUser, "uploadUser", false, "Whether a user should be able to upload")
130154
configUserCmd.Flags().BoolVar(&changePass, "changePass", false, "Whether a pass should be changed")
155+
156+
configUserCmd.Flags().StringSliceVar(&roles, "roles", nil, "Which roles have to be assigned to the custom user")
131157
}

Diff for: docs/CHANGELOG.md

+44-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,51 @@
22
## [Unreleased]
33

44

5+
<a name="7.4.0"></a>
6+
## [7.4.0] - 2024-02-03
7+
### Build
8+
- [[#423](https://github.com/030/n3dr/issues/423)] Add golang action. ([#424](https://github.com/030/n3dr/issues/424))
9+
- Replace separate hadolint, dockle and trivy by one workflow. ([#417](https://github.com/030/n3dr/issues/417))
10+
- **deps:** bump github.com/spf13/viper from 1.17.0 to 1.18.2 ([#426](https://github.com/030/n3dr/issues/426))
11+
- **deps:** bump github.com/go-openapi/swag from 0.22.4 to 0.22.9 ([#454](https://github.com/030/n3dr/issues/454))
12+
- **deps:** bump github.com/aws/aws-sdk-go from 1.48.16 to 1.50.5 ([#453](https://github.com/030/n3dr/issues/453))
13+
- **deps:** bump golang.org/x/crypto from 0.14.0 to 0.17.0 ([#416](https://github.com/030/n3dr/issues/416))
14+
- **deps:** bump alpine from 3.19.0 to 3.19.1 ([#455](https://github.com/030/n3dr/issues/455))
15+
- **deps:** bump schubergphilis/mcvs-golang-action from 0.2.2 to 0.2.3 ([#457](https://github.com/030/n3dr/issues/457))
16+
- **deps:** bump EndBug/add-and-commit from 9.1.3 to 9.1.4 ([#458](https://github.com/030/n3dr/issues/458))
17+
- **deps:** bump schubergphilis/mcvs-golang-action from 0.1.1 to 0.2.2 ([#448](https://github.com/030/n3dr/issues/448))
18+
- **deps:** bump schubergphilis/mcvs-docker-action from 0.2.1 to 0.3.2 ([#449](https://github.com/030/n3dr/issues/449))
19+
- **deps:** bump github.com/go-playground/validator/v10 ([#444](https://github.com/030/n3dr/issues/444))
20+
- **deps:** bump golang from 1.21.5-alpine3.18 to 1.21.6-alpine3.18 ([#445](https://github.com/030/n3dr/issues/445))
21+
- **deps:** bump alpine from 3.18.5 to 3.19.0 ([#413](https://github.com/030/n3dr/issues/413))
22+
- **deps:** bump github.com/go-openapi/strfmt from 0.21.7 to 0.22.0 ([#434](https://github.com/030/n3dr/issues/434))
23+
- **deps:** bump schubergphilis/mcvs-docker-action from 0.2.0 to 0.2.1 ([#427](https://github.com/030/n3dr/issues/427))
24+
- **deps:** bump codecov/codecov-action from 3.1.4 to 4.0.1 ([#463](https://github.com/030/n3dr/issues/463))
25+
- **deps:** bump github.com/go-openapi/runtime from 0.26.0 to 0.27.1 ([#452](https://github.com/030/n3dr/issues/452))
26+
- **deps:** bump github.com/samber/lo from 1.38.1 to 1.39.0 ([#389](https://github.com/030/n3dr/issues/389))
27+
- **deps:** bump github.com/hashicorp/go-retryablehttp ([#392](https://github.com/030/n3dr/issues/392))
28+
- **deps:** bump github.com/spf13/cobra from 1.7.0 to 1.8.0 ([#393](https://github.com/030/n3dr/issues/393))
29+
- **deps:** bump github.com/aws/aws-sdk-go from 1.45.25 to 1.48.16 ([#406](https://github.com/030/n3dr/issues/406))
30+
- **deps:** bump golang from 1.21.0-alpine3.18 to 1.21.5-alpine3.18 ([#405](https://github.com/030/n3dr/issues/405))
31+
- **deps:** bump github.com/go-openapi/validate from 0.22.1 to 0.22.3 ([#388](https://github.com/030/n3dr/issues/388))
32+
- **deps:** bump alpine from 3.18.4 to 3.18.5 ([#387](https://github.com/030/n3dr/issues/387))
33+
34+
### Feat
35+
- [[#440](https://github.com/030/n3dr/issues/440)] Create user and assign roles.
36+
37+
### Fix
38+
- [[#428](https://github.com/030/n3dr/issues/428)] Resolve race condition. ([#435](https://github.com/030/n3dr/issues/435))
39+
- [[#430](https://github.com/030/n3dr/issues/430)] Use semantic version. ([#432](https://github.com/030/n3dr/issues/432))
40+
- [[#430](https://github.com/030/n3dr/issues/430)] Do not run Sonar if dependabot branch. ([#431](https://github.com/030/n3dr/issues/431))
41+
- [[#428](https://github.com/030/n3dr/issues/428)] Resolve data race condition in upload. ([#429](https://github.com/030/n3dr/issues/429))
42+
- Ensure that integration tests are skipped on dep updates. ([#420](https://github.com/030/n3dr/issues/420))
43+
44+
545
<a name="7.3.3"></a>
646
## [7.3.3] - 2023-12-09
747
### Build
8-
- **deps:** [[#399](https://github.com/030/n3dr/issues/399)] Use semantic versioning for plugins in github actions.
48+
- **deps:** [[#399](https://github.com/030/n3dr/issues/399)] V is omitted in upload-release-action. ([#404](https://github.com/030/n3dr/issues/404))
49+
- **deps:** [[#399](https://github.com/030/n3dr/issues/399)] Use semantic versioning for plugins in github actions. ([#403](https://github.com/030/n3dr/issues/403))
950
- **deps:** bump actions/checkout from 3 to 4 ([#394](https://github.com/030/n3dr/issues/394))
1051

1152
### Fix
@@ -413,7 +454,8 @@ The `backup`, `upload` and `repositories` commands have been removed.
413454
<a name="1.0.0"></a>
414455
## 1.0.0 - 2019-05-12
415456

416-
[Unreleased]: https://github.com/030/n3dr/compare/7.3.3...HEAD
457+
[Unreleased]: https://github.com/030/n3dr/compare/7.4.0...HEAD
458+
[7.4.0]: https://github.com/030/n3dr/compare/7.3.3...7.4.0
417459
[7.3.3]: https://github.com/030/n3dr/compare/7.3.2...7.3.3
418460
[7.3.2]: https://github.com/030/n3dr/compare/7.3.1...7.3.2
419461
[7.3.1]: https://github.com/030/n3dr/compare/7.3.0...7.3.1

Diff for: docs/instructions/task.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# task
2+
3+
```bash
4+
go install github.com/go-task/task/v3/cmd/[email protected]
5+
~/go/bin/task integration-tests
6+
```

Diff for: docs/quickstarts/snippets/n3dr/DOWNLOAD.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Download
22

3-
Download the [latest N3DR binary](https://github.com/030/n3dr/releases/tag/7.3.3):
3+
Download the [latest N3DR binary](https://github.com/030/n3dr/releases/tag/7.4.0):
44

55
```bash
66
cd /tmp && \
7-
curl -L https://github.com/030/n3dr/releases/download/7.3.3/n3dr-ubuntu-latest \
7+
curl -L https://github.com/030/n3dr/releases/download/7.4.0/n3dr-ubuntu-latest \
88
-o n3dr-ubuntu-latest && \
9-
curl -L https://github.com/030/n3dr/releases/download/7.3.3/\
9+
curl -L https://github.com/030/n3dr/releases/download/7.4.0/\
1010
n3dr-ubuntu-latest.sha512.txt \
1111
-o n3dr-ubuntu-latest.sha512.txt && \
1212
sha512sum -c n3dr-ubuntu-latest.sha512.txt && \

0 commit comments

Comments
 (0)