forked from uyuni-project/uyuni-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateFirst.go
More file actions
44 lines (36 loc) · 1.27 KB
/
Copy pathcreateFirst.go
File metadata and controls
44 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-FileCopyrightText: 2026 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0
package org
import (
"errors"
"github.com/uyuni-project/uyuni-tools/shared/api"
"github.com/uyuni-project/uyuni-tools/shared/api/types"
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
"github.com/uyuni-project/uyuni-tools/shared/utils"
)
// CreateFirst creates the first organization and user after initial setup without authentication.
//
// orgName is the name of the first organization to create and admin the user to create.
func CreateFirst(cnxDetails *api.ConnectionDetails, orgName string, admin *types.User) (*types.Organization, error) {
client, err := api.Init(cnxDetails)
if err != nil {
return nil, utils.Errorf(err, L("unable to prepare API client"))
}
data := map[string]interface{}{
"orgName": orgName,
"adminLogin": admin.Login,
"adminPassword": admin.Password,
"firstName": admin.FirstName,
"lastName": admin.LastName,
"email": admin.Email,
}
res, err := api.PostChecked[types.Organization](client, "org/createFirst", "api.org.create_first", data)
if err != nil {
return nil, utils.Errorf(err, L("failed to create first user and organization"))
}
if !res.Success {
return nil, errors.New(res.Message)
}
return &res.Result, nil
}