Skip to content

Commit

Permalink
support server enroll (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alva8756 authored Nov 20, 2023
1 parent ff4fc3d commit 2064b67
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 16 deletions.
1 change: 1 addition & 0 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ func init() {
create.AddCommand(createFirmware)
create.AddCommand(createFirmwareSet)
create.AddCommand(uploadBomFile)
create.AddCommand(serverEnroll)
}
97 changes: 97 additions & 0 deletions cmd/create/serverenroll.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package create

import (
"context"
"encoding/json"
"log"

"github.com/spf13/cobra"

"github.com/metal-toolbox/mctl/internal/app"

coapiv1 "github.com/metal-toolbox/conditionorc/pkg/api/v1/types"
mctl "github.com/metal-toolbox/mctl/cmd"
)

type serverEnrollParams struct {
serverID string
facility string
ip string
username string
password string
}

var (
serverEnrollFlags *serverEnrollParams
)

var serverEnroll = &cobra.Command{
Use: "server-enroll",
Short: "Enroll server and publish conditions",
Run: func(cmd *cobra.Command, args []string) {
enrollServer(cmd.Context())
},
}

func enrollServer(ctx context.Context) {
theApp := mctl.MustCreateApp(ctx)

params, err := json.Marshal(coapiv1.AddServerParams{
Facility: serverEnrollFlags.facility,
IP: serverEnrollFlags.ip,
Username: serverEnrollFlags.username,
Password: serverEnrollFlags.password,
})
if err != nil {
log.Fatal(err)
}

conditionCreate := coapiv1.ConditionCreate{
Exclusive: false,
Parameters: params,
}

client, err := app.NewConditionsClient(ctx, theApp.Config.Conditions, theApp.Reauth)
if err != nil {
log.Fatal(err)
}

response, err := client.ServerEnroll(ctx, serverEnrollFlags.serverID, conditionCreate)
if err != nil {
log.Fatal(err)
}

condition, err := mctl.ConditionFromResponse(response)
if err != nil {
log.Fatal(err)
}

log.Printf("status=%d\nmsg=%s\nconditionID=%s\nserverID=%v", response.StatusCode, response.Message, condition.ID, response.Records.ServerID)

}

func init() {
serverEnrollFlags = &serverEnrollParams{}

serverEnroll.PersistentFlags().StringVar(&serverEnrollFlags.serverID, "server-id", "", "server id to be created. New id will be created if null.")
serverEnroll.PersistentFlags().StringVar(&serverEnrollFlags.facility, "facility", "", "facility of the server")
serverEnroll.PersistentFlags().StringVar(&serverEnrollFlags.ip, "ip", "", "ip of the server")
serverEnroll.PersistentFlags().StringVar(&serverEnrollFlags.username, "user", "", "username of the server")
serverEnroll.PersistentFlags().StringVar(&serverEnrollFlags.password, "pwd", "", "password of the server")

if err := serverEnroll.MarkPersistentFlagRequired("facility"); err != nil {
log.Fatal(err)
}

if err := serverEnroll.MarkPersistentFlagRequired("ip"); err != nil {
log.Fatal(err)
}

if err := serverEnroll.MarkPersistentFlagRequired("user"); err != nil {
log.Fatal(err)
}

if err := serverEnroll.MarkPersistentFlagRequired("pwd"); err != nil {
log.Fatal(err)
}
}
1 change: 1 addition & 0 deletions docs/mctl_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ mctl create [flags]
* [mctl create bom](mctl_create_bom.md) - Upload Bom File
* [mctl create firmware](mctl_create_firmware.md) - Create firmware
* [mctl create firmware-set](mctl_create_firmware-set.md) - Create a firmware set
* [mctl create server-enroll](mctl_create_server-enroll.md) - Enroll server and publish conditions

32 changes: 32 additions & 0 deletions docs/mctl_create_server-enroll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[Auto generated by spf13/cobra]: <>

## mctl create server-enroll

Enroll server and publish conditions

```
mctl create server-enroll [flags]
```

### Options

```
--facility string facility of the server
-h, --help help for server-enroll
--ip string ip of the server
--pwd string password of the server
--server-id string server id to be created. New id will be created if null.
--user string username of the server
```

### Options inherited from parent commands

```
--config string config file (default is $XDG_CONFIG_HOME/mctl/config.yml)
--reauth re-authenticate with oauth services
```

### SEE ALSO

* [mctl create](mctl_create.md) - Create resources

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/bmc-toolbox/common v0.0.0-20230717121556-5eb9915a8a5a
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/google/uuid v1.3.1
github.com/metal-toolbox/conditionorc v0.1.10
github.com/google/uuid v1.4.0
github.com/metal-toolbox/conditionorc v0.1.12
github.com/metal-toolbox/hollow-bomservice v0.1.1
github.com/metal-toolbox/rivets v0.0.0-20231020103738-10fc2993b885
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c
Expand Down Expand Up @@ -43,7 +43,7 @@ require (
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
Expand Down Expand Up @@ -132,7 +132,7 @@ require (
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.148.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ=
Expand Down Expand Up @@ -313,8 +313,8 @@ github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8=
github.com/googleapis/enterprise-certificate-proxy v0.3.1 h1:SBWmZhjUDRorQxrN0nwzf+AHBxnbFjViHQS4P0yVpmQ=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
Expand Down Expand Up @@ -511,8 +511,8 @@ github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/metal-toolbox/conditionorc v0.1.10 h1:CLkWlaJdd5EUST0QIiuMwAfgJzRMh8wEVX4ERz+XrqM=
github.com/metal-toolbox/conditionorc v0.1.10/go.mod h1:vLgTd+RSfbiYZ5doIVfrMVhClFSJbNWZK03MV9b5xVE=
github.com/metal-toolbox/conditionorc v0.1.12 h1:EwmMiLa3aznJ4P8G1aHPAS5VLo9EscJKXPhkFzXDCz4=
github.com/metal-toolbox/conditionorc v0.1.12/go.mod h1:WzyuNziOjdqhzSXX4PtGWlEpUNlRb8batYTO+J/lBJU=
github.com/metal-toolbox/hollow-bomservice v0.1.1 h1:Pll/HqF8Dff0jKo9B8ywcF9bfwTBmIIQpWcAWL3mYiM=
github.com/metal-toolbox/hollow-bomservice v0.1.1/go.mod h1:v37wkZnVs/PTlfF/t6/aoMO48yE9XDCpog8kFr0R/yY=
github.com/metal-toolbox/rivets v0.0.0-20231020103738-10fc2993b885 h1:mpJZhvW/Mi1pclg7OhhRVRBlXKl2eUQ6HlgVfTcQ2Bw=
Expand Down Expand Up @@ -545,7 +545,7 @@ github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/jwt/v2 v2.5.2 h1:DhGH+nKt+wIkDxM6qnVSKjokq5t59AZV5HRcFW0zJwU=
github.com/nats-io/nats-server/v2 v2.10.1 h1:MIJ614dhOIdo71iSzY8ln78miXwrYvlvXHUyS+XdKZQ=
github.com/nats-io/nats-server/v2 v2.10.4 h1:uB9xcwon3tPXWAdmTJqqqC6cie3yuPWHJjjTBgaPNus=
github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E=
github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8=
github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY=
Expand Down Expand Up @@ -747,7 +747,7 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
Expand Down Expand Up @@ -1230,10 +1230,10 @@ google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3/go.mod h1:8w6bsBMX
google.golang.org/genproto v0.0.0-20220429170224-98d788798c3e/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a h1:fwgW9j3vHirt4ObdHoYNwuO24BEZjSzbh+zPaNWoiY8=
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b h1:CIC2YMXmIhYw6evmhPxBKJ4fmLbOFtXQN/GV3XOZR8k=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA=
google.golang.org/genproto/googleapis/api v0.0.0-20231030173426-d783a09b4405 h1:HJMDndgxest5n2y77fnErkM62iUsptE/H8p0dC2Huo4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 h1:AB/lmRny7e2pLhFEYIbl5qkDAUt2h0ZRO4wGPhZf+ik=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405/go.mod h1:67X1fPuzjcrkymZzZV1vvkFeTn2Rvc6lYF9MYFGCcwE=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down

0 comments on commit 2064b67

Please sign in to comment.