Skip to content

Commit

Permalink
Merge pull request #1872 from justinsb/generate_apikeys
Browse files Browse the repository at this point in the history
Add APIKeysKey go types generated from proto
  • Loading branch information
google-oss-prow[bot] committed May 24, 2024
2 parents 4cfd5b6 + d0df79d commit 5ee1539
Show file tree
Hide file tree
Showing 19 changed files with 2,783 additions and 2,370 deletions.
179 changes: 179 additions & 0 deletions apis/apikeys/v1alpha1/apikey_generated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright 2024 Google LLC
//
// 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 (
"github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
)

// +kcc:proto=google.api.apikeys.v2.AndroidApplication
type AndroidApplication struct {
// The SHA1 fingerprint of the application. For example, both sha1 formats are
// acceptable : DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09 or
// DA39A3EE5E6B4B0D3255BFEF95601890AFD80709.
// Output format is the latter.
// +required
Sha1Fingerprint *string `json:"sha1Fingerprint,omitempty"`

// The package name of the application.
// +required
PackageName *string `json:"packageName,omitempty"`
}

// +kcc:proto=google.api.apikeys.v2.AndroidKeyRestrictions
type AndroidKeyRestrictions struct {
// A list of Android applications that are allowed to make API calls with this key.
// +required
AllowedApplications []AndroidApplication `json:"allowedApplications,omitempty"`
}

// +kcc:proto=google.api.apikeys.v2.ApiTarget
type ApiTarget struct {
// The service for this restriction. It should be the canonical
// service name, for example: `translate.googleapis.com`.
// You can use [`gcloud services list`](/sdk/gcloud/reference/services/list)
// to get a list of services that are enabled in the project.
// +required
Service *string `json:"service,omitempty"`

// Optional. List of one or more methods that can be called.
// If empty, all methods for the service are allowed. A wildcard
// (*) can be used as the last symbol.
// Valid examples:
// `google.cloud.translate.v2.TranslateService.GetSupportedLanguage`
// `TranslateText`
// `Get*`
// `translate.googleapis.com.Get*`
Methods []string `json:"methods,omitempty"`
}

// +kcc:proto=google.api.apikeys.v2.BrowserKeyRestrictions
type BrowserKeyRestrictions struct {
// A list of regular expressions for the referrer URLs that are allowed
// to make API calls with this key.
// +required
AllowedReferrers []string `json:"allowedReferrers,omitempty"`
}

// +kcc:proto=google.api.apikeys.v2.IosKeyRestrictions
type IosKeyRestrictions struct {
// A list of bundle IDs that are allowed when making API calls with this key.
// +required
AllowedBundleIds []string `json:"allowedBundleIds,omitempty"`
}

// +kcc:proto=google.api.apikeys.v2.Key
type APIKeySpec struct {
/* Immutable. The Project that this resource belongs to. */
ProjectRef v1beta1.ProjectRef `json:"projectRef"`

/* Immutable. Optional. The name of the resource. Used for creation and acquisition. When unset, the value of `metadata.name` is used as the default. */
// +optional
ResourceID *string `json:"resourceID,omitempty"`

// Human-readable display name of this key that you can modify.
// The maximum length is 63 characters.
DisplayName *string `json:"displayName,omitempty"`

/*NOTYET
// Annotations is an unstructured key-value map stored with a policy that
// may be set by external tools to store and retrieve arbitrary metadata.
// They are not queryable and should be preserved when modifying objects.
Annotations []Key_AnnotationsEntry `json:"annotations,omitempty"`
*/

// Key restrictions.
Restrictions *Restrictions `json:"restrictions,omitempty"`
}

// +kcc:proto=google.api.apikeys.v2.Key
type APIKeyObservedState struct {
/*NOTYET
// Output only. The resource name of the key.
// The `name` has the form:
// `projects/<PROJECT_NUMBER>/locations/global/keys/<KEY_ID>`.
// For example:
// `projects/123456867718/locations/global/keys/b7ff1f9f-8275-410a-94dd-3855ee9b5dd2`
//
// NOTE: Key is a global resource; hence the only supported value for
// location is `global`.
Name *string `json:"name,omitempty"`
*/

// Output only. Unique id in UUID4 format.
Uid *string `json:"uid,omitempty"`

/*NOTYET
// Output only. An encrypted and signed value held by this key.
// This field can be accessed only through the `GetKeyString` method.
KeyString *string `json:"keyString,omitempty"`
*/

/*NOTYET
// Output only. A timestamp identifying the time this key was originally
// created.
CreateTime *string `json:"createTime,omitempty"`
// Output only. A timestamp identifying the time this key was last
// updated.
UpdateTime *string `json:"updateTime,omitempty"`
// Output only. A timestamp when this key was deleted. If the resource is not
// deleted, this must be empty.
DeleteTime *string `json:"deleteTime,omitempty"`
// Output only. A checksum computed by the server based on the current value
// of the Key resource. This may be sent on update and delete requests to
// ensure the client has an up-to-date value before proceeding. See
// https://google.aip.dev/154.
Etag *string `json:"etag,omitempty"`
*/
}

