Giter VIP home page Giter VIP logo

nobl9-go's Introduction

N9

checks tests vulnerabilities

Nobl9 SDK for the Go programming language.

Checkout release notes for details on the latest bug fixes, updates, and features.

⚠️ Until v1.0.0 is released, we expect some minor breaking API changes to be introduced.


Legend:

  1. Installation
  2. Examples
  3. Repository structure
  4. Contributing

Installation

To add the latest version to your Go module run:

go get github.com/nobl9/nobl9-go

Examples

Basic usage

package main

import (
   "context"
   "encoding/json"
   "fmt"
   "log"

   "github.com/nobl9/nobl9-go/manifest"
   "github.com/nobl9/nobl9-go/manifest/v1alpha"
   "github.com/nobl9/nobl9-go/manifest/v1alpha/project"
   "github.com/nobl9/nobl9-go/manifest/v1alpha/service"
   "github.com/nobl9/nobl9-go/sdk"
   objectsV1 "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1"
)

func main() {
   ctx := context.Background()

   // Create client.
   client, err := sdk.DefaultClient()
   if err != nil {
      log.Fatalf("failed to create sdk client, err: %v", err)
   }

   // Read from file, url or glob pattern.
   objects, err := sdk.ReadObjects(ctx, "./project.yaml")
   if err != nil {
      log.Fatalf("failed to read project.yaml file, err: %v", err)
   }
   // Use manifest.FilterByKind to extract specific objects from the manifest.Object slice.
   myProject := manifest.FilterByKind[project.Project](objects)[0]
   // Define objects in code.
   myService := service.New(
      service.Metadata{
         Name:        "my-service",
         DisplayName: "My Service",
         Project:     myProject.GetName(),
         Labels: v1alpha.Labels{
            "team":   []string{"green", "orange"},
            "region": []string{"eu-central-1"},
         },
      },
      service.Spec{
         Description: "Example service",
      },
   )
   objects = append(objects, myService)

   // Verify the objects.
   if errs := manifest.Validate(objects); len(errs) > 0 {
      log.Fatalf("service validation failed, errors: %v", errs)
   }

   // Apply the objects.
   if err = client.Objects().V1().Apply(ctx, objects); err != nil {
      log.Fatalf("failed to apply objects, err: %v", err)
   }

   // Get the applied resources.
   services, err := client.Objects().V1().GetV1alphaServices(ctx, objectsV1.GetServicesRequest{
      Project: myProject.GetName(),
      Names:   []string{myService.GetName()},
   })
   if err != nil {
      log.Fatalf("failed to get services, err: %v", err)
   }
   projects, err := client.Objects().V1().GetV1alphaProjects(ctx, objectsV1.GetProjectsRequest{
      Names: []string{myProject.GetName()},
   })
   if err != nil {
      log.Fatalf("failed to get projects, err: %v", err)
   }

   // Aggregate objects back into manifest.Objects slice.
   appliedObjects := make([]manifest.Object, 0, len(services)+len(projects))
   for _, service := range services {
      appliedObjects = append(appliedObjects, service)
   }
   for _, project := range projects {
      appliedObjects = append(appliedObjects, project)
   }

   // Print JSON representation of these objects.
   data, err := json.MarshalIndent(appliedObjects, "", "  ")
   if err != nil {
      log.Fatalf("failed to marshal objects, err: %v", err)
   }
   fmt.Println(string(data))

   // Delete resources.
   if err = client.Objects().V1().Delete(ctx, objects); err != nil {
      log.Fatalf("failed to delete objects, err: %v", err)
   }
}

Repository structure

