Git Product home page Git Product logo

go-ztcentral's Introduction

go-ztcentral

Golang client library for interacting with the ZeroTier Central Network Management Portal

NOTE: This does not work with self-hosted controllers.

Example:

package main

import (
	"context"
	"log"
	"os"

	ztcentral "github.com/zerotier/go-ztcentral"
)

func main() {
	c, err := ztcentral.NewClient(os.Getenv("ZEROTIER_CENTRAL_TOKEN"))
	if err != nil {
		panic(err)
	}

	ctx := context.Background()

	// get list of networks
	networks, err := c.GetNetworks(ctx)
	if err != nil {
		log.Println("error:", err.Error())
		os.Exit(1)
	}

	// print networks and members
	for _, n := range networks {
		log.Printf("%s\t%s", *n.Id, *n.Config.Name)
		members, err := c.GetMembers(ctx, *n.Id)
		if err != nil {
			log.Println("error:", err.Error())
			os.Exit(1)
		}

		for _, m := range members {
			log.Printf("\t%s\t %s", *m.Id, *m.Name)
		}
	}
}

Development

Some useful make tasks:

  • make reflex-lint and make reflex-test run the linters/testers with file watchers.
  • VERSION=x.y.z make release - make a release with version x.y.z. Edits files and pushes tags.

License

Copyright (c) 2021, ZeroTier, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

go-ztcentral's People

Contributors

erikh avatar glimberg avatar someara avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-ztcentral's Issues

Adding (Admin) Users via ZeroTier Central API (updateNetwork > permissions map)

I am using the ZeroTier Central API and I can change things like Network Name, Network Description, MTU etc, however I would like to add my colleagues to a network automatically.

I have found the [ZeroTier Central API | ZeroTier Documentation] for updateNetwork (ZeroTier Central API | ZeroTier Documentation 1) and this has a “permissions” property.

However ZT Central or the response does not reflect the changes I make.

Network 885033839019b072 To be updated via url https://api.zerotier.com/api/v1/network/885033839019b072
POST Body to be used

{
  description: 'Dummy Description2',
  config: { name: 'Dummy Name', private: false, mtu: null, tags: [ '' ] },
  permissions: {
    '0501dedc-20da-46e2-8b36-7a46ff75920c': { a: true, d: true, m: true, r: true },
    'eab7efa4-0523-4e38-8f76-f74fde2a5125': { a: true, d: true, m: true, r: true }
  }
}

Network 885033839019b072 updated. Response: 200/OK

{
  id: '885033839019b072',
  type: 'Network',
  clock: 1696332065430,
  config: {
    authTokens: null,
    creationTime: 1694418011397,
    capabilities: [],
    enableBroadcast: true,
    id: '885033839019b072',
    ipAssignmentPools: [ [Object] ],
    lastModified: 1696332065395,
    mtu: 2800,
    multicastLimit: 32,
    name: 'Dummy Name',
    private: false,
    remoteTraceLevel: 0,
    remoteTraceTarget: null,
    routes: [ [Object] ],
    rules: [ [Object] ],
    tags: [ '' ],
    v4AssignMode: { zt: true },
    v6AssignMode: { '6plane': false, rfc4193: false, zt: false },
    dns: { domain: '', servers: null },
    ssoConfig: { enabled: false, mode: '' }
  },
  description: 'Dummy Description2',
  rulesSource: 'accept;',
  permissions: {
    '38852822-5922-4709-8283-5f72f7c2d6d5': { a: true, d: true, m: true, r: true },
    '6ba92a3f-ed27-467a-bf69-52661e93473a': { a: true, d: true, m: true, r: true },
    'eab7efa4-0523-4e38-8f76-f74fde2a5125': { a: true, d: true, m: true, r: true }
  },
  ownerId: 'eab7efa4-0523-4e38-8f76-f74fde2a5125',
  onlineMemberCount: 0,
  authorizedMemberCount: 0,
  totalMemberCount: 0,
  capabilitiesByName: {},
  tagsByName: {},
  ui: {
    membersHelpCollapsed: true,
    rulesHelpCollapsed: true,
    settingsHelpCollapsed: true,
    v4EasyMode: false
  }
}

I would expect that the following user would be added, but it is not added.

'0501dedc-20da-46e2-8b36-7a46ff75920c'

I am able to update networks via the ZeroTier Central UI.

So I wonder - can anyone else make this work?

Br

Andreas

ps. I have also created a post on discuss.zerotier.com but it seemed to be the wrong place to put it?
https://discuss.zerotier.com/t/adding-admin-users-via-zerotier-central-api-updatenetwork-permissions-map/16104

Take API key from environment

ZEROTIER_CONTROLLER_TOKEN should be renamed to ZEROTIER_CENTRAL_TOKEN. See also for the URL variants that control the baseURL

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.