iCloud Go is a Go client library for using the CloudKit Web Services API. While the foundation of this package is powerfull enough to support the whole API, its main purpose is to provide enough features to create records in CloudKit. This serves my personal purpose of using this package for building various kinds of importers.
$ go get github.com/lukasmalkmus/icloud-go/icloud
$ git clone https://github.com/lukasmalkmus/icloud-go.git
$ cd icloud-go
$ make
This package only supports Server-to-Server authentication.
You can create a keypair using openssl
:
$ openssl ecparam -name prime256v1 -genkey -noout -out eckey.pem
To get the public key (to enter it on iCloud Dashboard):
$ openssl ec -in eckey.pem -pubout
To get the private key (used by the client to sign requests):
$ openssl ec -in eckey.pem
import "github.com/lukasmalkmus/icloud-go/icloud"
var (
keyID = os.Getenv("ICLOUD_KEY_ID")
container = os.Getenv("ICLOUD_CONTAINER")
rawPrivateKey = os.Getenv("ICLOUD_PRIVATE_KEY")
)
// 1. Parse the private key.
privateKey, err := x509.ParseECPrivateKey([]byte(rawPrivateKey))
if err != nil {
log.Fatal(err)
}
// 2. Create the iCloud client.
client, err := icloud.NewClient(container, keyID, privateKey, icloud.Development)
if err != nil {
log.Fatal(err)
}
// 3. Create a record.
if _, err = client.Records.Modify(context.Background(), icloud.Public, icloud.RecordsRequest{
Operations: []icloud.RecordOperation{
{
Type: icloud.Create,
Record: icloud.Record{
Type: "MyRecord",
Fields: icloud.Fields{
{
Name: "MyField",
Value: "Hello, World!",
},
{
Name: "MyOtherField",
Value: 1000,
},
},
},
},
},
}); err != nil {
log.Fatal(err)
}
Feel free to submit PRs or to fill issues. Every kind of help is appreciated.
Before committing, make
should run without any issues.
© Lukas Malkmus, 2021
Distributed under MIT License (The MIT License
).
See LICENSE for more information.