Ejemplo n.º 1
0
func createNode(s *store.MemoryStore, nodeID, role string, csr, cert []byte) error {
	apiRole, _ := ca.FormatRole(role)

	err := s.Update(func(tx store.Tx) error {
		node := &api.Node{
			ID: nodeID,
			Certificate: api.Certificate{
				CSR:  csr,
				CN:   nodeID,
				Role: apiRole,
				Status: api.IssuanceStatus{
					State: api.IssuanceStateIssued,
				},
				Certificate: cert,
			},
			Spec: api.NodeSpec{
				Role:       apiRole,
				Membership: api.NodeMembershipAccepted,
			},
		}

		return store.CreateNode(tx, node)
	})

	return err
}
Ejemplo n.º 2
0
			if flags.Changed("autoaccept") {
				autoaccept, err := flags.GetStringSlice("autoaccept")
				if err != nil {
					return err
				}

				// We are getting a whitelist, so make all of the autoaccepts false
				for _, policy := range spec.AcceptancePolicy.Policies {
					policy.Autoaccept = false

				}

				// For each of the roles handed to us by the client, make them true
				for _, role := range autoaccept {
					// Convert the role into a proto role
					apiRole, err := ca.FormatRole("swarm-" + role)
					if err != nil {
						return fmt.Errorf("unrecognized role %s", role)
					}
					// Attempt to find this role inside of the current policies
					found := false
					for _, policy := range spec.AcceptancePolicy.Policies {
						if policy.Role == apiRole {
							// We found a matching policy, let's update it
							policy.Autoaccept = true
							found = true
						}

					}
					// We didn't find this policy, create it
					if !found {