Move the API struct definitions into internal/weldr
This will prevent problems with import loops. client already imports weldr, so weldr cannot import client.
This commit is contained in:
parent
0f8e40bdf1
commit
971bafbc09
3 changed files with 24 additions and 20 deletions
|
|
@ -7,6 +7,8 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/weldr"
|
||||
)
|
||||
|
||||
// PostTOMLBlueprintV0 sends a TOML blueprint string to the API
|
||||
|
|
@ -73,7 +75,7 @@ func ListBlueprintsV0(socket *http.Client) ([]string, *APIResponse, error) {
|
|||
if resp != nil || err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
var list BlueprintsListV0
|
||||
var list weldr.BlueprintsListV0
|
||||
err = json.Unmarshal(body, &list)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
|
@ -91,30 +93,30 @@ func GetBlueprintInfoTOMLV0(socket *http.Client, bpName string) (string, *APIRes
|
|||
}
|
||||
|
||||
// GetBlueprintsInfoJSONV0 returns the requested blueprints and their changed state
|
||||
func GetBlueprintsInfoJSONV0(socket *http.Client, bpName string) (BlueprintsInfoV0, *APIResponse, error) {
|
||||
func GetBlueprintsInfoJSONV0(socket *http.Client, bpName string) (weldr.BlueprintsInfoV0, *APIResponse, error) {
|
||||
body, resp, err := GetRaw(socket, "GET", "/api/v0/blueprints/info/"+bpName)
|
||||
if resp != nil || err != nil {
|
||||
return BlueprintsInfoV0{}, resp, err
|
||||
return weldr.BlueprintsInfoV0{}, resp, err
|
||||
}
|
||||
var info BlueprintsInfoV0
|
||||
var info weldr.BlueprintsInfoV0
|
||||
err = json.Unmarshal(body, &info)
|
||||
if err != nil {
|
||||
return BlueprintsInfoV0{}, nil, err
|
||||
return weldr.BlueprintsInfoV0{}, nil, err
|
||||
}
|
||||
return info, nil, nil
|
||||
}
|
||||
|
||||
// GetBlueprintsChangesV0 returns the changes to the listed blueprints
|
||||
func GetBlueprintsChangesV0(socket *http.Client, bpNames []string) (BlueprintsChangesV0, *APIResponse, error) {
|
||||
func GetBlueprintsChangesV0(socket *http.Client, bpNames []string) (weldr.BlueprintsChangesV0, *APIResponse, error) {
|
||||
names := strings.Join(bpNames, ",")
|
||||
body, resp, err := GetRaw(socket, "GET", "/api/v0/blueprints/changes/"+names)
|
||||
if resp != nil || err != nil {
|
||||
return BlueprintsChangesV0{}, resp, err
|
||||
return weldr.BlueprintsChangesV0{}, resp, err
|
||||
}
|
||||
var changes BlueprintsChangesV0
|
||||
var changes weldr.BlueprintsChangesV0
|
||||
err = json.Unmarshal(body, &changes)
|
||||
if err != nil {
|
||||
return BlueprintsChangesV0{}, nil, err
|
||||
return weldr.BlueprintsChangesV0{}, nil, err
|
||||
}
|
||||
return changes, nil, nil
|
||||
}
|
||||
|
|
@ -139,30 +141,30 @@ func TagBlueprintV0(socket *http.Client, blueprint string) (*APIResponse, error)
|
|||
}
|
||||
|
||||
// DepsolveBlueprintV0 depsolves the listed blueprint
|
||||
func DepsolveBlueprintV0(socket *http.Client, blueprint string) (BlueprintsDepsolveV0, *APIResponse, error) {
|
||||
func DepsolveBlueprintV0(socket *http.Client, blueprint string) (weldr.BlueprintsDepsolveV0, *APIResponse, error) {
|
||||
body, resp, err := GetRaw(socket, "GET", "/api/v0/blueprints/depsolve/"+blueprint)
|
||||
if resp != nil || err != nil {
|
||||
return BlueprintsDepsolveV0{}, resp, err
|
||||
return weldr.BlueprintsDepsolveV0{}, resp, err
|
||||
}
|
||||
var deps BlueprintsDepsolveV0
|
||||
var deps weldr.BlueprintsDepsolveV0
|
||||
err = json.Unmarshal(body, &deps)
|
||||
if err != nil {
|
||||
return BlueprintsDepsolveV0{}, nil, err
|
||||
return weldr.BlueprintsDepsolveV0{}, nil, err
|
||||
}
|
||||
return deps, nil, nil
|
||||
}
|
||||
|
||||
// FreezeBlueprintV0 depsolves the listed blueprint and returns the blueprint with frozen package
|
||||
// versions
|
||||
func FreezeBlueprintV0(socket *http.Client, blueprint string) (BlueprintsFreezeV0, *APIResponse, error) {
|
||||
func FreezeBlueprintV0(socket *http.Client, blueprint string) (weldr.BlueprintsFreezeV0, *APIResponse, error) {
|
||||
body, resp, err := GetRaw(socket, "GET", "/api/v0/blueprints/freeze/"+blueprint)
|
||||
if resp != nil || err != nil {
|
||||
return BlueprintsFreezeV0{}, resp, err
|
||||
return weldr.BlueprintsFreezeV0{}, resp, err
|
||||
}
|
||||
var frozen BlueprintsFreezeV0
|
||||
var frozen weldr.BlueprintsFreezeV0
|
||||
err = json.Unmarshal(body, &frozen)
|
||||
if err != nil {
|
||||
return BlueprintsFreezeV0{}, nil, err
|
||||
return weldr.BlueprintsFreezeV0{}, nil, err
|
||||
}
|
||||
return frozen, nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
// Package client - json contains Exported API response structures
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
// StatusV0 is the response to /api/status from a v0+ server
|
||||
type StatusV0 struct {
|
||||
API string `json:"api"`
|
||||
DBSupported bool `json:"db_supported"`
|
||||
DBVersion string `json:"db_version"`
|
||||
SchemaVersion string `json:"schema_version"`
|
||||
Backend string `json:"backend"`
|
||||
Build string `json:"build"`
|
||||
Messages []string `json:"messages"`
|
||||
}
|
||||
|
||||
// BlueprintsListV0 is the response to /blueprints/list request
|
||||
type BlueprintsListV0 struct {
|
||||
Total uint `json:"total"`
|
||||
Offset uint `json:"offset"`
|
||||
Limit uint `json:"limit"`
|
||||
Blueprints []string `json:"blueprints"`
|
||||
}
|
||||
|
||||
// ResponseError holds the API response error details
|
||||
type ResponseError struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
// BlueprintsInfoV0 is the response to /blueprints/info?format=json request
|
||||
type BlueprintsInfoV0 struct {
|
||||
Blueprints []blueprint.Blueprint `json:"blueprints"`
|
||||
Changes []infoChange `json:"changes"`
|
||||
Errors []ResponseError `json:"errors"`
|
||||
}
|
||||
type infoChange struct {
|
||||
Changed bool `json:"changed"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// BlueprintsChangesV0 is the response to /blueprints/changes/ request
|
||||
type BlueprintsChangesV0 struct {
|
||||
BlueprintsChanges []bpChange `json:"blueprints"`
|
||||
Errors []ResponseError `json:"errors"`
|
||||
Limit uint `json:"limit"`
|
||||
Offset uint `json:"offset"`
|
||||
}
|
||||
type bpChange struct {
|
||||
Changes []blueprint.Change `json:"changes"`
|
||||
Name string `json:"name"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// BlueprintsDepsolveV0 is the response to /blueprints/depsolve/ request
|
||||
type BlueprintsDepsolveV0 struct {
|
||||
Blueprints []depsolveEntry `json:"blueprints"`
|
||||
Errors []ResponseError `json:"errors"`
|
||||
}
|
||||
type depsolveEntry struct {
|
||||
Blueprint blueprint.Blueprint `json:"blueprint"`
|
||||
Dependencies []rpmmd.PackageSpec `json:"dependencies"`
|
||||
}
|
||||
|
||||
// BlueprintsFreezeV0 is the response to /blueprints/freeze/ request
|
||||
type BlueprintsFreezeV0 struct {
|
||||
Blueprints []blueprintFrozen `json:"blueprints"`
|
||||
Errors []ResponseError `json:"errors"`
|
||||
}
|
||||
type blueprintFrozen struct {
|
||||
Blueprint blueprint.Blueprint `json:"blueprint"`
|
||||
}
|
||||
|
|
@ -5,10 +5,12 @@ package client
|
|||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/weldr"
|
||||
)
|
||||
|
||||
// GetStatusV0 makes a GET request to /api/status and returns the v0 response as a StatusResponseV0
|
||||
func GetStatusV0(socket *http.Client) (reply StatusV0, resp *APIResponse, err error) {
|
||||
func GetStatusV0(socket *http.Client) (reply weldr.StatusV0, resp *APIResponse, err error) {
|
||||
body, resp, err := GetRaw(socket, "GET", "/api/status")
|
||||
if resp != nil || err != nil {
|
||||
return reply, resp, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue