<commit_before>// Copyright 2017-present <NAME>. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package main

import (
	"os"

	"github.com/dihedron/go-log"
	"github.com/dihedron/go-openstack/openstack"
)

// https://developer.openstack.org/sdks/python/openstacksdk/users/profile.html#openstack.profile.Profile
func main() {

	log.SetLevel(log.DBG)
	log.SetStream(os.Stdout, true)
	log.SetTimeFormat("15:04:05.000")

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                             LOGIN                                 |")
	log.Debugf("+-------------------------------------------------------------------+")

	endpoint := os.Getenv("OS_AUTH_URL")
	if endpoint == "" {
		if len(os.Args) >= 2 {
			endpoint = os.Args[1]
		} else {
			endpoint = "http://192.168.56.101/identity/" // my shiny devstack :-)
		}
	}

	opts1 := &openstack.LoginOptions{
		UserName:       openstack.String("admin"),
		UserDomainName: openstack.String("Default"),
		UserPassword:   openstack.String("password"),
		//UnscopedLogin:  openstack.Bool(true),
		//ScopeProjectName: openstack.String("admin"),
		ScopeProjectName: openstack.String("demo"),
		ScopeDomainName:  openstack.String("Default"),
	}

	client := openstack.NewDefaultClient(endpoint)
	//client.LoadProfileFrom("./my-profile.json")
	client.Connect(opts1)
	defer client.Close()

	os.Exit(0)

	//time.Sleep(10 * time.Second)

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                         CREATE TOKEN                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	opts2 := &openstack.CreateTokenOptions{
		NoCatalog:        openstack.Bool(true),
		Authenticated:    true,
		ScopeProjectName: openstack.String("admin"),
		ScopeDomainName:  openstack.String("Default"),
		UserName:         openstack.String("admin"),
		UserDomainName:   openstack.String("Default"),
		UserPassword:     openstack.String("password"),
	}

	token, result, err := client.IdentityV3().CreateToken(opts2)
	log.Debugf("token is %q\n", *token.Value)
	log.Debugf("token is\n%s\n", log.ToJSON(token))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                          READ TOKEN                               |")
	log.Debugf("+-------------------------------------------------------------------+")

	opts3 := &openstack.ReadTokenOptions{
		AllowExpired: openstack.Bool(true),
		NoCatalog:    openstack.Bool(false),
		SubjectToken: *token.Value,
	}
	token, result, err = client.IdentityV3().ReadToken(opts3)
	log.Debugf("token is %q\n", *token.Value)
	log.Debugf("token is\n%s\n", log.ToJSON(token))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                          CHECK TOKEN                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	opts4 := &openstack.CheckTokenOptions{
		AllowExpired: openstack.Bool(true),
		SubjectToken: *token.Value,
	}
	ok, result, err := client.IdentityV3().CheckToken(opts4)
	log.Debugf("token valid: %t\n", ok)
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                          GET CATALOG                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	catalog, result, err := client.IdentityV3().ReadCatalog()
	log.Debugf("catalog is:\n%s\n", log.ToJSON(catalog))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                         GET PROJECTS                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	projects, result, err := client.IdentityV3().ReadProjects()
	log.Debugf("projects are:\n%s\n", log.ToJSON(projects))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                          GET DOMAINS                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	domains, result, err := client.IdentityV3().ReadDomains()
	log.Debugf("domains are:\n%s\n", log.ToJSON(domains))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	//time.Sleep(10 * time.Second)

	// log.Debugf("+-------------------------------------------------------------------+")
	// log.Debugf("|                          GET SYSTEMS                              |")
	// log.Debugf("+-------------------------------------------------------------------+")

	// systems, result, err := client.IdentityV3().ReadSystems()
	// log.Debugf("systems are:\n%s\n", log.ToJSON(systems))
	// log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	// if err != nil {
	// 	log.Debugf("call resulted in %v\n", err)
	// }

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                        APP CREDENTIALS                            |")
	log.Debugf("+-------------------------------------------------------------------+")

	// opts5 := &openstack.CreateTokenOptions{
	// 	NoCatalog:        false,
	// 	Authenticated:    true,
	// 	ScopeProjectName: openstack.String("admin"),
	// 	ScopeDomainName:  openstack.String("Default"),
	// 	UserName:         openstack.String("admin"),<commit_msg>Amend previous commit: Read on collection renamed "ListXXX"<commit_after>// Copyright 2017-present <NAME>. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package main

import (
	"os"

	"github.com/dihedron/go-log"
	"github.com/dihedron/go-openstack/openstack"
)

// https://developer.openstack.org/sdks/python/openstacksdk/users/profile.html#openstack.profile.Profile
func main() {

	log.SetLevel(log.DBG)
	log.SetStream(os.Stdout, true)
	log.SetTimeFormat("15:04:05.000")

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                             LOGIN                                 |")
	log.Debugf("+-------------------------------------------------------------------+")

	endpoint := os.Getenv("OS_AUTH_URL")
	if endpoint == "" {
		if len(os.Args) >= 2 {
			endpoint = os.Args[1]
		} else {
			endpoint = "http://192.168.56.101/identity/" // my shiny devstack :-)
		}
	}

	opts1 := &openstack.LoginOptions{
		UserName:       openstack.String("admin"),
		UserDomainName: openstack.String("Default"),
		UserPassword:   openstack.String("password"),
		//UnscopedLogin:  openstack.Bool(true),
		//ScopeProjectName: openstack.String("admin"),
		ScopeProjectName: openstack.String("demo"),
		ScopeDomainName:  openstack.String("Default"),
	}

	client := openstack.NewDefaultClient(endpoint)
	//client.LoadProfileFrom("./my-profile.json")
	client.Connect(opts1)
	defer client.Close()

	os.Exit(0)

	//time.Sleep(10 * time.Second)

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                         CREATE TOKEN                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	opts2 := &openstack.CreateTokenOptions{
		NoCatalog:        openstack.Bool(true),
		Authenticated:    true,
		ScopeProjectName: openstack.String("admin"),
		ScopeDomainName:  openstack.String("Default"),
		UserName:         openstack.String("admin"),
		UserDomainName:   openstack.String("Default"),
		UserPassword:     openstack.String("password"),
	}

	token, result, err := client.IdentityV3().CreateToken(opts2)
	log.Debugf("token is %q\n", *token.Value)
	log.Debugf("token is\n%s\n", log.ToJSON(token))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                          READ TOKEN                               |")
	log.Debugf("+-------------------------------------------------------------------+")

	opts3 := &openstack.ReadTokenOptions{
		AllowExpired: openstack.Bool(true),
		NoCatalog:    openstack.Bool(false),
		SubjectToken: *token.Value,
	}
	token, result, err = client.IdentityV3().ReadToken(opts3)
	log.Debugf("token is %q\n", *token.Value)
	log.Debugf("token is\n%s\n", log.ToJSON(token))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                          CHECK TOKEN                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	opts4 := &openstack.CheckTokenOptions{
		AllowExpired: openstack.Bool(true),
		SubjectToken: *token.Value,
	}
	ok, result, err := client.IdentityV3().CheckToken(opts4)
	log.Debugf("token valid: %t\n", ok)
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                          GET CATALOG                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	catalog, result, err := client.IdentityV3().ReadCatalog()
	log.Debugf("catalog is:\n%s\n", log.ToJSON(catalog))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                         GET PROJECTS                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	projects, result, err := client.IdentityV3().ListProjects()
	log.Debugf("projects are:\n%s\n", log.ToJSON(projects))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                          GET DOMAINS                              |")
	log.Debugf("+-------------------------------------------------------------------+")

	domains, result, err := client.IdentityV3().ListDomains()
	log.Debugf("domains are:\n%s\n", log.ToJSON(domains))
	log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	if err != nil {
		log.Debugf("call resulted in %v\n", err)
	}

	//time.Sleep(10 * time.Second)

	// log.Debugf("+-------------------------------------------------------------------+")
	// log.Debugf("|                          GET SYSTEMS                              |")
	// log.Debugf("+-------------------------------------------------------------------+")

	// systems, result, err := client.IdentityV3().ReadSystems()
	// log.Debugf("systems are:\n%s\n", log.ToJSON(systems))
	// log.Debugf("result is %d (%s)\n", result.Code, result.Status)
	// if err != nil {
	// 	log.Debugf("call resulted in %v\n", err)
	// }

	log.Debugf("+-------------------------------------------------------------------+")
	log.Debugf("|                        APP CREDENTIALS                            |")
	log.Debugf("+-------------------------------------------------------------------+")

	// opts5 := &openstack.CreateTokenOptions{
	// 	NoCatalog:        false,
	// 	Authenticated:    true,
	// 	ScopeProjectName: openstack.String("admin"),
	// 	ScopeDomainName:  openstack.String("Default"),
	// 	UserName:         openstack.String("admin"),
{'fraction_non_alphanumeric': 0.33564814814814814, 'fraction_numerical': 0.007503192848020434, 'mean_word_length': 1.4103501346671796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1702281', 'n_tokens_mistral': 3710, 'n_tokens_neox': 3520, 'n_words': 652}