File: resources.go

package info (click to toggle)
golang-github-akamai-akamaiopen-edgegrid-golang 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,408 kB
  • sloc: sh: 532; makefile: 3
file content (76 lines) | stat: -rw-r--r-- 2,275 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package apiendpoints

import (
	"fmt"

	"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
)

type Resources []Resource

type Resource struct {
	APIResourceID           int     `json:"apiResourceId"`
	APIResourceName         string  `json:"apiResourceName"`
	ResourcePath            string  `json:"resourcePath"`
	Description             string  `json:"description"`
	LockVersion             int     `json:"lockVersion"`
	APIResourceClonedFromID *int    `json:"apiResourceClonedFromId"`
	APIResourceLogicID      int     `json:"apiResourceLogicId"`
	CreatedBy               string  `json:"createdBy"`
	CreateDate              string  `json:"createDate"`
	UpdatedBy               string  `json:"updatedBy"`
	UpdateDate              string  `json:"updateDate"`
	APIResourceMethods      Methods `json:"apiResourceMethods"`
}

type ResourceBaseInfo struct {
	APIResourceClonedFromID *int    `json:"apiResourceClonedFromId"`
	APIResourceID           int     `json:"apiResourceId"`
	APIResourceLogicID      int     `json:"apiResourceLogicId"`
	APIResourceName         string  `json:"apiResourceName"`
	CreateDate              string  `json:"createDate"`
	CreatedBy               string  `json:"createdBy"`
	Description             *string `json:"description"`
	Link                    *string `json:"link"`
	LockVersion             int     `json:"lockVersion"`
	Private                 bool    `json:"private"`
	ResourcePath            string  `json:"resourcePath"`
	UpdateDate              string  `json:"updateDate"`
	UpdatedBy               string  `json:"updatedBy"`
}

type ResourceSettings struct {
	Path                 string        `json:"path"`
	Methods              []MethodValue `json:"methods"`
	InheritsFromEndpoint bool          `json:"inheritsFromEndpoint"`
}

func GetResources(endpointId int, version int) (*Resources, error) {
	req, err := client.NewJSONRequest(
		Config,
		"GET",
		fmt.Sprintf(
			"/api-definitions/v2/endpoints/%d/versions/%d/resources",
			endpointId,
			version,
		),
		nil,
	)

	if err != nil {
		return nil, err
	}

	res, err := client.Do(Config, req)

	if client.IsError(res) {
		return nil, client.NewAPIError(res)
	}

	rep := &Resources{}
	if err = client.BodyJSON(res, rep); err != nil {
		return nil, err
	}

	return rep, nil
}