Public packages

  1. sdk defines:

    • Client which exposes methods for interacting with different Nobl9 web APIs.
    • Methods for reading and managing Nobl9 configuration (including the config.toml file) used by tools such as sloctl or the SDK itself.
    • Methods for fetching and parsing Nobl9 configuration objects.
  2. manifest holds definitions of all Nobl9 configuration objects, such as SLO or Project. It is divided into three package levels:

    └── manifest
        └── version (e.g. v1alpha)
            └── object (e.g. slo)
    
    • manifest defines general contracts and generic methods for all objects.
    • Version-specific packages, such as v1alpha, define version-specific APIs, functions and structures shared by multiple objects.
    • Object-specific packages, like slo, provide object definition for specific object versions.

Contributing

TBA

nobl9-go's People

Contributors

alt-6 avatar bdw-nobl9 avatar bsski avatar bsski-nobl9 avatar daniel-zelazny avatar danstan9 avatar davex98 avatar dawidwisn avatar dependabot[bot] avatar ditrytus avatar jakubpieta avatar kskitek avatar kubaceg avatar kuklyy avatar lukasz-dobek avatar marcinlawnik avatar mkaras-nobl9 avatar natalialanga avatar nieomylnieja avatar nikodemrafalski avatar nobl9-adam-szymanski avatar nuusk avatar piotrkwarcinski avatar remilis avatar renovate[bot] avatar shubhindia avatar skrolikiewicz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

shubhindia

nobl9-go's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/checks.yml
  • actions/checkout v4
  • actions/setup-go v5
  • actions/setup-node v4
  • actions/cache v4
.github/workflows/e2e-tests.yml
  • actions/checkout v4
  • actions/setup-go v5
.github/workflows/pr-title.yml
  • Slashgear/action-check-pr-title v4.3.0
.github/workflows/release-drafter.yml
  • actions/checkout v4
  • release-drafter/release-drafter v6
.github/workflows/tests.yml
  • actions/checkout v4
  • actions/setup-go v5
.github/workflows/vulns.yml
  • actions/checkout v4
  • actions/setup-go v5
gomod
docs/mock_example/go.mod
  • go 1.22
  • github.com/nobl9/nobl9-go v0.84.0
  • github.com/stretchr/testify v1.9.0
  • go.uber.org/mock v0.4.0
go.mod
  • go 1.22
  • github.com/BurntSushi/toml v1.4.0
  • github.com/MicahParks/jwkset v0.5.18
  • github.com/MicahParks/keyfunc/v3 v3.3.3
  • github.com/aws/aws-sdk-go v1.55.5
  • github.com/bmatcuk/doublestar/v4 v4.6.1
  • github.com/goccy/go-yaml v1.12.0
  • github.com/golang-jwt/jwt/v5 v5.2.1
  • github.com/hashicorp/go-retryablehttp v0.7.7
  • github.com/nobl9/go-yaml v1.0.1
  • github.com/pkg/errors v0.9.1
  • github.com/stretchr/testify v1.9.0
  • github.com/teambition/rrule-go v1.8.2
  • golang.org/x/sync v0.8.0
  • golang.org/x/text v0.17.0
  • golang.org/x/time v0.6.0
npm
package.json
  • cspell 8.14.2
  • markdownlint-cli 0.41.0
  • yaml 2.5.0
  • yarn 1.22.22
regex
Makefile
  • abice/go-enum v0.6.0
  • securego/gosec v2.20.0
  • golangci/golangci-lint v1.60.1
  • golang.org/x/vuln/cmd/govulncheck v1.1.3
  • golang.org/x/tools/cmd/goimports v0.24.0
  • github.com/vburenin/ifacemaker v1.2.1

  • Check this box to trigger a request for Renovate to run again on this repository

[BUG] Multiline, quoted strings are not handled correctly by sdk.ReadObjects

Describe the bug
Double quoted, multiline strings result in an error and are not handled properly by sdk.ReadObjects function.

To Reproduce

Minimal main.go:

package main

import (
	"context"
	"fmt"

	"github.com/nobl9/nobl9-go/manifest"
	"github.com/nobl9/nobl9-go/manifest/v1alpha/project"
	"github.com/nobl9/nobl9-go/sdk"
)

