Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/public-api-demo/examples/system_information_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
62 changes: 62 additions & 0 deletions cmd/public-api-demo/examples/system_information_rancher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"version": "1",
"subscription": {
"installuuid": "a4b6c3d1-2e4f-4a7b-9c8d-5e6f7a8b9c0d",
"clusteruuid": "0bcf9fc5-e66a-4b36-bf6b-6a9d6a4c393e",
"product": "cpe:/a:suse:rancher:2.12.1",
"version": "2.12.1",
"git": "2b5a6c8f9d3e4a7b1c2d3e4f5a6b7c8d9e0f1a2b",
"arch": "x86_64",
"server_url": "https://rancher.example.com"
},
"feature_flags": [
"continuous-delivery",
"fleet",
"multi-cluster-management",
"harvester",
"rke2"
],
"managedSystems": [
{
"arch": "x86_64",
"cpu": 16,
"memory": 32768,
"count": 5
},
{
"arch": "x86_64",
"cpu": 8,
"memory": 16384,
"count": 12
},
{
"arch": "aarch64",
"cpu": 4,
"memory": 8192,
"count": 3
}
],
"managedClusters": [
{
"nodes": 3,
"upstream": true,
"count": 1
},
{
"nodes": 5,
"upstream": false,
"count": 2
},
{
"nodes": 10,
"upstream": false,
"count": 1
},
{
"nodes": 1,
"upstream": false,
"count": 1
}
],
"timestamp": "2025-01-15T10:30:45.123Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"arch": "x86_64",
"container_runtime": "docker",
"cpus": 8,
"hostname": "example",
"mem_total": 13854,
"sockets": 1,
"uuid": "3bf24e5b-6142-4ea9-8294-88b9a36b5d7f",
"uname": "6.12.6-1-default #1 SMP PREEMPT_DYNAMIC Thu Dec 19 17:23:25 UTC 2024 (fb072de)",
"arch_specs": {
"layer_type": "ONETYPE",
"type": "8561",
"type_name": "IBM LinuxONE III"
}
}
19 changes: 19 additions & 0 deletions cmd/public-api-demo/examples/system_information_with_sap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"arch": "x86_64",
"container_runtime": "docker",
"cpus": 8,
"hostname": "example",
"mem_total": 13854,
"sockets": 1,
"uuid": "3bf24e5b-6142-4ea9-8294-88b9a36b5d7f",
"sap": [
{
"system_id": "DEV",
"instance_types": [
"ASCS",
"J"
]
}
],
"uname": "6.12.6-1-default #1 SMP PREEMPT_DYNAMIC Thu Dec 19 17:23:25 UTC 2024 (fb072de)"
}
41 changes: 32 additions & 9 deletions cmd/public-api-demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"crypto/x509"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
Expand Down Expand Up @@ -31,12 +32,12 @@ func waitForUser(message string) {
}
}

func runDemo(identifier, version, arch, regcode string) error {
func runDemo(identifier, version, arch, infoPath, regcode string) error {
opts := connection.DefaultOptions("public-api-demo", "1.0", "DE")
isProxy := false
creds := &SccCredentials{}

if url := os.Getenv("REGISTRATION_HOST_URL"); url != "" {
if url := os.Getenv("SCC_HOST"); url != "" {
opts.URL = url
isProxy = true
}
Expand Down Expand Up @@ -65,6 +66,24 @@ func runDemo(identifier, version, arch, regcode string) error {
opts.Certificate = cert
}

systemInformation := registration.SystemInformation{
"uname": "public api demo",
}

if infoPath != "" {
data, readErr := os.ReadFile(infoPath)
if readErr != nil {
fmt.Fprintf(os.Stderr, "Error reading system information file: %v\n", readErr)
os.Exit(1)
}

parseErr := json.Unmarshal(data, &systemInformation)
if parseErr != nil {
fmt.Fprintf(os.Stderr, "Error unmarshalling system information JSON: %v\n", parseErr)
os.Exit(1)
}
}

bold("1) Setup connection and perform an request\n")
conn := connection.New(opts, &SccCredentials{})

Expand All @@ -86,7 +105,7 @@ func runDemo(identifier, version, arch, regcode string) error {
}

bold("2) Registering a client to SCC with a registration code\n")
id, regErr := registration.Register(conn, regcode, hostname, registration.NoSystemInformation, registration.NoExtraData)
id, regErr := registration.Register(conn, regcode, hostname, systemInformation, registration.NoExtraData)
if regErr != nil {
return regErr
}
Expand All @@ -101,14 +120,13 @@ func runDemo(identifier, version, arch, regcode string) error {
waitForUser("Registration complete")

bold("4) System status // Ping\n")
systemInformation := registration.SystemInformation{
"uname": "public api demo - ping",
}

extraData := registration.ExtraData{
"instance_data": "<document>{}</document>",
}

systemInformation["uname"] = "public api demo - ping"

status, statusErr := registration.Status(conn, hostname, systemInformation, extraData)
if statusErr != nil {
return statusErr
Expand Down Expand Up @@ -214,16 +232,21 @@ func runDemo(identifier, version, arch, regcode string) error {
func main() {
fmt.Println("public-api-demo: A connect client library demo")

if len(os.Args) != 4 {
fmt.Println("./public-api-demo IDENTIFIER VERSION ARCH")
if len(os.Args) < 4 || len(os.Args) > 5 {
fmt.Println("./public-api-demo IDENTIFIER VERSION ARCH <system_information>")
return
}

// Allow empty regcodes see registering against RMT without a registration
// code working
regcode := os.Getenv("REGCODE")

err := runDemo(os.Args[1], os.Args[2], os.Args[3], regcode)
systemInformationPath := ""
if len(os.Args) == 5 {
systemInformationPath = os.Args[4]
}

err := runDemo(os.Args[1], os.Args[2], os.Args[3], systemInformationPath, regcode)

if err != nil {
fmt.Printf("%s\n", err)
Expand Down