feat: v0 — glpi-go client, mglpi CLI, mglpi-mcp, fake-GLPI test suite [#767]
https://projects.knownelement.com/issues/767#note-4191
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package glpi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Profile is one GLPI profile of the logged-in user (GET /getMyProfiles,
|
||||
// GET /Profile/<id>). IsActive reflects the session's active profile.
|
||||
type Profile struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
// GetMyProfiles lists the profiles of the logged-in user. GLPI answers
|
||||
// with a bare JSON array (not a wrapped object).
|
||||
func (c *Client) GetMyProfiles(ctx context.Context) ([]Profile, error) {
|
||||
var profiles []Profile
|
||||
if err := c.call(ctx, http.MethodGet, "/getMyProfiles", nil, nil, &profiles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
// ChangeActiveProfile switches the session's active profile
|
||||
// (POST /changeActiveProfile with {"profiles_id":N}). Agent mode uses
|
||||
// this to move into the right role (e.g. 5 = Hotliner) after
|
||||
// InitSession; servers that gate operations per profile then accept the
|
||||
// calls that were previously rejected.
|
||||
func (c *Client) ChangeActiveProfile(ctx context.Context, profileID int) error {
|
||||
if profileID <= 0 {
|
||||
return fmt.Errorf("%w: profile id must be positive", ErrValidation)
|
||||
}
|
||||
payload := map[string]any{"profiles_id": profileID}
|
||||
// The endpoint answers `true` — nothing to parse.
|
||||
return c.call(ctx, http.MethodPost, "/changeActiveProfile", nil, payload, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user