Skip to content

Commit

Permalink
Add ApiKey CRD (#224)
Browse files Browse the repository at this point in the history
* bump coralogix-management-sdk

* Remove unnecessary client function input

* Add ApiKey CRD
  • Loading branch information
assafad1 authored Nov 27, 2024
1 parent cdbbdbf commit 48db34a
Show file tree
Hide file tree
Showing 33 changed files with 1,528 additions and 20 deletions.
12 changes: 12 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ resources:
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: coralogix.com
group: coralogix
kind: ApiKey
path: github.com/coralogix/coralogix-operator/api/coralogix/v1alpha1
version: v1alpha1
webhooks:
validation: true
webhookVersion: v1
version: "3"
108 changes: 108 additions & 0 deletions api/coralogix/v1alpha1/apikey_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright 2024 Coralogix Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

cxsdk "github.com/coralogix/coralogix-management-sdk/go"
)

// ApiKeySpec defines the desired state of ApiKey.
type ApiKeySpec struct {
//+kubebuilder:validation:MinLength=0
Name string `json:"name"`

// +optional
//+kubebuilder:default=true
Active bool `json:"active"`

Owner ApiKeyOwner `json:"owner"`

// +optional
Presets []string `json:"presets,omitempty"`

// +optional
Permissions []string `json:"permissions,omitempty"`
}

type ApiKeyOwner struct {
// +optional
UserId *string `json:"userId,omitempty"`

// +optional
TeamId *uint32 `json:"teamId,omitempty"`
}

// ApiKeyStatus defines the observed state of ApiKey.
type ApiKeyStatus struct {
Id *string `json:"id"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// ApiKey is the Schema for the apikeys API.
type ApiKey struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ApiKeySpec `json:"spec,omitempty"`
Status ApiKeyStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// ApiKeyList contains a list of ApiKey.
type ApiKeyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ApiKey `json:"items"`
}

func (s *ApiKeySpec) ExtractCreateApiKeyRequest() *cxsdk.CreateAPIKeyRequest {
owner := &cxsdk.Owner{}
if s.Owner.UserId != nil {
owner.Owner = &cxsdk.OwnerUserID{UserId: *s.Owner.UserId}
}
if s.Owner.TeamId != nil {
owner.Owner = &cxsdk.OwnerTeamID{TeamId: *s.Owner.TeamId}
}

return &cxsdk.CreateAPIKeyRequest{
Name: s.Name,
Owner: owner,
KeyPermissions: &cxsdk.APIKeyPermissions{
Presets: s.Presets,
Permissions: s.Permissions,
},
Hashed: false,
}
}

func (s *ApiKeySpec) ExtractUpdateApiKeyRequest(id string) *cxsdk.UpdateAPIKeyRequest {
return &cxsdk.UpdateAPIKeyRequest{
KeyId: id,
NewName: ptr.To(s.Name),
IsActive: ptr.To(s.Active),
Presets: ptr.To(cxsdk.APIKeyPresetsUpdate{Presets: s.Presets}),
Permissions: ptr.To(cxsdk.APIKeyPermissionsUpdate{Permissions: s.Permissions}),
}
}

func init() {
SchemeBuilder.Register(&ApiKey{}, &ApiKeyList{})
}
4 changes: 2 additions & 2 deletions api/coralogix/v1alpha1/rulegroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,8 @@ func expandSourceFiledAndParameters(rule Rule) (sourceField *wrapperspb.StringVa
parameters = &cxsdk.RuleParameters{
RuleParameters: &cxsdk.RuleParametersJSONExtractParameters{
JsonExtractParameters: &cxsdk.JSONExtractParameters{
DestinationField: destinationField,
Rule: jsonKey,
DestinationFieldType: destinationField,
Rule: jsonKey,
},
},
}
Expand Down
130 changes: 130 additions & 0 deletions api/coralogix/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions charts/coralogix-operator/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ rules:
- get
- patch
- update
- apiGroups:
- coralogix.com
resources:
- apikeys
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- coralogix.com
resources:
- apikeys/finalizers
verbs:
- update
- apiGroups:
- coralogix.com
resources:
- apikeys/status
verbs:
- get
- patch
- update
- apiGroups:
- coralogix.com
resources:
Expand Down Expand Up @@ -139,6 +165,10 @@ rules:
resources:
- secrets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
name: apikeys.coralogix.com
spec:
group: coralogix.com
names:
kind: ApiKey
listKind: ApiKeyList
plural: apikeys
singular: apikey
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: ApiKey is the Schema for the apikeys API.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: ApiKeySpec defines the desired state of ApiKey.
properties:
active:
default: true
type: boolean
name:
minLength: 0
type: string
owner:
properties:
teamId:
format: int32
type: integer
userId:
type: string
type: object
permissions:
items:
type: string
type: array
presets:
items:
type: string
type: array
required:
- name
- owner
type: object
status:
description: ApiKeyStatus defines the observed state of ApiKey.
properties:
id:
type: string
required:
- id
type: object
type: object
served: true
storage: true
subresources:
status: {}
Loading

0 comments on commit 48db34a

Please sign in to comment.