func (m *Machine) EncodeToken(ctx context.Context, notifier *observer.Notifier,
	token *envelope.Unsigned) error {

	n := notifier.Notifier(2)

	n.Notify(observer.Progress, "Creating keyring memberships for token", true)

	tokenBody, ok := token.Body.(*primitive.MachineToken)
	if !ok {
		return errors.New("Could not cast token to MachineToken")
	}

	v1members, v2members, err := createKeyringMemberships(ctx, m.engine.crypto,
		m.engine.client, m.engine.session, tokenBody.OrgID, token.ID)
	if err != nil {
		return err
	}

	n.Notify(observer.Progress, "Uploading keyring memberships", true)

	if len(v1members) != 0 {
		_, err = m.engine.client.KeyringMember.Post(ctx, v1members)
		if err != nil {
			log.Printf("error uploading memberships: %s", err)
			return err
		}
	}

	for _, member := range v2members {
		err = m.engine.client.Keyring.Members.Post(ctx, member)
		if err != nil {
			log.Printf("error uploading memberships: %s", err)
			return err
		}
	}

	return nil
}
// EncodeToken creates KeyringMemberships for the provided Machine Token. Used
// during the machine creation process
EncodeToken creates KeyringMemberships for the provided Machine Token. Used
during the machine creation process
// EncodeToken creates KeyringMemberships for the provided Machine Token . Used // during the machine creation process
func (m *Machine) EncodeToken(ctx context.Context, notifier *observer.Notifier,
	token *envelope.Unsigned) error {
	n := notifier.Notifier(2)
	n.Notify(observer.Progress, "Creating keyring memberships for token", true)
	tokenBody, ok := token.Body.(*primitive.MachineToken)
	if !ok {
		return errors.New("Could not cast token to MachineToken")
	}
	v1members, v2members, err := createKeyringMemberships(ctx, m.engine.crypto,
		m.engine.client, m.engine.session, tokenBody.OrgID, token.ID)
	if err != nil {
		return err
	}
	n.Notify(observer.Progress, "Uploading keyring memberships", true)
	if len(v1members) != 0 {
		_, err = m.engine.client.KeyringMember.Post(ctx, v1members)
		if err != nil {
			log.Printf("error uploading memberships: %s", err)
			return err
		}
	}
	for _, member := range v2members {
		err = m.engine.client.Keyring.Members.Post(ctx, member)
		if err != nil {
			log.Printf("error uploading memberships: %s", err)
			return err
		}
	}
	return nil
}
func ( m * Machine ) EncodeToken ( ctx context . Context , notifier * observer . Notifier , token * envelope . Unsigned ) error { n := notifier . Notifier ( 2 ) n . Notify ( observer . Progress , " " , true ) tokenBody , ok := token . Body . ( * primitive . MachineToken ) if ! ok { return errors . New ( " " ) } v1members , v2members , err := createKeyringMemberships ( ctx , m . engine . crypto , m . engine . client , m . engine . session , tokenBody . OrgID , token . ID ) if err != nil { return err } n . Notify ( observer . Progress , " " , true ) if len ( v1members ) != 0 { _ , err = m . engine . client . KeyringMember . Post ( ctx , v1members ) if err != nil { log . Printf ( " " , err ) return err } } for _ , member := range v2members { err = m . engine . client . Keyring . Members . Post ( ctx , member ) if err != nil { log . Printf ( " " , err ) return err } } return nil }
EncodeToken creates KeyringMemberships for the provided Machine Token.
EncodeToken creates KeyringMemberships for the provided Machine Token .