// +kcc:proto=google.api.apikeys.v2.Key.AnnotationsEntry
type Key_AnnotationsEntry struct {
Key *string `json:"key,omitempty"`

Value *string `json:"value,omitempty"`
}

// +kcc:proto=google.api.apikeys.v2.Restrictions
type Restrictions struct {
// The HTTP referrers (websites) that are allowed to use the key.
BrowserKeyRestrictions *BrowserKeyRestrictions `json:"browserKeyRestrictions,omitempty"`

// The IP addresses of callers that are allowed to use the key.
ServerKeyRestrictions *ServerKeyRestrictions `json:"serverKeyRestrictions,omitempty"`

// The Android apps that are allowed to use the key.
AndroidKeyRestrictions *AndroidKeyRestrictions `json:"androidKeyRestrictions,omitempty"`

// The iOS apps that are allowed to use the key.
IosKeyRestrictions *IosKeyRestrictions `json:"iosKeyRestrictions,omitempty"`

// A restriction for a specific service and optionally one or
// more specific methods. Requests are allowed if they
// match any of these restrictions. If no restrictions are
// specified, all targets are allowed.
ApiTargets []ApiTarget `json:"apiTargets,omitempty"`
}

// +kcc:proto=google.api.apikeys.v2.ServerKeyRestrictions
type ServerKeyRestrictions struct {
// A list of the caller IP addresses that are allowed to make API calls
// with this key.
// +required
AllowedIps []string `json:"allowedIps,omitempty"`
}
87 changes: 87 additions & 0 deletions apis/apikeys/v1alpha1/apikey_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2024 Google LLC
//
// 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 (
"reflect"

"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/k8s/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}

// AddToScheme is a global function that registers this API group & version to a scheme
AddToScheme = SchemeBuilder.AddToScheme

APIKeysKeyGVK = schema.GroupVersionKind{
Group: SchemeGroupVersion.Group,
Version: SchemeGroupVersion.Version,
Kind: reflect.TypeOf(APIKeysKey{}).Name(),
}
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=gcp,shortName=gcpapikeyskey;gcpapikeyskeys
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="cnrm.cloud.google.com/tf2crd=true";"cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/stability-level=alpha";"cnrm.cloud.google.com/system=true"
// +kubebuilder:printcolumn:name="Age",JSONPath=".metadata.creationTimestamp",type="date"
// +kubebuilder:printcolumn:name="Ready",JSONPath=".status.conditions[?(@.type=='Ready')].status",type="string",description="When 'True', the most recent reconcile of the resource succeeded"
// +kubebuilder:printcolumn:name="Status",JSONPath=".status.conditions[?(@.type=='Ready')].reason",type="string",description="The reason for the value in 'Ready'"
// +kubebuilder:printcolumn:name="Status Age",JSONPath=".status.conditions[?(@.type=='Ready')].lastTransitionTime",type="date",description="The last transition time for the value in 'Status'"

// APIKeysKey is the Schema for the APIKeys Key resource.
// +k8s:openapi-gen=true
type APIKeysKey struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +required
Spec APIKeySpec `json:"spec,omitempty"`

Status APIKeyStatus `json:"status,omitempty"`
}

type APIKeyStatus struct {
/* Conditions represent the latest available observations of the
object's current state. */
Conditions []v1alpha1.Condition `json:"conditions,omitempty"`

/* ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource. */
// +optional
ObservedGeneration *int64 `json:"observedGeneration,omitempty"`

/* ObservedState is the state of the resource as most recently observed in GCP. */
// +optional
ObservedState *APIKeyObservedState `json:"observedState,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

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

func init() {
SchemeBuilder.Register(&APIKeysKey{}, &APIKeysKeyList{})
}
19 changes: 19 additions & 0 deletions apis/apikeys/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2024 Google LLC
//
// 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.

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +groupName=apikeys.cnrm.cloud.google.com

package v1alpha1
22 changes: 22 additions & 0 deletions apis/apikeys/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 Google LLC
//
// 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 "k8s.io/apimachinery/pkg/runtime/schema"

var (
// SchemeGroupVersion is the group version used to register these objects.
SchemeGroupVersion = schema.GroupVersion{Group: "apikeys.cnrm.cloud.google.com", Version: "v1alpha1"}
)

0 comments on commit 5ee1539

Please sign in to comment.