aboutsummaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorJulien Dessaux2023-07-31 00:31:43 +0200
committerJulien Dessaux2023-07-31 00:31:43 +0200
commit6642a66a1df5db5f2f9780905e83ba2c412128f6 (patch)
tree35d04ade200db806152bc80cd6cf33ed6bf23052 /external
parentUpgrade notes (diff)
downloadterraform-provider-eventline-6642a66a1df5db5f2f9780905e83ba2c412128f6.tar.gz
terraform-provider-eventline-6642a66a1df5db5f2f9780905e83ba2c412128f6.tar.bz2
terraform-provider-eventline-6642a66a1df5db5f2f9780905e83ba2c412128f6.zip
Implemented identities datasourcev0.0.5
Diffstat (limited to 'external')
-rw-r--r--external/evcli/client.go28
-rw-r--r--external/evcli/identities.go73
2 files changed, 101 insertions, 0 deletions
diff --git a/external/evcli/client.go b/external/evcli/client.go
index b9d5032..ce3d4a0 100644
--- a/external/evcli/client.go
+++ b/external/evcli/client.go
@@ -181,6 +181,34 @@ func (c *Client) UpdateProject(project *eventline.Project) error {
return c.SendRequest("PUT", uri, project, nil)
}
+func (c *Client) FetchIdentities() (Identities, error) {
+ var identities Identities
+
+ cursor := eventline.Cursor{Size: 20}
+
+ for {
+ var page IdentityPage
+
+ uri := NewURL("identities")
+ uri.RawQuery = cursor.Query().Encode()
+
+ err := c.SendRequest("GET", uri, nil, &page)
+ if err != nil {
+ return nil, err
+ }
+
+ identities = append(identities, page.Elements...)
+
+ if page.Next == nil {
+ break
+ }
+
+ cursor = *page.Next
+ }
+
+ return identities, nil
+}
+
func (c *Client) ReplayEvent(id string) (*eventline.Event, error) {
var event eventline.Event
diff --git a/external/evcli/identities.go b/external/evcli/identities.go
new file mode 100644
index 0000000..f89ae1b
--- /dev/null
+++ b/external/evcli/identities.go
@@ -0,0 +1,73 @@
+package evcli
+
+import (
+ "encoding/json"
+ "fmt"
+ "time"
+
+ "github.com/exograd/eventline/pkg/eventline"
+ "github.com/exograd/eventline/pkg/utils"
+)
+
+type IdentityPage struct {
+ Elements Identities `json:"elements"`
+ Previous *eventline.Cursor `json:"previous,omitempty"`
+ Next *eventline.Cursor `json:"next,omitempty"`
+}
+
+type Identity struct {
+ Id eventline.Id `json:"id"`
+ ProjectId *eventline.Id `json:"project_id"`
+ Name string `json:"name"`
+ Status eventline.IdentityStatus `json:"status"`
+ ErrorMessage string `json:"error_message,omitempty"`
+ CreationTime time.Time `json:"creation_time"`
+ UpdateTime time.Time `json:"update_time"`
+ LastUseTime *time.Time `json:"last_use_time,omitempty"`
+ RefreshTime *time.Time `json:"refresh_time,omitempty"`
+ Connector string `json:"connector"`
+ Type string `json:"type"`
+ Data eventline.IdentityData `json:"-"`
+ RawData json.RawMessage `json:"data"`
+}
+
+type Identities []*Identity
+
+func (i *Identity) SortKey(sort string) (key string) {
+ switch sort {
+ case "id":
+ key = i.Id.String()
+ case "name":
+ key = i.Name
+ default:
+ utils.Panicf("unknown identity sort %q", sort)
+ }
+
+ return
+}
+
+func (pi *Identity) MarshalJSON() ([]byte, error) {
+ type Identity2 Identity
+
+ i := Identity2(*pi)
+ data, err := json.Marshal(i.Data)
+ if err != nil {
+ return nil, fmt.Errorf("cannot encode data: %w", err)
+ }
+
+ i.RawData = data
+
+ return json.Marshal(i)
+}
+
+func (pi *Identity) UnmarshalJSON(data []byte) error {
+ type Identity2 Identity
+
+ i := Identity2(*pi)
+ if err := json.Unmarshal(data, &i); err != nil {
+ return err
+ }
+
+ *pi = Identity(i)
+ return nil
+}