func main() {
	objects, err := sdk.ReadObjects(context.Background(), "./project.yaml")
	if err != nil {
    panic(err)
	}
	fmt.Println(manifest.FilterByKind[project.Project](objects)[0].Spec.Description)
}

project.yaml:

apiVersion: n9/v1alpha
kind: Project
metadata:
    name: test
spec:
  description: "This operation includes the following processes: <br>
- Get all orders in a particular timeframe
"

Expected behavior

The object should be parsed just fine, the YAML library parses the file just fine on its own, which might hint at quoting handling issues on our side.
Here's a minimal working exmaple:

package main

import (
	"fmt"
	"os"

	"github.com/nobl9/nobl9-go/manifest/v1alpha/project"
  "github.com/goccy/go-yaml"
)

func main() {
	data, err := os.ReadFile("./project.yaml")
	if err != nil {
		panic(err)
	}
	var project project.Project
	if err = yaml.Unmarshal(data, &project); err != nil {
		panic(err)
	}
	fmt.Println(project.Spec.Description)
}

System details (please complete the following information):

  • Fedora 37
  • 0.77.1

[FEAT] Allow using user email for role binding

We are building an internal driver which will allow teams to onboard themselves onto nobl9. Now, as a part of this driver, we need to create some RBAC as well, since each team will have its own project and they'll get access to that particular project only. Same goes for an individual user as well. Now, in case of groups, in our case they will be synced from an enterprise-application in Azure. But for users, all we can do is add that individual user to the enterprise-application. According to the RoleBinding document here the userID needs to be passed.
Now, the issue with this is :

  1. I could not find any API to get this ID programatically
  2. If the user doesn't already exist, this ID won't be there but we would like to do the roleBinding any ways.
    The workflow is
    Create Project -> Create an appRoleAssignment (which assigns that user/group to enterprise app) -> Create a roleBinding so that the user/group gets access to the nobl9 project.

Describe the solution you'd like
In case of both user and group roleBinding, the input looks like an ID and not the actual username/email or group name. Since, we want to pre-provision the project with all the necessary access already in place, is it possible to create this roleBinding using email or group name (irrespective of if the user already exists or not).

Additional context
For e.g. We have a project called sloctl-projcet and [email protected] needs access to it. Now, to grant access, that user should already exist in app.nobl9.com and then we either give access to that user from UI or use a roleBinding. Now, to use roleBinding, we need the userID, which I couldn't find a way to fetch programatically.
Current Implementation:

apiVersion: n9/v1alpha
kind: RoleBinding
metadata:
  name: 7b565df6-8dd8-4c00-a318-70d82e5043d1
spec:
  projectRef: sloctl-project
  roleRef: project-viewer
  user: 00ucfmbtcr8X9mIcj417

Expected Implementation:

apiVersion: n9/v1alpha
kind: RoleBinding
metadata:
  name: 7b565df6-8dd8-4c00-a318-70d82e5043d1
spec:
  projectRef: sloctl-project
  roleRef: project-viewer
  user: [email protected]

Same goes for groups as well, that way we don't have to wait for users to login and then give them access.

Mocking the noble9 sdk

We are writing some internal APIs to manage nobl9 objects. Any suggestions on how I should mock the client for unit testing?
Currently mocking the methods which we are actually using.
e.g.

type N9Client interface {
	GetUser(ctx context.Context) (string, error)
	GetProjects(ctx context.Context, projectName string) ([]project.Project, error)
	CreateProject(ctx context.Context, projectName string) error
	DeleteProject(ctx context.Context, projectName string) error
}

Was wondering if we could pass the mockedClient to actual SDK and then SDK holds these mocked methods.

[BUG] Validation package does not handle empty map keys

Describe the bug
Property errors for map keys validation do not handle empty strings. Instead of a path like metadata.labels."" we get metadata.labels.

To Reproduce
Set map key to an empty string, run validation. The result is a property path without the empty string key element.

Expected behavior
The result should be a valid YAMLPath pointing at the empty key.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.