Skip to content

Commit 3ffab77

Browse files
committed
xclient: added method to annotate signals from admin namespace
1 parent 8eaf89c commit 3ffab77

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

examples/signals_annotate/main.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"os"
7+
8+
clarify "github.com/clarify/clarify-go"
9+
"github.com/clarify/clarify-go/views"
10+
clarifyx "github.com/clarify/clarify-go/x"
11+
)
12+
13+
func main() {
14+
// To select or publish signals, you must grant the integration access to
15+
// the "admin" namespace in the Clarify admin panel.
16+
creds, err := clarify.CredentialsFromFile("clarify-credentials.json")
17+
if err != nil {
18+
panic(err)
19+
}
20+
21+
ctx := context.Background()
22+
client := creds.Client(ctx)
23+
xclient := clarifyx.Upgrade(client)
24+
25+
// For this example, the signals we want to select are created by the same
26+
// integration that we are using to select them. Note that this isn't a
27+
// requirement; for production cases, you may want this integration ID to be
28+
// configured to be something else.
29+
integrationID := creds.Integration
30+
signalID := "cl1d4kobi2aq0ttkc4b0"
31+
32+
data := []views.SignalAnnotate{{
33+
ID: signalID,
34+
Annotations: map[string]string{
35+
"my-new-annotation": "with-new-value",
36+
"annotations-to-delete-has-empty-values": "",
37+
},
38+
}}
39+
40+
result, err := xclient.Admin().Signals().Annotate(integrationID, data).Do(ctx)
41+
if err != nil {
42+
panic(err)
43+
}
44+
enc := json.NewEncoder(os.Stdout)
45+
enc.SetIndent("", " ")
46+
enc.Encode(result)
47+
}

views/signal_annotate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2022-2025 Searis AS
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package views
16+
17+
type SignalAnnotate struct {
18+
ID string `json:"id"`
19+
Annotations map[string]string `json:"annotations"`
20+
}

x/admin.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2022-2025 Searis AS
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package clarifyx
16+
17+
import (
18+
"github.com/clarify/clarify-go/internal/request"
19+
"github.com/clarify/clarify-go/views"
20+
)
21+
22+
type SignalAdminGroup struct {
23+
AdminNamespace
24+
}
25+
26+
func (ns AdminNamespace) Signals() SignalAdminGroup {
27+
return SignalAdminGroup{AdminNamespace: ns}
28+
}
29+
30+
// Annotate returns a new request for publishing signals as items.
31+
func (s SignalAdminGroup) Annotate(integration string, data []views.SignalAnnotate) SignalsAnnotateRequest {
32+
return methodSignalsAnnotate.NewRequest(s.Handler(),
33+
paramIntegration.Value(integration),
34+
paramData.Value(data),
35+
paramFormat.Value(views.SelectionFormat{
36+
DataAsArray: true,
37+
GroupIncludedByType: true,
38+
}),
39+
)
40+
}
41+
42+
type (
43+
// SignalsAnnotateRequest describe an initialized admin.signals.annotate RPC
44+
// request with access to a request handler.
45+
SignalsAnnotateRequest = request.Request[SignalsAnnotateResult]
46+
47+
// SignalsAnnotateResult describe the result format for a SignalsAnnotateRequest.
48+
SignalsAnnotateResult = views.Selection[[]views.Signal, views.SignalInclude]
49+
)
50+
51+
var methodSignalsAnnotate = request.Method[SignalsAnnotateResult]{
52+
APIVersion: apiVersionExperimental,
53+
Method: "admin.signals.annotate",
54+
}

x/clarifyx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828

2929
paramFormat jsonrpc.ParamName = "format"
3030
paramIntegration jsonrpc.ParamName = "integration"
31+
paramData jsonrpc.ParamName = "data"
3132
paramItem jsonrpc.ParamName = "item"
3233
paramQuery jsonrpc.ParamName = "query"
3334
)

0 commit comments

Comments
 (0)