Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IP to public machine struct #16

Merged
merged 1 commit into from
May 28, 2024

Conversation

ezekg
Copy link
Member

@ezekg ezekg commented May 28, 2024

Supersedes #15. Adds the IP property to the public Machine struct, but does not implement functionality to set a machine's IP attribute during license.Activate(). This allows the IP property to be accessible via a machine file.

One possibility for setting the IP could be:

func (l *License) Activate(fingerprint string, components ...Component) (*Machine, error) {
	client := NewClient()
	hostname, _ := os.Hostname()
	conn, _ := net.Dial("udp", "keygen.sh:80") // this doesn't actually hit the network
	defer conn.Close()

	params := &Machine{
		Fingerprint: fingerprint,
		Hostname:    hostname,
		Platform:    runtime.GOOS + "/" + runtime.GOARCH,
		IP:          conn.LocalAddr().String(),
		Cores:       runtime.NumCPU(),
		LicenseID:   l.ID,
		components:  components,
	}

	machine := &Machine{}
	if _, err := client.Post("machines", params, machine); err != nil {
		return nil, err
	}

	return machine, nil
}

But that risks not using the right IP, so it may be best to leave this to the end user somehow.

@ezekg ezekg merged commit 288e4df into master May 28, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant