Skip to content

Commit

Permalink
Set content type header for license client (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>

Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Nov 13, 2022
1 parent d371021 commit 69a84f7
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 24 deletions.
7 changes: 7 additions & 0 deletions Development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Develop `license-proxyserver`

## Deploy to KIND

```
make deploy-to-kind PLATFORM_BASEURL=https://appscode.ninja PLATFORM_TOKEN=$APPSCODE_NINJA_TOKEN OS=linux
```
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
go.bytebuilders.dev/license-verifier v0.12.0
go.bytebuilders.dev/license-verifier v0.12.1-0.20221113063237-6eb88040dd50
gomodules.xyz/logs v0.0.6
gomodules.xyz/x v0.0.14
k8s.io/api v0.25.1
Expand All @@ -16,8 +16,8 @@ require (
k8s.io/client-go v0.25.1
k8s.io/klog/v2 v2.80.1
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1
kmodules.xyz/client-go v0.25.0
sigs.k8s.io/controller-runtime v0.13.0
kmodules.xyz/client-go v0.25.10
sigs.k8s.io/controller-runtime v0.13.1
)

require (
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.bytebuilders.dev/license-verifier v0.12.0 h1:HdgYKDe+lzjvTkkhlhrBtm5ORUXIKg8obst107OYVd4=
go.bytebuilders.dev/license-verifier v0.12.0/go.mod h1:47HPt3RVp9gsujYpOeXi28IsTV5lilZ+EOpuhz/DIJM=
go.bytebuilders.dev/license-verifier v0.12.1-0.20221113063237-6eb88040dd50 h1:RaKwNQ6dvJMLVUT5/EZ+WBZQxwloskamgDgiMwMJwEQ=
go.bytebuilders.dev/license-verifier v0.12.1-0.20221113063237-6eb88040dd50/go.mod h1:47HPt3RVp9gsujYpOeXi28IsTV5lilZ+EOpuhz/DIJM=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
go.etcd.io/etcd/api/v3 v3.5.4 h1:OHVyt3TopwtUQ2GKdd5wu3PmmipR4FTwCqoEjSyRdIc=
Expand Down Expand Up @@ -1017,15 +1017,15 @@ k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 h1:MQ8BAZPZlWk3S9K4a9NCkI
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1/go.mod h1:C/N6wCaBHeBHkHUesQOQy2/MZqGgMAFPqGsGQLdbZBU=
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed h1:jAne/RjBTyawwAy0utX5eqigAwz/lQhTmy+Hr/Cpue4=
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
kmodules.xyz/client-go v0.25.0 h1:ItlaPAwQEzmle33ieIvT+zSIlZ0sZpwxgtCBD8OJnuE=
kmodules.xyz/client-go v0.25.0/go.mod h1:PQAVWlXoHmk/OXqIuUz3xEW5H04uidiLwVyGX0yYnBQ=
kmodules.xyz/client-go v0.25.10 h1:jp94jSBI43C91Uy6gJx3qatzpm0GuaDdOLconw2IiCo=
kmodules.xyz/client-go v0.25.10/go.mod h1:6VSRxDP2UqoWUcF0aSpWu3m/56bEUzuuvZUrAxSFBr8=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.32 h1:2WjukG7txtEsbXsSKWtTibCdsyYAhcu6KFnttyDdZOQ=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.32/go.mod h1:fEO7lRTdivWO2qYVCVG7dEADOMo/MLDCVr8So2g88Uw=
sigs.k8s.io/controller-runtime v0.13.0 h1:iqa5RNciy7ADWnIc8QxCbOX5FEKVR3uxVxKHRMc2WIQ=
sigs.k8s.io/controller-runtime v0.13.0/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI=
sigs.k8s.io/controller-runtime v0.13.1 h1:tUsRCSJVM1QQOOeViGeX3GMT3dQF1eePPw6sEE3xSlg=
sigs.k8s.io/controller-runtime v0.13.1/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kustomize/api v0.12.1 h1:7YM7gW3kYBwtKvoY216ZzY+8hM+lV53LUayghNRJ0vM=
Expand Down
28 changes: 28 additions & 0 deletions hack/examples/issue_license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Copyright AppsCode Inc. and Contributors.
#
# 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.

set -x

TOKEN=${APPSCODE_NINJA_TOKEN}
CLUSTER_ID=$(kubectl get ns kube-system -o=jsonpath='{.metadata.uid}')

curl --location --request POST 'https://appscode.ninja/api/v1/license/issue' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKEN" \
--data-raw "{
\"cluster\": \"${CLUSTER_ID}\",
\"features\": [\"kubedb-enterprise\"]
}"
5 changes: 5 additions & 0 deletions hack/examples/request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: proxyserver.licenses.appscode.com/v1alpha1
kind: LicenseRequest
request:
features:
- kubedb-enterprise
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (c *Client) AcquireLicense(features []string) ([]byte, *v1alpha1.Contract,
if err != nil {
return nil, nil, err
}
req.Header.Set("Content-Type", "application/json")
// add authorization header to the req
if c.token != "" {
req.Header.Add("Authorization", "Bearer "+c.token)
Expand Down
2 changes: 1 addition & 1 deletion vendor/kmodules.xyz/client-go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
BASEIMAGE_PROD ?= gcr.io/distroless/static-debian11
BASEIMAGE_DBG ?= debian:bullseye

GO_VERSION ?= 1.18
GO_VERSION ?= 1.19
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)

OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
Expand Down
13 changes: 7 additions & 6 deletions vendor/kmodules.xyz/client-go/meta/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ package meta
import (
"crypto/x509"
"errors"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
"time"

Expand All @@ -30,7 +31,7 @@ import (
// ref: https://cloud.google.com/compute/docs/storing-retrieving-metadata
func TestGKE() (string, error) {
// ref: https://github.com/kubernetes/kubernetes/blob/a0f94123616c275f94e7a5b680d60d6f34e92f37/pkg/credentialprovider/gcp/metadata.go#L115
data, err := ioutil.ReadFile("/sys/class/dmi/id/product_name")
data, err := os.ReadFile("/sys/class/dmi/id/product_name")
if err != nil {
return "", err
}
Expand All @@ -50,7 +51,7 @@ func TestGKE() (string, error) {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -79,13 +80,13 @@ func TestAKS(cert *x509.Certificate) (string, error) {

// ref: https://cloud.google.com/compute/docs/storing-retrieving-metadata
func isAKS() error {
data, err := ioutil.ReadFile("/sys/class/dmi/id/sys_vendor")
data, err := os.ReadFile("/sys/class/dmi/id/sys_vendor")
if err != nil {
return err
}
sysVendor := strings.TrimSpace(string(data))

data, err = ioutil.ReadFile("/sys/class/dmi/id/product_name")
data, err = os.ReadFile("/sys/class/dmi/id/product_name")
if err != nil {
return err
}
Expand All @@ -110,7 +111,7 @@ func TestEKS(cert *x509.Certificate) (string, error) {

// ref: https://cloud.google.com/compute/docs/storing-retrieving-metadata
func isEKS() error {
data, err := ioutil.ReadFile("/sys/class/dmi/id/sys_vendor")
data, err := os.ReadFile("/sys/class/dmi/id/sys_vendor")
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion vendor/kmodules.xyz/client-go/meta/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ func UnmarshalFromJSON(data []byte, gv schema.GroupVersion) (runtime.Object, err
//
// WARNING: `json` tags are not respected when struct converted to map[string]interface{}
// WARNING: Embedded structs are not decoded properly: https://github.com/mitchellh/mapstructure/pull/80
//
func Decode(input interface{}, output interface{}) error {
config := &mapstructure.DecoderConfig{
DecodeHook: StringToQuantityHookFunc(),
Expand Down
3 changes: 1 addition & 2 deletions vendor/kmodules.xyz/client-go/meta/incluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
Expand All @@ -44,7 +43,7 @@ func PodNamespace() string {
return ns
}

if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
if data, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
return ns
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/kmodules.xyz/client-go/meta/ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package meta

import (
"context"
"io/ioutil"
"os"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -43,7 +43,7 @@ func IPv6EnabledInCluster(kc kubernetes.Interface) (bool, error) {
}

func IPv6EnabledInKernel() (bool, error) {
content, err := ioutil.ReadFile("/sys/module/ipv6/parameters/disable")
content, err := os.ReadFile("/sys/module/ipv6/parameters/disable")
if err != nil {
return false, err
}
Expand Down
6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ github.com/yudai/gojsondiff/formatter
# github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82
## explicit
github.com/yudai/golcs
# go.bytebuilders.dev/license-verifier v0.12.0
# go.bytebuilders.dev/license-verifier v0.12.1-0.20221113063237-6eb88040dd50
## explicit; go 1.18
go.bytebuilders.dev/license-verifier
go.bytebuilders.dev/license-verifier/apis/licenses
Expand Down Expand Up @@ -1141,7 +1141,7 @@ k8s.io/utils/path
k8s.io/utils/pointer
k8s.io/utils/strings/slices
k8s.io/utils/trace
# kmodules.xyz/client-go v0.25.0
# kmodules.xyz/client-go v0.25.10
## explicit; go 1.18
kmodules.xyz/client-go
kmodules.xyz/client-go/api/v1
Expand All @@ -1155,7 +1155,7 @@ kmodules.xyz/client-go/tools/clusterid
## explicit; go 1.17
sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/client
sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client
# sigs.k8s.io/controller-runtime v0.13.0
# sigs.k8s.io/controller-runtime v0.13.1
## explicit; go 1.17
sigs.k8s.io/controller-runtime/pkg/cache
sigs.k8s.io/controller-runtime/pkg/cache/internal
Expand Down
4 changes: 4 additions & 0 deletions vendor/sigs.k8s.io/controller-runtime/pkg/manager/internal.go

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

5 changes: 5 additions & 0 deletions vendor/sigs.k8s.io/controller-runtime/pkg/manager/manager.go

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

0 comments on commit 69a84f7

Please sign in to comment.