Giter Club home page Giter Club logo

insightcloudsec's Introduction

insightcloudsec

Note
I forked this repo from gstotts to merge his pending PRs.

Go Module for Interacting with InsightCloudSec API (formerly DivvyCloud)

Go CodeQL

General Usage

package main

import(
    "github.com/gstotts/insightcloudsec"
)

func main() {
    config := insightcloudsec.Config{
        BaseURL: "http://localhost:8001",
        ApiKey: "1232351351235ABSLAFL:JSDFA"
    }

    // Can also use environment variables above and pass nil
    ics := insightcloudsec.NewClient(config)
}

Examples

List Clouds
package main

import (
	"fmt"

	"github.com/gstotts/insightcloudsec"
)

func main() {
	// Get a client
	c, err := insightcloudsec.NewClient(nil)
	if err != nil {
		fmt.Println(err)
	}

	clouds, err := c.Clouds.List()
	if err != nil {
		fmt.Println(err)
	}
	for _, cloud := range clouds.Clouds {
		fmt.Println(cloud.Name)
	}
}
List Cloud Types
package main

import (
	"fmt"

	"github.com/gstotts/insightcloudsec"
)

func main() {
	// Get a client
	c, err := insightcloudsec.NewClient(nil)
	if err != nil {
		fmt.Println(err)
	}

	types, err := c.Clouds.ListTypes()
	if err != nil {
		fmt.Println(err)
	}
	for _, t := range types.CloudTypesList {
		fmt.Println(t.Name)
	}
}
List Cloud Regions
package main

import (
	"fmt"
	"os"

	"github.com/gstotts/insightcloudsec"
)

func main() {
	// Get a client
	c, err := insightcloudsec.NewClient(nil)
	if err != nil {
		fmt.Println(err)
	}

	clouds, err := c.Clouds.ListClouds()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	for _, cloud := range clouds.Clouds {
		fmt.Printf("Name: %s\n", cloud.Name)
		regions, _ := c.ListCloudRegions(cloud)
		fmt.Println("Regions:")
		for _, region := range regions.Regions {
			fmt.Printf("- %s\n", region.Name)
		}
	}
}
List Harvesting Strategies
package main

import (
	"fmt"
	"os"

	"github.com/gstotts/insightcloudsec"
)

func main() {
	// Get a client
	c, err := insightcloudsec.NewClient(nil)
	if err != nil {
		fmt.Println(err)
	}

	hs, err := c.Clouds.ListHarvestingStrategies()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	for _, s := range hs {
		fmt.Printf("Name: %s\n", s.Name)
	}
}
Create Insight
package main

import (
	"github.com/gstotts/insightcloudsec"
)

func main() {

	filter := insightcloudsec.InsightFilter{}
	filter.Name = "divvy.filter.cloud_trail_in_all_regions"
	insight := insightcloudsec.Insight{}
	insight.Name = "Test Divvy Insight"
	insight.Description = "Test Divvy Insight Description"
	insight.Severity = insightcloudsec.INSIGHT_SEVERITY_MINOR
	insight.Tags = nil
	insight.Badges = nil
	insight.BadgeFilterOperator = ""
	insight.ResourceTypes = []string{"divvyorganizationservice"}
	insight.Filters = []insightcloudsec.InsightFilter{filter}

	ics, _ := insightcloudsec.NewClient(nil)
	ics.Insights.Create(insight)

}
List Insights
package main

import (
	"fmt"
	"os"

	"github.com/gstotts/insightcloudsec"
)

func main() {
	// Get a client
	c, err := insightcloudsec.NewClient(nil)
	if err != nil {
		fmt.Println(err)
	}

	insights, err := c.Insights.List()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	for _, insight := range insights {
		fmt.Printf("       Name: %s\n", insight.Name)
		fmt.Printf("Description: %s\n\n", insight.Description)
	}
}
Add Azure Cloud
package main

import (
	"fmt"

	"github.com/gstotts/insightcloudsec"
)

func main() {
	ics, _ := insightcloudsec.NewClient(nil)

	azure_cloud := insightcloudsec.AzureCloudAccount{
		CreationParameters: insightcloudsec.CloudAccountParameters{
			CloudType:      insightcloudsec.AZURE_CLOUD_TYPE,
			AuthType:       insightcloudsec.STANDARD_AUTH,
			Name:           "Azure Test",
			ApiKeyOrCert:   "1111111111111111111111111111",
			TenantID:       "01234567-1234-1234-1234-012345678901",
			SubscriptionID: "01234567-1234-1234-1234-012345678901",
			AppID:          "01234567-1234-1234-1234-012345678901",
		},
	}
	account, err := ics.Clouds.AddAzureCloud(azure_cloud)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(account)
}
Create User
package main

import (
	"fmt"

	"github.com/gstotts/insightcloudsec"
)

func main() {
	ics, _ := insightcloudsec.NewClient(nil)
	details, err := ics.Users.Create(insightcloudsec.User{
		Name:        "Testy McTester",
		Username:    "tmctester",
		Email:       "[email protected]",
		Password:    "testpassword123",
		AccessLevel: "BASIC_USER",
	})

	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(details)
}

insightcloudsec's People

Contributors

gstotts avatar the1337beauty avatar

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.