// Image examples. func main() { config := getConfig() // Authenticate with a username, password, tenant id. creds := openstack.AuthOpts{ AuthUrl: config.Host, Project: config.ProjectName, Username: config.Username, Password: config.Password, } auth, err := openstack.DoAuthRequest(creds) if err != nil { panicString := fmt.Sprint("There was an error authenticating:", err) panic(panicString) } if !auth.GetExpiration().After(time.Now()) { panic("There was an error. The auth token has an invalid expiration.") } // Find the endpoint for the image service. url, err := auth.GetEndpoint("image", "") if url == "" || err != nil { panic("v1 image service url not found during authentication") } // Make a new client with these creds sess, err := openstack.NewSession(nil, auth, nil) if err != nil { panicString := fmt.Sprint("Error crating new Session:", err) panic(panicString) } imageService := image.Service{ Session: *sess, Client: *http.DefaultClient, URL: url + "/v1", // We're forcing Image v1 for now } imagesDetails, err := imageService.ImagesDetail() if err != nil { panicString := fmt.Sprint("Cannot access images:", err) panic(panicString) } var imageIDs = make([]string, 0) for _, element := range imagesDetails { imageIDs = append(imageIDs, element.ID) } if len(imageIDs) == 0 { panicString := fmt.Sprint("No images found, check to make sure access is correct") panic(panicString) } }
// renewToken gets the keystone token from service AuthOpts func (validator *Validator) renewToken() error { // Get the service token to get the token revocation list auth, err := openstack.DoAuthRequest(validator.SvcAuthOpts) if err != nil { return err } // Make a new client with these creds serviceTokenSession, err = openstack.NewSession(nil, auth, nil) if err != nil { return err } return nil }
// Authentication examples. func main() { config := getConfig() // Authenticate with just a username and password. The returned token is // unscoped to a tenant. creds := openstack.AuthOpts{ AuthUrl: config.Host, Username: config.Username, Password: config.Password, } auth, err := openstack.DoAuthRequest(creds) if err != nil { fmt.Println("Error authenticating username/password:"******"There was an error. The auth token has an invalid expiration.") return } // Authenticate with a project name, username, password. creds = openstack.AuthOpts{ AuthUrl: config.Host, Project: config.ProjectName, Username: config.Username, Password: config.Password, } auth, err = openstack.DoAuthRequest(creds) if err != nil { fmt.Println("Error authenticating project/username/password:"******"There was an error. The auth token has an invalid expiration.") return } // Authenticate with a project id, username, password. creds = openstack.AuthOpts{ AuthUrl: config.Host, Project: config.ProjectID, Username: config.Username, Password: config.Password, } auth, err = openstack.DoAuthRequest(creds) if err != nil { fmt.Println("Error authenticating project/username/password:"******"There was an error. The auth token has an invalid expiration.") return } // Get the first endpoint _, err = auth.GetEndpoint("compute", "") if err != nil { fmt.Println("No compute endpoint found:", err) return } }